Example usage for android.database AbstractWindowedCursor isNull

List of usage examples for android.database AbstractWindowedCursor isNull

Introduction

In this page you can find the example usage for android.database AbstractWindowedCursor isNull.

Prototype

@Override
    public boolean isNull(int columnIndex) 

Source Link

Usage

From source file:com.futureplatforms.kirin.internal.fragmentation.CursorCoercer4.java

public JSONObject coerceToJSONObject(String[] cols, AbstractWindowedCursor c) {
    JSONObject obj = new JSONObject();
    for (int i = 0; i < cols.length; i++) {
        String name = cols[i];/*  w w w .ja  v a 2s. c o m*/

        if (c.isNull(i)) {
            continue;
        }
        String str = null;
        try {
            str = c.getString(i);
        } catch (Exception e) {
            // not a string
            Log.i(C.TAG, MessageFormat.format("Column {0} could not be represented as a string", name), e);
        }
        Object res = null;
        try {
            if (res == null) {
                res = Long.parseLong(str);
            }
        } catch (Exception e) {
            // wasn't a long!
        }
        try {
            if (res == null) {
                res = Double.parseDouble(str);
            }
        } catch (Exception e) {
            // wasn't a double!
        }
        if (res == null) {
            res = str;
        }

        if (res != null) {
            try {
                obj.putOpt(name, res);
            } catch (JSONException e) {
                Log.e(C.TAG, e.getLocalizedMessage(), e);
            }
        }
    }
    return obj;
}

From source file:com.futureplatforms.kirin.internal.fragmentation.CursorCoercer5.java

@Override
@SuppressWarnings("deprecation")
public JSONObject coerceToJSONObject(String[] cols, AbstractWindowedCursor c) {
    JSONObject obj = new JSONObject();
    for (int i = 0; i < cols.length; i++) {
        String name = cols[i];//from  w  ww .jav a2 s  . c  o m
        // do we have to worry about types?
        // if we do, then we need the CursorWindow.

        // TODO we can make this faster for SDK > 5.
        // TODO have a separate class depending on SDK.
        try {
            if (c.isString(i)) {
                obj.putOpt(name, c.getString(i));
            } else if (c.isLong(i)) {
                obj.put(name, c.getLong(i));
            } else if (c.isFloat(i)) {
                obj.put(name, c.getDouble(i));
            } else if (c.isNull(i)) {
                obj.remove(name);
            }
        } catch (JSONException e) {
            Log.e(C.TAG, e.getLocalizedMessage(), e);
        }
    }
    return obj;
}