Search in sources :

Example 1 with SortDescriptor

use of io.realm.internal.SortDescriptor in project realm-java by realm.

the class RealmQuery method findAllSortedAsync.

/**
     * Similar to {@link #findAllSorted(String[], Sort[])} but runs asynchronously.
     * from a worker thread.
     * This method is only available from a Looper thread.
     *
     * @return immediately an empty {@link RealmResults}. Users need to register a listener
     * {@link io.realm.RealmResults#addChangeListener(RealmChangeListener)} to be notified when the query completes.
     * @see io.realm.RealmResults
     * @throws java.lang.IllegalArgumentException if one of the field names does not exist or it belongs to a child
     * {@link RealmObject} or a child {@link RealmList}.
     */
public RealmResults<E> findAllSortedAsync(String[] fieldNames, final Sort[] sortOrders) {
    realm.checkIfValid();
    realm.sharedRealm.capabilities.checkCanDeliverNotification(ASYNC_QUERY_WRONG_THREAD_MESSAGE);
    SortDescriptor sortDescriptor = SortDescriptor.getInstanceForSort(query.getTable(), fieldNames, sortOrders);
    return createRealmResults(query, sortDescriptor, null, false);
}
Also used : SortDescriptor(io.realm.internal.SortDescriptor)

Example 2 with SortDescriptor

use of io.realm.internal.SortDescriptor in project realm-java by realm.

the class RealmQuery method distinctAsync.

/**
     * Asynchronously returns a distinct set of objects of a specific class. If the result is
     * sorted, the first object will be returned in case of multiple occurrences, otherwise it is
     * undefined which object is returned.
     *
     * @param fieldName the field name.
     * @return immediately a {@link RealmResults}. Users need to register a listener
     * {@link io.realm.RealmResults#addChangeListener(RealmChangeListener)} to be notified when the
     * query completes.
     * @throws IllegalArgumentException if a field is {@code null}, does not exist, is an unsupported type,
     * is not indexed, or points to linked fields.
     */
public RealmResults<E> distinctAsync(String fieldName) {
    realm.checkIfValid();
    realm.sharedRealm.capabilities.checkCanDeliverNotification(ASYNC_QUERY_WRONG_THREAD_MESSAGE);
    SortDescriptor distinctDescriptor = SortDescriptor.getInstanceForDistinct(query.getTable(), fieldName);
    return createRealmResults(query, null, distinctDescriptor, false);
}
Also used : SortDescriptor(io.realm.internal.SortDescriptor)

Example 3 with SortDescriptor

use of io.realm.internal.SortDescriptor in project realm-java by realm.

the class RealmQuery method findAllSorted.

/**
     * Finds all objects that fulfill the query conditions and sorted by specific field names.
     * <p>
     * Sorting is currently limited to character sets in 'Latin Basic', 'Latin Supplement', 'Latin Extended A',
     * 'Latin Extended B' (UTF-8 range 0-591). For other character sets, sorting will have no effect.
     *
     * @param fieldNames an array of field names to sort by.
     * @param sortOrders how to sort the field names.
     * @return a {@link io.realm.RealmResults} containing objects. If no objects match the condition, a list with zero
     *         objects is returned.
     * @throws java.lang.IllegalArgumentException if one of the field names does not exist or it belongs to a child
     * {@link RealmObject} or a child {@link RealmList}.
     */
public RealmResults<E> findAllSorted(String[] fieldNames, Sort[] sortOrders) {
    realm.checkIfValid();
    SortDescriptor sortDescriptor = SortDescriptor.getInstanceForSort(query.getTable(), fieldNames, sortOrders);
    return createRealmResults(query, sortDescriptor, null, true);
}
Also used : SortDescriptor(io.realm.internal.SortDescriptor)

Example 4 with SortDescriptor

use of io.realm.internal.SortDescriptor in project realm-java by realm.

the class RealmResults method distinct.

/**
     * @deprecated use {@link RealmQuery#distinct(String)} on the return value of {@link #where()} instead. This will
     * be removed in coming 3.x.x minor releases.
     */
@Deprecated
public RealmResults<E> distinct(String fieldName) {
    SortDescriptor distinctDescriptor = SortDescriptor.getInstanceForDistinct(collection.getTable(), fieldName);
    Collection distinctCollection = collection.distinct(distinctDescriptor);
    return createLoadedResults(distinctCollection);
}
Also used : SortDescriptor(io.realm.internal.SortDescriptor) Collection(io.realm.internal.Collection)

Example 5 with SortDescriptor

use of io.realm.internal.SortDescriptor in project realm-java by realm.

the class OrderedRealmCollectionImpl method sort.

/**
     * {@inheritDoc}
     */
@Override
public RealmResults<E> sort(String[] fieldNames, Sort[] sortOrders) {
    SortDescriptor sortDescriptor = SortDescriptor.getInstanceForSort(collection.getTable(), fieldNames, sortOrders);
    Collection sortedCollection = collection.sort(sortDescriptor);
    return createLoadedResults(sortedCollection);
}
Also used : SortDescriptor(io.realm.internal.SortDescriptor) Collection(io.realm.internal.Collection)

Aggregations

SortDescriptor (io.realm.internal.SortDescriptor)10 Collection (io.realm.internal.Collection)4