LongLens.java

  1. package net.zer0bandwidth.android.lib.database.sqlitehouse.refractor;

  2. import android.content.ContentValues;
  3. import android.database.Cursor;
  4. import android.os.Bundle;

  5. import net.zer0bandwidth.android.lib.database.SQLiteSyntax;
  6. import net.zer0bandwidth.android.lib.database.sqlitehouse.SQLightable;

  7. import java.lang.reflect.Field;

  8. /**
  9.  * Marshals long integers.
  10.  * @since zer0bandwidth-net/android 0.1.4 (#26)
  11.  */
  12. public class LongLens
  13. extends Lens<Long>
  14. implements Refractor<Long>
  15. {
  16. @Override
  17. public String getSQLiteDataType()
  18. { return SQLiteSyntax.SQLITE_TYPE_INT ; }

  19. /**
  20.  * Defines the default value as zero.
  21.  * @return {@code 0L}
  22.  */
  23. @Override
  24. public Long getSQLiteDefaultValue()
  25. { return 0L ; }

  26. @Override
  27. public Long getValueFrom( SQLightable o, Field fld )
  28. throws IllegalAccessException
  29. { return fld.getLong(o) ; }

  30. @Override
  31. public LongLens addToContentValues( ContentValues vals, String sKey, Long val )
  32. {
  33. vals.put( sKey, val ) ;
  34. return this ;
  35. }

  36. /** @since zer0bandwidth-net/android 0.1.7 (#50) */
  37. @Override
  38. public LongLens addToBundle( Bundle bndl, String sKey, Long val )
  39. {
  40. bndl.putLong( sKey, val ) ;
  41. return this ;
  42. }

  43. @Override
  44. public Long fromCursor( Cursor crs, String sKey )
  45. { return crs.getLong( crs.getColumnIndex( sKey ) ) ; }

  46. /** @since zer0bandwidth-net/android 0.1.7 (#50) */
  47. @Override
  48. public Long fromBundle( Bundle bndl, String sKey )
  49. { return bndl.getLong( sKey ) ; }
  50. }