本文整理汇总了Java中io.realm.RealmQuery.distinct方法的典型用法代码示例。如果您正苦于以下问题:Java RealmQuery.distinct方法的具体用法?Java RealmQuery.distinct怎么用?Java RealmQuery.distinct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.realm.RealmQuery
的用法示例。
在下文中一共展示了RealmQuery.distinct方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getItems
import io.realm.RealmQuery; //导入方法依赖的package包/类
@Override
public List<Item> getItems(Realm realm, boolean onlyUnread) {
// Get all feeds belonging to Folder treeItem
List<Feed> feeds = getFeeds(realm, onlyUnread);
RealmQuery<Item> query = null;
if(feeds != null && feeds.size() > 0) {
// Find all items belonging to any feed from this folder
Iterator<Feed> feedIterator = feeds.iterator();
query = realm.where(Item.class).beginGroup()
.equalTo(Item.FEED_ID, feedIterator.next().getId());
while (feedIterator.hasNext()) {
query.or().equalTo(Item.FEED_ID, feedIterator.next().getId());
}
query.endGroup();
if(onlyUnread)
query.equalTo(Item.UNREAD, true);
}
return query != null ? query.distinct(Item.FINGERPRINT) : null;
}
示例2: getItems
import io.realm.RealmQuery; //导入方法依赖的package包/类
@Override
public List<Item> getItems(Realm realm, boolean onlyUnread) {
final RealmQuery<Item> query = realm.where(Item.class);
if(onlyUnread)
query.equalTo(Item.UNREAD, true);
return query.distinct(Item.FINGERPRINT);
}
示例3: doInBackground
import io.realm.RealmQuery; //导入方法依赖的package包/类
@Override
protected ArrayList<SummaryObject> doInBackground(String... String) {
// Create an ArrayList of SummaryObjects
ArrayList<SummaryObject> summaryObjects = new ArrayList<>();
// Get a Realm instance
RealmConfiguration realmConfig = new RealmConfiguration.Builder(context).build();
Realm.setDefaultConfiguration(realmConfig);
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
// Add the query conditions
RealmQuery<RealmReview> query = realm.where(RealmReview.class);
query.between(FIELD_COMPLETED_DATE, date1, date2);
// Execute the query
RealmResults<RealmReview> results = query.findAll();
realm.commitTransaction();
// Get the SummaryReviews attributes
int count = results.size();
// If nothing found return null
if (count == 0) {
return null;
}
Number revenue = results.sum(FIELD_PRICE);
Number hours = results.sum(FIELD_ELAPSED_TIME);
// Store the reviews summary
SummaryObject summaryReviews = new SummaryObject(VALUE_REVIEWS, count, revenue, hours);
summaryObjects.add(summaryReviews);
// Get the distinct reports_project names
RealmResults<RealmReview> projects = query.distinct(FIELD_PROJECT_NAME);
int totalProjectsCount = projects.size();
if (totalProjectsCount > 0) {
int i = 0;
while (i < totalProjectsCount) {
RealmReview project = projects.get(i);
String projectName = project.getProject_name();
// Being a new Realm transaction
realm.beginTransaction();
RealmQuery<RealmReview> projectQuery = realm.where(RealmReview.class);
// Set the query conditions
projectQuery.equalTo(FIELD_PROJECT_NAME, projectName).between(FIELD_COMPLETED_DATE, date1, date2);
// Execute the query
RealmResults<RealmReview> projectResults = projectQuery.findAll();
realm.commitTransaction();
// Get the reports_project attributes
Number projectRevenue = projectResults.sum(FIELD_PRICE);
long projectHours = projectResults.sum(FIELD_HOURS).longValue();
int projectsCount = projectResults.size();
// Store the reports_project's summary
SummaryObject summaryProject = new SummaryObject(VALUE_PROJECTS, projectName,
projectsCount, projectRevenue, projectHours);
summaryObjects.add(summaryProject);
i++;
}
realm.close();
}
return summaryObjects;
}