Android Open Source - android-tools Cursor Helper






From Project

Back to project page android-tools.

License

The source code is released under:

MIT License

If you think the Android project android-tools listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.comfreeze.lib.api.helper;
//from  w  w  w .  j a  va 2s  .  c o  m
import android.database.Cursor;

import net.comfreeze.lib.api.helper.ModelHelper.ModelHelperMap.ElementType;

public abstract class CursorHelper {
    private static final String TAG = CursorHelper.class.getSimpleName();

    public CursorHelper() {
    }

    @SuppressWarnings("incomplete-switch")
    public static Object get(Cursor source, String key, ElementType type) {
        Object result = null;
        if (null != type && null != key) {
            switch (type) {
                case SQL_INTEGER:
                case INTEGER:
                    result = getInteger(source, key);
                    break;
                case SQL_REAL:
                case FLOAT:
                    result = getFloat(source, key);
                    break;
                case DOUBLE:
                    result = getDouble(source, key);
                    break;
                case LONG:
                    result = getLong(source, key);
                    break;
                case SQL_TEXT:
                case STRING:
                    result = getString(source, key);
                    break;
                case BOOLEAN:
                    result = getBoolean(source, key);
                    break;
                case SHORT:
                    result = getShort(source, key);
                    break;
                case SQL_BLOB:
                    result = getByteArray(source, key);
                    break;
            }
        }
        return result;
    }

    public static double getDouble(Cursor source, String key) {
        double realValue = -1;
        if (source.getColumnIndex(key) > -1) {
            realValue = source.getDouble(source.getColumnIndex(key));
            return realValue;
        }
        return -1;
    }

    public static short getShort(Cursor source, String key) {
        short value = -1;
        if (source.getColumnIndex(key) > -1) {
            value = source.getShort(source.getColumnIndex(key));
            return value;
        }
        return -1;
    }

    public static String getString(Cursor source, String key) {
        String value = null;
        if (source.getColumnIndex(key) > -1) {
            value = source.getString(source.getColumnIndex(key));
            return value;
        }
        return null;
    }

    public static long getLong(Cursor source, String key) {
        long value = -1;
        if (source.getColumnIndex(key) > -1) {
            value = source.getLong(source.getColumnIndex(key));
            return value;
        }
        return -1;
    }

    public static float getFloat(Cursor source, String key) {
        float value = -1;
        if (source.getColumnIndex(key) > -1) {
            value = source.getFloat(source.getColumnIndex(key));
            return value;
        }
        return -1;
    }

    public static int getInteger(Cursor source, String key) {
        int value = -1;
        if (source.getColumnIndex(key) > -1) {
            value = source.getInt(source.getColumnIndex(key));
            return value;
        }
        return -1;
    }

    public static boolean getBoolean(Cursor source, String key) {
        boolean value = false;
        if (source.getColumnIndex(key) > -1) {
            value = source.getInt(source.getColumnIndex(key)) == 1 ? true : false;
            return value;
        }
        return value;
    }

    public static byte[] getByteArray(Cursor source, String key) {
        byte[] value = null;
        if (source.getColumnIndex(key) > -1) {
            value = source.getBlob(source.getColumnIndex(key));
        }
        return value;
    }
}




Java Source Code List

net.comfreeze.lib.BundleBuilder.java
net.comfreeze.lib.CFZApplication.java
net.comfreeze.lib.ContentValueBuilder.java
net.comfreeze.lib.FragmentMap.java
net.comfreeze.lib.adapter.HeaderListAdapter.java
net.comfreeze.lib.adapter.IHeaderListAdapter.java
net.comfreeze.lib.adapter.SeparatedListAdapter.java
net.comfreeze.lib.api.BaseAPI.java
net.comfreeze.lib.api.RestAPI.java
net.comfreeze.lib.api.XMLAPI.java
net.comfreeze.lib.api.helper.CursorHelper.java
net.comfreeze.lib.api.helper.JSONHelper.java
net.comfreeze.lib.api.helper.ModelHelper.java
net.comfreeze.lib.api.xml.WordpressAPI.java
net.comfreeze.lib.audio.SoundManager.java
net.comfreeze.lib.db.DatabaseHelper.java
net.comfreeze.lib.db.DatabaseTable.java
net.comfreeze.lib.db.helper.HelperCursor.java
net.comfreeze.lib.db.model.CFZModel.java
net.comfreeze.lib.db.model.FieldColumnMap.java
net.comfreeze.lib.fragments.CFZListFragment.java
net.comfreeze.lib.provider.CFZSimpleProvider.java
net.comfreeze.lib.service.CFZService.java
net.comfreeze.lib.ui.SupportFragmentActivity.java
net.comfreeze.lib.ui.dialog.CFZDialogProgress.java
net.comfreeze.lib.ui.fragment.CFZFragmentBase.java
net.comfreeze.lib.views.BiScrollView.java
net.comfreeze.lib.views.CFZViewHelper.java
net.comfreeze.lib.views.FlowLayout.java
net.comfreeze.lib.views.GestureHelper.java
net.comfreeze.lib.views.HeaderListView.java
net.comfreeze.lib.views.ResizingView.java
net.comfreeze.lib.views.ViewCollection.java
net.comfreeze.lib.views.ViewUtils.java
net.comfreeze.lib.xml.XMLParser.java
net.comfreeze.lib.xml.wordpress.FeedXmlParser.java