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


Java RealmQuery.distinct方法代碼示例

本文整理匯總了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;
}
 
開發者ID:schaal,項目名稱:ocreader,代碼行數:20,代碼來源:Folder.java

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

示例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;
}
 
開發者ID:throwrocks,項目名稱:android-udacity-reviews,代碼行數:57,代碼來源:ReportQueryTask.java


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