本文整理汇总了Java中io.realm.RealmResults.first方法的典型用法代码示例。如果您正苦于以下问题:Java RealmResults.first方法的具体用法?Java RealmResults.first怎么用?Java RealmResults.first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.realm.RealmResults
的用法示例。
在下文中一共展示了RealmResults.first方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOne
import io.realm.RealmResults; //导入方法依赖的package包/类
/**
* Get one with a specific filter object
* @param filter
* @return
*/
@Override
public Flowable<Optional<T>> getOne(Filter filter, SortingMode sortingMode) {
Realm realm = Realm.getDefaultInstance();
RealmQuery<T> query = realm.where(clazz);
query = filterToQuery(filter, query);
T item = null;
if (sortingMode != null) {
RealmResults<T> items = applySortingMode(sortingMode, query);
if (!items.isEmpty()) {
item = items.first();
}
} else {
item = query.findFirst();
}
T copy = null;
if (item != null) {
copy = realm.copyFromRealm(item);
}
realm.close();
return Flowable.just(Optional.wrap(copy));
}
示例2: updateList
import io.realm.RealmResults; //导入方法依赖的package包/类
private void updateList(RealmResults<TaskList> results)
{
// Use `findAllAsync` because change listeners are not called when items are deleted and using `findFirst()`
// See https://github.com/realm/realm-java/issues/3138
if (results.size() > 0)
{
TaskList element = results.first();
setTitle(element.getText());
if (adapter == null)
{
adapter = new TaskAdapter(TaskActivity.this, element.getItems());
touchHelper = new TouchHelper(new Callback(), adapter);
touchHelper.attachToRecyclerView(recyclerView);
}
}
else
{
setTitle(getString(R.string.title_deleted));
}
}
示例3: makeGlucoseData
import io.realm.RealmResults; //导入方法依赖的package包/类
private GlucoseData makeGlucoseData(Realm realmProcessedData, int glucoseLevelRaw, int ageInSensorMinutes, long dataDate) {
// if this data point has been read from this sensor before, reuse the object form the database, instead of changing the old data
RealmResults<GlucoseData> previousGlucoseData = realmProcessedData.where(GlucoseData.class)
.equalTo(GlucoseData.ID, GlucoseData.generateId(sensor, ageInSensorMinutes, false, glucoseLevelRaw)).findAll();
// check if a valid previous data point was found
if (!previousGlucoseData.isEmpty()) {
if (previousGlucoseData.first().getGlucoseLevelRaw() == glucoseLevelRaw) {
return previousGlucoseData.first();
}
// if the old value does not equal the new one and the sensor has been running for more than three hours, there is an error in the data
if (ageInSensorMinutes > 3 * minSensorAgeInMinutes) {
Log.e("OpenLibre::ReadingData", "error in glucose level raw:" + previousGlucoseData.first().getGlucoseLevelRaw() + " != " + glucoseLevelRaw
+ " for glucose data with id: " + previousGlucoseData.first().getId());
history.clear();
trend.clear();
return null;
}
}
return new GlucoseData(sensor, ageInSensorMinutes, timezoneOffsetInMinutes, glucoseLevelRaw, false, dataDate);
}
示例4: createObjects
import io.realm.RealmResults; //导入方法依赖的package包/类
@Benchmark
public void createObjects(long reps) {
RealmResults<AllTypes> results = realm.where(AllTypes.class).findAll();
for (long i = 0; i < reps; i++) {
results.first();
}
}
示例5: setupUi
import io.realm.RealmResults; //导入方法依赖的package包/类
public void setupUi(View view) {
Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
RealmResults<SensorData> sensorDataResults = realmProcessedData.where(SensorData.class).
findAllSorted(START_DATE, Sort.DESCENDING);
TextView sensorId = (TextView) view.findViewById(R.id.tv_sensor_id_value);
TextView sensorStartDate = (TextView) view.findViewById(R.id.tv_sensor_start_date_value);
TextView sensorEndsIn = (TextView) view.findViewById(R.id.tv_sensor_ends_in_value);
if (sensorDataResults.size() == 0) {
sensorId.setText(getResources().getString(R.string.no_sensor_registered));
sensorStartDate.setText("");
sensorEndsIn.setText("");
} else {
SensorData sensorData = sensorDataResults.first();
sensorId.setText(sensorData.getTagId());
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
sensorStartDate.setText(dateFormat.format(new Date(sensorData.getStartDate())));
long timeLeft = sensorData.getTimeLeft();
if (timeLeft >= TimeUnit.MINUTES.toMillis(1L)) {
sensorEndsIn.setText(getDurationBreakdown(getResources(), sensorData.getTimeLeft()));
} else {
sensorEndsIn.setText(getResources().getString(R.string.sensor_expired));
}
}
realmProcessedData.close();
}