package fr.tvbarthel.apps.sayitfromthesky.helpers;

import android.database.Cursor;

import com.google.gson.Gson;

import java.util.Arrays;

import fr.tvbarthel.apps.sayitfromthesky.models.Drawing;
import fr.tvbarthel.apps.sayitfromthesky.providers.contracts.DrawingContract;

/**
 * Static utility methods for dealing with cursor.
 */
public final class CursorHelper {

    private static final Gson GSON = new Gson();

    // Non-instantiability
    private CursorHelper() {
    }

    public static String getString(Cursor cursor, String columnName, String defaultValue) {
        final int columnIndex = cursor.getColumnIndex(columnName);
        if (columnIndex == -1) return defaultValue;
        return cursor.getString(columnIndex);
    }

    public static long getLong(Cursor cursor, String columnName, long defaultValue) {
        final int columnIndex = cursor.getColumnIndex(columnName);
        if (columnIndex == -1) return defaultValue;
        return cursor.getLong(columnIndex);
    }

    public static Drawing cursorToDrawing(Cursor cursor) {
        final String title = CursorHelper.getString(cursor, DrawingContract.Columns.COLUMN_TITLE, "");
        final long creationTime = CursorHelper.getLong(cursor, DrawingContract.Columns.COLUMN_CREATION_TIME, 0l);
        final String encodedPolylines = CursorHelper.getString(cursor, DrawingContract.Columns.COLUMN_ENCODED_POLYLINES, "");
        final String[] polylines = GSON.fromJson(encodedPolylines, String[].class);
        return new Drawing(title, creationTime, Arrays.asList(polylines));
    }

}

@@ -485,523 +485,1619 @@
     
-public static String getString(Cursor cursor, String columnName, String defaultValue) %7B%0A        final int columnIndex = cursor.getColumnIndex(columnName);%0A        if (columnIndex == -1) return defaultValue;%0A        return cursor.getString(columnIndex);%0A    %7D%0A%0A    public static long getLong(Cursor cursor, String columnName, long defaultValue) %7B%0A        final int columnIndex = cursor.getColumnIndex(columnName);%0A        if (columnIndex == -1) return defaultValue;%0A        return cursor.getLong(columnIndex);%0A    %7D%0A
+/**%0A     * Get a %7B@link java.lang.String%7D from a %7B@link android.database.Cursor%7D%0A     *%0A     * @param cursor       the %7B@link android.database.Cursor%7D from which the %7B@link java.lang.String%7D will be extracted.%0A     * @param columnName   the column name of the %7B@link java.lang.String%7D%0A     * @param defaultValue the default %7B@link java.lang.String%7D to use if the column name does not exist.%0A     * @return a %7B@link java.lang.String%7D%0A     */%0A    public static String getString(Cursor cursor, String columnName, String defaultValue) %7B%0A        final int columnIndex = cursor.getColumnIndex(columnName);%0A        if (columnIndex == -1) return defaultValue;%0A        return cursor.getString(columnIndex);%0A    %7D%0A%0A    /**%0A     * Get a long from a %7B@link android.database.Cursor%7D.%0A     *%0A     * @param cursor       the %7B@link android.database.Cursor%7D from which the long will be extracted.%0A     * @param columnName   the column name of the long value.%0A     * @param defaultValue the default long value to use if the column name does not exist.%0A     * @return a long value%0A     */%0A    public static long getLong(Cursor cursor, String columnName, long defaultValue) %7B%0A        final int columnIndex = cursor.getColumnIndex(columnName);%0A        if (columnIndex == -1) return defaultValue;%0A        return cursor.getLong(columnIndex);%0A    %7D%0A%0A    /**%0A     * Convert a %7B@link android.database.Cursor%7D to a %7B@link fr.tvbarthel.apps.sayitfromthesky.models.Drawing%7D%0A     *%0A     * @param cursor the %7B@link android.database.Cursor%7D to be converted.%0A     * @return a new %7B@link fr.tvbarthel.apps.sayitfromthesky.models.Drawing%7D%0A     */
 %0A   

Comment a bit