android.database.Cursor.getFloat()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(251)

本文整理了Java中android.database.Cursor.getFloat()方法的一些代码示例,展示了Cursor.getFloat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cursor.getFloat()方法的具体详情如下:
包路径:android.database.Cursor
类名称:Cursor
方法名:getFloat

Cursor.getFloat介绍

[英]Returns the value of the requested column as a float.

The result and whether this method throws an exception when the column value is null, the column type is not a floating-point type, or the floating-point value is not representable as a float value is implementation-defined.
[中]以浮点形式返回请求列的值。
结果以及当列值为null、列类型不是浮点类型或浮点值不能表示为float值时,此方法是否引发异常是由实现定义的。

代码示例

代码示例来源:origin: naman14/Timber

@Override
public float getFloat(final int column) {
  return mQueueCursor.getFloat(column);
}

代码示例来源:origin: naman14/Timber

@Override
public float getFloat(int column) {
  return mCursor.getFloat(column);
}

代码示例来源:origin: aa112901/remusic

@Override
public float getFloat(int column) {
  return mCursor.getFloat(column);
}

代码示例来源:origin: k9mail/k-9

@Override
public float getFloat(int columnIndex) {
  return mActiveCursor.getFloat(columnIndex);
}

代码示例来源:origin: aa112901/remusic

@Override
public float getFloat(final int column) {
  return mQueueCursor.getFloat(column);
}

代码示例来源:origin: seven332/EhViewer

public static float getFloat(Cursor cursor, String column, float defValue) {
  try {
    int index = cursor.getColumnIndex(column);
    if (index != -1) {
      return cursor.getFloat(index);
    }
  } catch (Throwable e) { /* Ignore */ }
  return defValue;
}

代码示例来源:origin: robolectric/robolectric

@Override @Implementation
public float getFloat(int i) {
 return wrappedCursor.getFloat(i);
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

public static Progress parseCursorToBean(Cursor cursor) {
  Progress progress = new Progress();
  progress.tag = cursor.getString(cursor.getColumnIndex(Progress.TAG));
  progress.url = cursor.getString(cursor.getColumnIndex(Progress.URL));
  progress.folder = cursor.getString(cursor.getColumnIndex(Progress.FOLDER));
  progress.filePath = cursor.getString(cursor.getColumnIndex(Progress.FILE_PATH));
  progress.fileName = cursor.getString(cursor.getColumnIndex(Progress.FILE_NAME));
  progress.fraction = cursor.getFloat(cursor.getColumnIndex(Progress.FRACTION));
  progress.totalSize = cursor.getLong(cursor.getColumnIndex(Progress.TOTAL_SIZE));
  progress.currentSize = cursor.getLong(cursor.getColumnIndex(Progress.CURRENT_SIZE));
  progress.status = cursor.getInt(cursor.getColumnIndex(Progress.STATUS));
  progress.priority = cursor.getInt(cursor.getColumnIndex(Progress.PRIORITY));
  progress.date = cursor.getLong(cursor.getColumnIndex(Progress.DATE));
  progress.request = (Request<?, ? extends Request>) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.REQUEST)));
  progress.extra1 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA1)));
  progress.extra2 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA2)));
  progress.extra3 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA3)));
  return progress;
}

代码示例来源:origin: greenrobot/greenDAO

