Search in sources :

Example 1 with Collection

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

the class RealmQuery method createRealmResults.

private RealmResults<E> createRealmResults(TableQuery query, SortDescriptor sortDescriptor, SortDescriptor distinctDescriptor, boolean loadResults) {
    RealmResults<E> results;
    Collection collection = new Collection(realm.sharedRealm, query, sortDescriptor, distinctDescriptor);
    if (isDynamicQuery()) {
        results = new RealmResults<E>(realm, collection, className);
    } else {
        results = new RealmResults<E>(realm, collection, clazz);
    }
    if (loadResults) {
        results.load();
    }
    return results;
}
Also used : Collection(io.realm.internal.Collection)

Example 2 with Collection

use of io.realm.internal.Collection 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 3 with Collection

use of io.realm.internal.Collection 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)

Example 4 with Collection

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

the class OrderedRealmCollectionImpl method sort.

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

Example 5 with Collection

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

the class RealmResultsTests method size_returns_Integer_MAX_VALUE_for_huge_results.

@Test
public void size_returns_Integer_MAX_VALUE_for_huge_results() {
    final Collection collection = Mockito.mock(Collection.class);
    final RealmResults<AllTypes> targetResult = TestHelper.newRealmResults(realm, collection, AllTypes.class);
    Mockito.when(collection.isLoaded()).thenReturn(true);
    Mockito.when(collection.size()).thenReturn(((long) Integer.MAX_VALUE) - 1);
    assertEquals(Integer.MAX_VALUE - 1, targetResult.size());
    Mockito.when(collection.size()).thenReturn(((long) Integer.MAX_VALUE));
    assertEquals(Integer.MAX_VALUE, targetResult.size());
    Mockito.when(collection.size()).thenReturn(((long) Integer.MAX_VALUE) + 1);
    assertEquals(Integer.MAX_VALUE, targetResult.size());
}
Also used : Collection(io.realm.internal.Collection) AllTypes(io.realm.entities.AllTypes) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test)

Aggregations

Collection (io.realm.internal.Collection)7 SortDescriptor (io.realm.internal.SortDescriptor)4 UiThreadTest (android.support.test.annotation.UiThreadTest)1 AllTypes (io.realm.entities.AllTypes)1 PendingRow (io.realm.internal.PendingRow)1 RealmObjectProxy (io.realm.internal.RealmObjectProxy)1 Row (io.realm.internal.Row)1 Test (org.junit.Test)1