本文整理匯總了Java中io.realm.RealmQuery.count方法的典型用法代碼示例。如果您正苦於以下問題:Java RealmQuery.count方法的具體用法?Java RealmQuery.count怎麽用?Java RealmQuery.count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.realm.RealmQuery
的用法示例。
在下文中一共展示了RealmQuery.count方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deleteAll
import io.realm.RealmQuery; //導入方法依賴的package包/類
@Override
public Flowable<Integer> deleteAll() {
final Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
RealmQuery<T> query = realm.where(clazz);
long count = query.count();
realm.delete(clazz);
realm.commitTransaction();
realm.close();
return Flowable.just((int)count);
}
示例2: getChild
import io.realm.RealmQuery; //導入方法依賴的package包/類
@Override
public ExamResult getChild(int i, int i1) {
if (examHeaders.size() < i)
return null;
final RealmQuery<ExamResult> examResults = getChildren(examHeaders.get(i).semester);
if (examResults.count() < i1)
return null;
return examResults.findAll().get(i1);
}
示例3: fetchDataAsyncPeriodicaly
import io.realm.RealmQuery; //導入方法依賴的package包/類
/**
* Fetchs yellow pages from server periodically (once per 3 days).
*/
public void fetchDataAsyncPeriodicaly() {
Realm myRealm = null;
YPDownload data;
try {
myRealm = Realm.getInstance(context);
RealmQuery<YPDownload> query = myRealm.where(YPDownload.class);
if (query.count() > 0) {
data = query.findFirst();
} else {
myRealm.beginTransaction();
data = myRealm.createObject(YPDownload.class);
data.setWhen(0);
myRealm.commitTransaction();
}
Log.d(TAG, "when: " + data.getWhen());
if (System.currentTimeMillis() - data.getWhen() > 1000L * 60 * 60 * 24 * 3) {
fetchDataAsync();
}
} finally {
if (myRealm != null) {
myRealm.close();
}
}
}
示例4: exists
import io.realm.RealmQuery; //導入方法依賴的package包/類
/**
* Check if a post exists or not in the db
* @param link
* @return boolean
*/
public static boolean exists(String link){
RealmQuery<Post> query = App.Realm().where(Post.class)
.equalTo("link", link);
return query.count() != 0;
}
示例5: getExamStatsForSemester
import io.realm.RealmQuery; //導入方法依賴的package包/類
/**
* Erstellt die Noten-Statistik über das Semester. Wenn kein Semester angegeben wird, wird das ganze Studium berücksichtigt.
*
* @param realm aktuelle Datenbankverbindung
* @param semester Semester für welches die Statistik erstellt wird
* @return {@link ExamStats} Objekt welches die Statistik enthält
*/
public static ExamStats getExamStatsForSemester(@NonNull final Realm realm, @Nullable final Integer semester) {
// Rückgabe-Objekt erstellen
final ExamStats stats = new ExamStats();
stats.semester = semester;
// Datenbankabfrage
final RealmQuery<ExamResult> realmQuery = realm.where(ExamResult.class)
.isNotNull(Const.database.ExamResults.GRADE)
.notEqualTo(Const.database.ExamResults.GRADE, 0f);
// Wenn ein Semester angegeben, die Abfrage auf dieses einschränken
if (semester != null) {
realmQuery.equalTo(Const.database.ExamResults.SEMESTER, semester);
}
// Wenn keine Noten vorhanden sind, leeres Objekt zurückgeben, um Fehler beim ermitteln der St
if (realmQuery.count() == 0) {
return stats;
}
final float credits = realmQuery.sum(Const.database.ExamResults.CREDITS).floatValue();
final Number bestGrade = realmQuery.min(Const.database.ExamResults.GRADE);
final Number worstGrade = realmQuery.max(Const.database.ExamResults.GRADE);
if (bestGrade != null) {
stats.setGradeBest(bestGrade.floatValue());
}
if (worstGrade != null) {
stats.setGradeWorst(worstGrade.floatValue());
}
stats.gradeCount = realmQuery.count();
stats.setCredits(credits);
// Berechne Durchschnitt
if (credits > 0) {
final RealmResults<ExamResult> noten = realmQuery.notEqualTo(Const.database.ExamResults.CREDITS, 0f).isNotNull(Const.database.ExamResults.GRADE).findAll();
float average = 0f;
for (final ExamResult examResult : noten) {
if (examResult.grade != null)
average += examResult.grade * examResult.credits;
}
average /= credits;
stats.setAverage(average);
} else {
stats.setAverage(realmQuery.average(Const.database.ExamResults.GRADE));
}
return stats;
}