本文整理汇总了Java中io.realm.RealmResults.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java RealmResults.isEmpty方法的具体用法?Java RealmResults.isEmpty怎么用?Java RealmResults.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.realm.RealmResults
的用法示例。
在下文中一共展示了RealmResults.isEmpty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: loadCurrentActivityData
import io.realm.RealmResults; //导入方法依赖的package包/类
@Nullable
public List<CurrentActivityData> loadCurrentActivityData() {
RealmResults<CurrentActivityData> results = realm.where(CurrentActivityData.class).findAll();
if (!results.isEmpty()) {
List<CurrentActivityData> data = new ArrayList<>();
int resultsNum = results.size() - 1;
if (resultsNum >= 10) {
for (int i = resultsNum; i >= resultsNum - 10; i--)
data.add(results.get(i));
} else {
for (int i = resultsNum; i >= 0; i--) data.add(results.get(i));
}
return data;
}
return null;
}
示例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: isPackageExist
import io.realm.RealmResults; //导入方法依赖的package包/类
/**
* Query the existence of a specific number.
* @param packageId the package number to query.
* See {@link Package#number}
* @return whether the number is in the database.
*/
@Override
public boolean isPackageExist(@NonNull String packageId) {
Realm rlm = RealmHelper.newRealmInstance();
RealmResults<Package> results = rlm.where(Package.class)
.equalTo("number", packageId)
.findAll();
return (results != null) && (!results.isEmpty());
}
示例5: getCurrentActivity
import io.realm.RealmResults; //导入方法依赖的package包/类
@NonNull
private String getCurrentActivity(Context context) {
String packageName = null;
String activityName = null;
String applicationName;
switch (Settings.getString(Settings.Mode.SELECTION, Settings.Mode.NONE)) {
case Settings.Mode.ROOT:
String request = SU.getSU().runCommand("dumpsys activity | grep \"mFocusedActivity\"");
if (!TextUtils.isEmpty(request)) {
String requests[] = request.split(" ")[3].split("/");
packageName = requests[0];
activityName = requests[1].substring(0, 1).equals(".") ? requests[0] + requests[1] : requests[1];
}
break;
case Settings.Mode.ACCESSIBILITY_SERVICE:
if (AccessibilityServiceUtils.isAccessibilityServiceEnabled(context, CurrentActivityAccessibilityService.class)) {
packageName = CurrentActivityAccessibilityService.foregroundPackageName();
activityName = CurrentActivityAccessibilityService.foregroundClassName();
if (packageName.equals("null") || activityName.equals("null")) return "";
} else {
return context.getString(R.string.should_re_enable_accessibility_service);
}
break;
}
if (packageName != null && activityName != null) {
applicationName = ApplicationUtil.getApplicationNameByPackageName(context, packageName);
if (applicationName != null) {
RealmResults<CurrentActivityData> results = realm.where(CurrentActivityData.class).findAll();
if (!Objects.equals(packageName, getPackageName())) {
if (results.isEmpty()) {
saveCurrentActivityData(applicationName, packageName, activityName);
} else {
CurrentActivityData lastData = results.get(results.size() - 1);
if (!Objects.equals(lastData.getPackageName(), packageName) || !Objects.equals(lastData.getActivityName(), activityName))
saveCurrentActivityData(applicationName, packageName, activityName);
}
}
return (applicationName + " ( " + packageName + " )" + "\n" + activityName);
} else {
return (packageName + "\n" + activityName);
}
} else {
return context.getString(R.string.failed_to_get);
}
}
示例6: deleteBlog
import io.realm.RealmResults; //导入方法依赖的package包/类
public static void deleteBlog(@NonNull String blogUrl) {
RealmResults<BlogMetadata> matchingBlogs = findAllBlogsMatchingUrl(blogUrl);
if (matchingBlogs.isEmpty()) {
throw new IllegalStateException("No blog found matching the URL: " + blogUrl);
}
// we don't allow adding more than 1 blog with the same URL, so this should never happen
if (matchingBlogs.size() > 1) {
throw new IllegalStateException("More than 1 blog found matching the URL: " + blogUrl);
}
// delete blog metadata before data because data without metadata is harmless, but vice-versa is not
// keep a copy of the metadata around so we can delete the data Realm after this
final Realm realm = Realm.getDefaultInstance();
BlogMetadata blogToDelete = matchingBlogs.get(0);
RealmConfiguration dataRealmToDelete = realm.copyFromRealm(blogToDelete).getDataRealmConfig();
RealmUtils.executeTransaction(realm, r -> {
RealmObject.deleteFromRealm(blogToDelete);
});
// delete blog data
Realm.deleteRealm(dataRealmToDelete);
// if the active blog was deleted, set the active blog to a different one
if (blogUrl.equals(getActiveBlogUrl())) {
List<BlogMetadata> allBlogs = getAllBlogs();
if (!allBlogs.isEmpty()) {
setActiveBlog(allBlogs.get(0).getBlogUrl());
} else {
setActiveBlog("");
}
}
}