@Override
public SimpleEntityNotNull readEntity(Cursor cursor, int offset) {
  SimpleEntityNotNull entity = new SimpleEntityNotNull( //
    cursor.getLong(offset + 0), // id
    cursor.getShort(offset + 1) != 0, // simpleBoolean
    (byte) cursor.getShort(offset + 2), // simpleByte
    cursor.getShort(offset + 3), // simpleShort
    cursor.getInt(offset + 4), // simpleInt
    cursor.getLong(offset + 5), // simpleLong
    cursor.getFloat(offset + 6), // simpleFloat
    cursor.getDouble(offset + 7), // simpleDouble
    cursor.getString(offset + 8), // simpleString
    cursor.getBlob(offset + 9) // simpleByteArray
  );
  return entity;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testGetFloat() throws Exception {
 assertThat(cursor.moveToFirst()).isTrue();
 assertThat(cursor.getFloat(3)).isEqualTo((float) 1.5);
}

代码示例来源:origin: greenrobot/greenDAO

@Override
public void readEntity(Cursor cursor, SimpleEntityNotNull entity, int offset) {
  entity.setId(cursor.getLong(offset + 0));
  entity.setSimpleBoolean(cursor.getShort(offset + 1) != 0);
  entity.setSimpleByte((byte) cursor.getShort(offset + 2));
  entity.setSimpleShort(cursor.getShort(offset + 3));
  entity.setSimpleInt(cursor.getInt(offset + 4));
  entity.setSimpleLong(cursor.getLong(offset + 5));
  entity.setSimpleFloat(cursor.getFloat(offset + 6));
  entity.setSimpleDouble(cursor.getDouble(offset + 7));
  entity.setSimpleString(cursor.getString(offset + 8));
  entity.setSimpleByteArray(cursor.getBlob(offset + 9));
 }

代码示例来源:origin: robolectric/robolectric

@Test
public void testGetNumbersFromStringField() throws Exception {
 database.execSQL("update table_name set name = '1.2'");
 assertThat(cursor.moveToFirst()).isTrue();
 assertThat(cursor.getInt(1)).isEqualTo(1);
 assertThat(cursor.getDouble(1)).isEqualTo(1.2d);
 assertThat(cursor.getFloat(1)).isEqualTo(1.2f);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testGetNumbersFromBlobField() throws Exception {
 database.execSQL("update table_name set name = '1.2'");
 assertThat(cursor.moveToFirst()).isTrue();
 assertThat(cursor.getInt(1)).isEqualTo(1);
 assertThat(cursor.getDouble(1)).isEqualTo(1.2d);
 assertThat(cursor.getFloat(1)).isEqualTo(1.2f);
}

代码示例来源:origin: seven332/EhViewer

/** @inheritdoc */
@Override
public void readEntity(Cursor cursor, LocalFavoriteInfo entity, int offset) {
  entity.setGid(cursor.getLong(offset + 0));
  entity.setToken(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
  entity.setTitle(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
  entity.setTitleJpn(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
  entity.setThumb(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
  entity.setCategory(cursor.getInt(offset + 5));
  entity.setPosted(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
  entity.setUploader(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
  entity.setRating(cursor.getFloat(offset + 8));
  entity.setSimpleLanguage(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
  entity.setTime(cursor.getLong(offset + 10));
 }

代码示例来源:origin: seven332/EhViewer

/** @inheritdoc */
@Override
public void readEntity(Cursor cursor, HistoryInfo entity, int offset) {
  entity.setGid(cursor.getLong(offset + 0));
  entity.setToken(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
  entity.setTitle(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
  entity.setTitleJpn(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
  entity.setThumb(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
  entity.setCategory(cursor.getInt(offset + 5));
  entity.setPosted(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
  entity.setUploader(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
  entity.setRating(cursor.getFloat(offset + 8));
  entity.setSimpleLanguage(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
  entity.setMode(cursor.getInt(offset + 10));
  entity.setTime(cursor.getLong(offset + 11));
 }

代码示例来源:origin: seven332/EhViewer

/** @inheritdoc */
@Override
public void readEntity(Cursor cursor, BookmarkInfo entity, int offset) {
  entity.setGid(cursor.getLong(offset + 0));
  entity.setToken(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
  entity.setTitle(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
  entity.setTitleJpn(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
  entity.setThumb(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
  entity.setCategory(cursor.getInt(offset + 5));
  entity.setPosted(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
  entity.setUploader(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
  entity.setRating(cursor.getFloat(offset + 8));
  entity.setSimpleLanguage(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
  entity.setPage(cursor.getInt(offset + 10));
  entity.setTime(cursor.getLong(offset + 11));
 }

代码示例来源:origin: seven332/EhViewer

/** @inheritdoc */
@Override
public void readEntity(Cursor cursor, DownloadInfo entity, int offset) {
  entity.setGid(cursor.getLong(offset + 0));
  entity.setToken(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
  entity.setTitle(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
  entity.setTitleJpn(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
  entity.setThumb(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
  entity.setCategory(cursor.getInt(offset + 5));
  entity.setPosted(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
  entity.setUploader(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
  entity.setRating(cursor.getFloat(offset + 8));
  entity.setSimpleLanguage(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
  entity.setState(cursor.getInt(offset + 10));
  entity.setLegacy(cursor.getInt(offset + 11));
  entity.setTime(cursor.getLong(offset + 12));
  entity.setLabel(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
 }

代码示例来源:origin: greenrobot/greenDAO

@Override
public SimpleEntity readEntity(Cursor cursor, int offset) {
  SimpleEntity entity = new SimpleEntity( //
    cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
    cursor.isNull(offset + 1) ? null : cursor.getShort(offset + 1) != 0, // simpleBoolean
    cursor.isNull(offset + 2) ? null : (byte) cursor.getShort(offset + 2), // simpleByte
    cursor.isNull(offset + 3) ? null : cursor.getShort(offset + 3), // simpleShort
    cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4), // simpleInt
    cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5), // simpleLong
    cursor.isNull(offset + 6) ? null : cursor.getFloat(offset + 6), // simpleFloat
    cursor.isNull(offset + 7) ? null : cursor.getDouble(offset + 7), // simpleDouble
    cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // simpleString
    cursor.isNull(offset + 9) ? null : cursor.getBlob(offset + 9) // simpleByteArray
  );
  return entity;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testGetNullNumberValues() throws Exception {
 String sql = "UPDATE table_name set long_value=NULL, float_value=NULL, double_value=NULL";
 database.execSQL(sql);
 assertThat(cursor.moveToFirst()).isTrue();
 assertThat(cursor.getType(2)).isEqualTo(Cursor.FIELD_TYPE_NULL);
 assertThat(cursor.getLong(2)).isEqualTo(0);
 assertThat(cursor.getType(3)).isEqualTo(Cursor.FIELD_TYPE_NULL);
 assertThat(cursor.getFloat(3)).isEqualTo(0f);
 assertThat(cursor.getType(4)).isEqualTo(Cursor.FIELD_TYPE_NULL);
 assertThat(cursor.getDouble(4)).isEqualTo(0d);
}

代码示例来源:origin: greenrobot/greenDAO

@Override
public void readEntity(Cursor cursor, SimpleEntity entity, int offset) {
  entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
  entity.setSimpleBoolean(cursor.isNull(offset + 1) ? null : cursor.getShort(offset + 1) != 0);
  entity.setSimpleByte(cursor.isNull(offset + 2) ? null : (byte) cursor.getShort(offset + 2));
  entity.setSimpleShort(cursor.isNull(offset + 3) ? null : cursor.getShort(offset + 3));
  entity.setSimpleInt(cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4));
  entity.setSimpleLong(cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5));
  entity.setSimpleFloat(cursor.isNull(offset + 6) ? null : cursor.getFloat(offset + 6));
  entity.setSimpleDouble(cursor.isNull(offset + 7) ? null : cursor.getDouble(offset + 7));
  entity.setSimpleString(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
  entity.setSimpleByteArray(cursor.isNull(offset + 9) ? null : cursor.getBlob(offset + 9));
 }

相关文章