當前位置: 首頁>>代碼示例>>Java>>正文


Java RealmResults.first方法代碼示例

本文整理匯總了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));
}
 
開發者ID:playmoweb,項目名稱:store2realm,代碼行數:27,代碼來源:RealmDao.java

示例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));
    }
}
 
開發者ID:WangZhiYao,項目名稱:RealmTasks,代碼行數:21,代碼來源:TaskActivity.java

示例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);
}
 
開發者ID:DorianScholz,項目名稱:OpenLibre,代碼行數:22,代碼來源:ReadingData.java

示例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();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:RealmAllocBenchmarks.java

示例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();
}
 
開發者ID:DorianScholz,項目名稱:OpenLibre,代碼行數:28,代碼來源:SensorStatusFragment.java


注:本文中的io.realm.RealmResults.first方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。