Ejemplo n.º 1
0
  public void testSortWithDanishCharacters() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    AllTypes at1 = testRealm.createObject(AllTypes.class);
    at1.setColumnString("Æble");
    AllTypes at2 = testRealm.createObject(AllTypes.class);
    at2.setColumnString("Øl");
    AllTypes at3 = testRealm.createObject(AllTypes.class);
    at3.setColumnString("Århus");
    testRealm.commitTransaction();

    RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
    RealmResults<AllTypes> sortedResult = result.where().findAll();
    sortedResult.sort(FIELD_STRING);

    assertEquals(3, sortedResult.size());
    assertEquals("Æble", sortedResult.first().getColumnString());
    assertEquals("Æble", sortedResult.get(0).getColumnString());
    assertEquals("Øl", sortedResult.get(1).getColumnString());
    assertEquals("Århus", sortedResult.get(2).getColumnString());

    RealmResults<AllTypes> reverseResult = result.where().findAll();
    reverseResult.sort(FIELD_STRING, Sort.DESCENDING);
    assertEquals(3, reverseResult.size());
    assertEquals("Æble", reverseResult.last().getColumnString());
    assertEquals("Århus", reverseResult.get(0).getColumnString());
    assertEquals("Øl", reverseResult.get(1).getColumnString());
    assertEquals("Æble", reverseResult.get(2).getColumnString());
  }
Ejemplo n.º 2
0
  public void testSortWithRussianCharacters() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    AllTypes at1 = testRealm.createObject(AllTypes.class);
    at1.setColumnString("Санкт-Петербург");
    AllTypes at2 = testRealm.createObject(AllTypes.class);
    at2.setColumnString("Москва");
    AllTypes at3 = testRealm.createObject(AllTypes.class);
    at3.setColumnString("Новороссийск");
    testRealm.commitTransaction();

    RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
    RealmResults<AllTypes> sortedResult = result.where().findAll();
    sortedResult.sort(FIELD_STRING);

    assertEquals(3, sortedResult.size());
    assertEquals("Москва", sortedResult.first().getColumnString());
    assertEquals("Москва", sortedResult.get(0).getColumnString());
    assertEquals("Новороссийск", sortedResult.get(1).getColumnString());
    assertEquals("Санкт-Петербург", sortedResult.get(2).getColumnString());

    RealmResults<AllTypes> reverseResult = result.where().findAll();
    reverseResult.sort(FIELD_STRING, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(3, reverseResult.size());
    assertEquals("Москва", reverseResult.last().getColumnString());
    assertEquals("Санкт-Петербург", reverseResult.get(0).getColumnString());
    assertEquals("Новороссийск", reverseResult.get(1).getColumnString());
    assertEquals("Москва", reverseResult.get(2).getColumnString());
  }
Ejemplo n.º 3
0
  // No sorting order defined. There are Korean, Arabic and Chinese characters.
  public void testSortWithManyDifferentCharacters() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    AllTypes at1 = testRealm.createObject(AllTypes.class);
    at1.setColumnString("단위");
    AllTypes at2 = testRealm.createObject(AllTypes.class);
    at2.setColumnString("테스트");
    AllTypes at3 = testRealm.createObject(AllTypes.class);
    at3.setColumnString("وحدة");
    AllTypes at4 = testRealm.createObject(AllTypes.class);
    at4.setColumnString("اختبار");
    AllTypes at5 = testRealm.createObject(AllTypes.class);
    at5.setColumnString("单位");
    AllTypes at6 = testRealm.createObject(AllTypes.class);
    at6.setColumnString("试验");
    AllTypes at7 = testRealm.createObject(AllTypes.class);
    at7.setColumnString("單位");
    AllTypes at8 = testRealm.createObject(AllTypes.class);
    at8.setColumnString("測試");
    testRealm.commitTransaction();

    RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
    RealmResults<AllTypes> sortedResult = result.where().findAll();
    sortedResult.sort(FIELD_STRING);

    assertEquals(8, sortedResult.size());

    @SuppressWarnings("UnnecessaryLocalVariable")
    RealmResults<AllTypes> reverseResult = result;
    reverseResult.sort(FIELD_STRING, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(8, reverseResult.size());
  }
Ejemplo n.º 4
0
  public void testSortWithGreekCharacters() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    AllTypes at1 = testRealm.createObject(AllTypes.class);
    at1.setColumnString("αύριο");
    AllTypes at2 = testRealm.createObject(AllTypes.class);
    at2.setColumnString("ημέρες");
    AllTypes at3 = testRealm.createObject(AllTypes.class);
    at3.setColumnString("δοκιμές");
    testRealm.commitTransaction();

    RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
    RealmResults<AllTypes> sortedResult = result.where().findAll();
    sortedResult.sort(FIELD_STRING);

    assertEquals(3, sortedResult.size());
    assertEquals("αύριο", sortedResult.first().getColumnString());
    assertEquals("αύριο", sortedResult.get(0).getColumnString());
    assertEquals("δοκιμές", sortedResult.get(1).getColumnString());
    assertEquals("ημέρες", sortedResult.get(2).getColumnString());

    RealmResults<AllTypes> reverseResult = result.where().findAll();
    reverseResult.sort(FIELD_STRING, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(3, reverseResult.size());
    assertEquals("αύριο", reverseResult.last().getColumnString());
    assertEquals("ημέρες", reverseResult.get(0).getColumnString());
    assertEquals("δοκιμές", reverseResult.get(1).getColumnString());
    assertEquals("αύριο", reverseResult.get(2).getColumnString());
  }
Ejemplo n.º 5
0
  public void testSortByLong() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    RealmResults<AllTypes> sortedList = testRealm.allObjects(AllTypes.class);
    sortedList.sort(FIELD_LONG, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals("Should have same size", resultList.size(), sortedList.size());
    assertEquals(TEST_DATA_SIZE, sortedList.size());
    assertEquals(
        "First excepted to be last",
        resultList.first().getColumnLong(),
        sortedList.last().getColumnLong());

    RealmResults<AllTypes> reverseList = sortedList;
    reverseList.sort(FIELD_LONG, RealmResults.SORT_ORDER_ASCENDING);
    assertEquals(TEST_DATA_SIZE, reverseList.size());
    assertEquals(
        "First excepted to be first",
        resultList.first().getColumnLong(),
        reverseList.first().getColumnLong());
    assertEquals(
        "Last excepted to be last",
        resultList.last().getColumnLong(),
        reverseList.last().getColumnLong());

    RealmResults<AllTypes> reserveSortedList = reverseList;
    reverseList.sort(FIELD_LONG, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(TEST_DATA_SIZE, reserveSortedList.size());
  }
Ejemplo n.º 6
0
 public void testSortWithNullThrows() {
   RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
   try {
     result.sort(null);
     fail("Sorting with a null field name should throw an IllegalArgumentException");
   } catch (IllegalArgumentException ignored) {
   }
   try {
     result.sort(null, null);
     fail();
   } catch (IllegalArgumentException ignored) {
   }
 }
Ejemplo n.º 7
0
 public void testSortSingleField() {
   RealmResults<AllTypes> sortedList = testRealm.allObjects(AllTypes.class);
   sortedList.sort(new String[] {FIELD_LONG}, new boolean[] {RealmResults.SORT_ORDER_DESCENDING});
   assertEquals(TEST_DATA_SIZE, sortedList.size());
   assertEquals(TEST_DATA_SIZE - 1, sortedList.first().getColumnLong());
   assertEquals(0, sortedList.last().getColumnLong());
 }
Ejemplo n.º 8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sleep);
    Realm realm = Realm.getDefaultInstance();

    Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
    tb.setTitle("Sleep Summaries");
    setSupportActionBar(tb);

    if (getSupportActionBar() != null) {
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      getSupportActionBar().setDisplayShowHomeEnabled(true);
      final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
      upArrow.setColorFilter(Color.parseColor("#FFFFFF"), PorterDuff.Mode.SRC_ATOP);
      getSupportActionBar().setHomeAsUpIndicator(upArrow);
      tb.setTitleTextColor(Color.WHITE);
    }

    tb.setNavigationOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onBackPressed();
          }
        });

    // Get all sleep data recorded and send this to adapter to populate the list

    RealmResults<Sleep> sleeps = realm.where(Sleep.class).findAll();
    sleeps.sort("startTime", Sort.DESCENDING);
    SleepAdapter sleepAdapter = new SleepAdapter(this, R.id.listView, sleeps, true);
    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(sleepAdapter);
  }
Ejemplo n.º 9
0
 public void testSortOnNonExistingColumn() {
   try {
     RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
     resultList.sort("Non-existing");
     fail("Column should not exist");
   } catch (IllegalArgumentException ignored) {
   }
 }
Ejemplo n.º 10
0
  public void testSortByFloat() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    RealmResults<AllTypes> sortedList = resultList.where().findAll();
    sortedList.sort(FIELD_FLOAT, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(resultList.size(), sortedList.size());
    assertEquals(TEST_DATA_SIZE, sortedList.size());
    assertEquals(resultList.first().getColumnFloat(), sortedList.last().getColumnFloat());

    RealmResults<AllTypes> reverseList = sortedList.where().findAll();
    reverseList.sort(FIELD_FLOAT, RealmResults.SORT_ORDER_ASCENDING);
    assertEquals(TEST_DATA_SIZE, reverseList.size());
    assertEquals(resultList.first().getColumnFloat(), reverseList.first().getColumnFloat());
    assertEquals(resultList.last().getColumnFloat(), reverseList.last().getColumnFloat());

    RealmResults<AllTypes> reverseSortedList = reverseList.where().findAll();
    reverseSortedList.sort(FIELD_FLOAT, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(TEST_DATA_SIZE, reverseSortedList.size());
  }
Ejemplo n.º 11
0
  private void doTestSortOnColumnWithPartialNullValues(String fieldName) {
    RealmResults<NullTypes> resultList = testRealm.where(NullTypes.class).findAll();
    // Ascending
    RealmResults<NullTypes> sortedList = testRealm.allObjects(NullTypes.class);
    sortedList.sort(fieldName, RealmResults.SORT_ORDER_ASCENDING);
    assertEquals("Should have same size", resultList.size(), sortedList.size());
    // Null should always be the first one in the ascending sorted list
    assertEquals(2, sortedList.first().getId());
    assertEquals(1, sortedList.last().getId());

    // Descending
    sortedList = testRealm.allObjects(NullTypes.class);
    sortedList.sort(fieldName, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals("Should have same size", resultList.size(), sortedList.size());
    assertEquals(1, sortedList.first().getId());
    // Null should always be the last one in the descending sorted list
    assertEquals(2, sortedList.last().getId());
  }
Ejemplo n.º 12
0
  public void testSortByDouble() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    RealmResults<AllTypes> sortedList = resultList.where().findAll();
    sortedList.sort(FIELD_DOUBLE, Sort.DESCENDING);
    assertEquals(resultList.size(), sortedList.size());
    assertEquals(TEST_DATA_SIZE, sortedList.size());
    assertEquals(resultList.first().getColumnDouble(), sortedList.last().getColumnDouble());

    RealmResults<AllTypes> reverseList = sortedList.where().findAll();
    reverseList.sort(FIELD_DOUBLE, Sort.ASCENDING);
    assertEquals(TEST_DATA_SIZE, reverseList.size());
    assertEquals(resultList.first().getColumnDouble(), reverseList.first().getColumnDouble());
    assertEquals(resultList.last().getColumnDouble(), reverseList.last().getColumnDouble());

    RealmResults<AllTypes> reverseSortedList = reverseList.where().findAll();
    reverseSortedList.sort(FIELD_DOUBLE, Sort.DESCENDING);
    assertEquals(TEST_DATA_SIZE, reverseSortedList.size());
  }
Ejemplo n.º 13
0
  public void testSortWithAdapter() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    resultList.sort(FIELD_STRING, RealmResults.SORT_ORDER_DESCENDING);
    RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, automaticUpdate);
    assertEquals(
        resultList.first().getColumnString(),
        realmAdapter.getRealmResults().first().getColumnString());
    assertEquals(resultList.size(), realmAdapter.getRealmResults().size());

    resultList.sort(FIELD_STRING);

    assertEquals(
        resultList.last().getColumnString(),
        realmAdapter.getRealmResults().last().getColumnString());
    assertEquals(
        resultList.get(TEST_DATA_SIZE / 2).getColumnString(),
        realmAdapter.getRealmResults().get(TEST_DATA_SIZE / 2).getColumnString());
    assertEquals(resultList.size(), realmAdapter.getRealmResults().size());
  }
Ejemplo n.º 14
0
 /**
  * Sorts existing {@link io.realm.RealmResults} using three fields.
  *
  * @param fieldName1 first field name.
  * @param sortOrder1 sort order for first field.
  * @param fieldName2 second field name.
  * @param sortOrder2 sort order for second field.
  * @param fieldName3 third field name.
  * @param sortOrder3 sort order for third field.
  * @throws java.lang.IllegalArgumentException if a field name does not exist.
  */
 public void sort(
     String fieldName1,
     Sort sortOrder1,
     String fieldName2,
     Sort sortOrder2,
     String fieldName3,
     Sort sortOrder3) {
   sort(
       new String[] {fieldName1, fieldName2, fieldName3},
       new Sort[] {sortOrder1, sortOrder2, sortOrder3});
 }
 public CommentFragmentController(CommentFragment fragment, View view) {
   super(fragment, view);
   liveChannelList =
       realm
           .where(LiveChannelComment.class)
           .equalTo(LiveChannelComment.FIELD_LIVE_CHANNEL_ID, fragment.id)
           .findAll();
   liveChannelList.sort(LiveChannelComment.FIELD_DATE, false);
   adapter = new CommentLiveChannelAdapter(context, liveChannelList);
   fragment.setupCommentList(adapter);
   fragment.updateList(adapter);
   getComments();
 }
Ejemplo n.º 16
0
  public void testSortByString() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    RealmResults<AllTypes> sortedList = resultList.where().findAll();
    sortedList.sort(FIELD_STRING, RealmResults.SORT_ORDER_DESCENDING);

    assertEquals(resultList.size(), sortedList.size());
    assertEquals(TEST_DATA_SIZE, sortedList.size());
    assertEquals(resultList.first().getColumnString(), sortedList.last().getColumnString());

    RealmResults<AllTypes> reverseList = sortedList.where().findAll();
    reverseList.sort(FIELD_STRING, RealmResults.SORT_ORDER_ASCENDING);
    assertEquals(TEST_DATA_SIZE, reverseList.size());
    assertEquals(resultList.first().getColumnString(), reverseList.first().getColumnString());

    int numberOfDigits = 1 + ((int) Math.log10(TEST_DATA_SIZE));
    int largestNumber = 1;
    for (int i = 1; i < numberOfDigits; i++) largestNumber *= 10; // 10*10* ... *10
    largestNumber = largestNumber - 1;
    assertEquals(
        resultList.get(largestNumber).getColumnString(), reverseList.last().getColumnString());
    RealmResults<AllTypes> reverseSortedList = reverseList.where().findAll();
    reverseList.sort(FIELD_STRING, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(TEST_DATA_SIZE, reverseSortedList.size());
  }
Ejemplo n.º 17
0
  public void testSortByBoolean() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    RealmResults<AllTypes> sortedList = resultList.where().findAll();
    sortedList.sort(FIELD_BOOLEAN, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(resultList.size(), sortedList.size());
    assertEquals(TEST_DATA_SIZE, sortedList.size());
    assertEquals(false, sortedList.last().isColumnBoolean());
    assertEquals(true, sortedList.first().isColumnBoolean());
    assertEquals(true, sortedList.get(TEST_DATA_FIRST_HALF).isColumnBoolean());
    assertEquals(false, sortedList.get(TEST_DATA_LAST_HALF).isColumnBoolean());

    RealmResults<AllTypes> reverseList = sortedList.where().findAll();
    reverseList.sort(FIELD_BOOLEAN, RealmResults.SORT_ORDER_ASCENDING);
    assertEquals(TEST_DATA_SIZE, reverseList.size());
    assertEquals(true, reverseList.last().isColumnBoolean());
    assertEquals(false, reverseList.first().isColumnBoolean());
    assertEquals(false, reverseList.get(TEST_DATA_FIRST_HALF).isColumnBoolean());
    assertEquals(true, reverseList.get(TEST_DATA_LAST_HALF).isColumnBoolean());

    RealmResults<AllTypes> reserveSortedList = reverseList.where().findAll();
    reserveSortedList.sort(FIELD_BOOLEAN, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(TEST_DATA_SIZE, reserveSortedList.size());
    assertEquals(reserveSortedList.first(), sortedList.first());
  }
Ejemplo n.º 18
0
  private void readDataFromDb() {
    if (locationModels.size() > 0) locationModels.clear();
    RealmResults<LocationModel> result = realm.where(LocationModel.class).findAll();
    // sortiny by id.
    // show greater first
    result.sort("id", RealmResults.SORT_ORDER_DESCENDING);
    for (LocationModel data : result) {
      Log.d("tag", "datanya " + data.getId());
      locationModels.add(data);
    }
    // notify adapter
    adapterRoute.notifyDataSetChanged();

    // update view
    updateView();
  }
Ejemplo n.º 19
0
  public void testSortByChildObject() {
    testRealm.beginTransaction();
    Owner owner = testRealm.createObject(Owner.class);
    owner.setName("owner");
    Cat cat = testRealm.createObject(Cat.class);
    cat.setName("cat");
    owner.setCat(cat);
    testRealm.commitTransaction();

    RealmQuery<Owner> query = testRealm.where(Owner.class);
    RealmResults<Owner> owners = query.findAll();

    try {
      owners.sort("cat.name");
      fail("Sorting by child object properties should result in a IllegalArgumentException");
    } catch (IllegalArgumentException ignore) {
    }
  }
Ejemplo n.º 20
0
  public void testSortWithTwoLanguages() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    AllTypes allTypes1 = testRealm.createObject(AllTypes.class);
    allTypes1.setColumnString("test");
    AllTypes allTypes2 = testRealm.createObject(AllTypes.class);
    allTypes2.setColumnString("αύριο");
    AllTypes allTypes3 = testRealm.createObject(AllTypes.class);
    allTypes3.setColumnString("work");
    testRealm.commitTransaction();

    try {
      RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
      result.sort(FIELD_STRING);
    } catch (IllegalArgumentException e) {
      fail("Failed to sort with two kinds of alphabets");
    }
  }
  public Transporte preencherDados(Transporte transporte) {

    if (transporte.getId() == 0) {
      // gerando id
      transportes.sort("id", Sort.DESCENDING);
      id = transportes.size() == 0 ? 1 : transportes.get(0).getId() + 1;
      transporte.setId(id);
    }

    transporte.setModelo(modelo.getText().toString());
    transporte.setMarca(marca.getText().toString());
    transporte.setAno(Integer.parseInt(ano.getText().toString()));
    transporte.setKm(Integer.parseInt(km.getText().toString()));
    transporte.setPotencia(Double.parseDouble(potencia.getText().toString()));
    transporte.setTipo(rgTipo.getCheckedRadioButtonId());
    if (imagemSelecionada != 0) {
      transporte.setImagem(imagemSelecionada);
    }

    return transporte;
  }
  public void callAddUpdateDiscipline(View view) {
    String label = "atualizada";
    if (discipline.getId() == 0) {
      disciplines.sort("id", RealmResults.SORT_ORDER_DESCENDING);
      long id = disciplines.size() == 0 ? 1 : disciplines.get(0).getId() + 1;
      discipline.setId(id);
      label = "adicionada";
    }

    try {
      realm.beginTransaction();
      discipline.setName(etName.getText().toString());
      realm.copyToRealmOrUpdate(discipline);
      realm.commitTransaction();

      Toast.makeText(AddUpdateDisciplineActivity.this, "Disciplina " + label, Toast.LENGTH_SHORT)
          .show();
      finish();
    } catch (Exception e) {
      e.printStackTrace();
      Toast.makeText(AddUpdateDisciplineActivity.this, "Falhou!", Toast.LENGTH_SHORT).show();
    }
  }
Ejemplo n.º 23
0
  /**
   * Sorts existing {@link io.realm.RealmResults}.
   *
   * @param fieldNames an array of field names to sort by. Only fields of type boolean, short, int,
   *     long, float, double, Date, and String are supported.
   * @param sortOrders the directions to sort by.
   * @throws java.lang.IllegalArgumentException if a field name does not exist.
   */
  public void sort(String fieldNames[], Sort sortOrders[]) {
    if (fieldNames == null) {
      throw new IllegalArgumentException("fieldNames must be provided.");
    } else if (sortOrders == null) {
      throw new IllegalArgumentException("sortOrder must be provided.");
    }

    if (fieldNames.length == 1 && sortOrders.length == 1) {
      sort(fieldNames[0], sortOrders[0]);
    } else {
      realm.checkIfValid();
      TableOrView table = getTable();
      if (table instanceof TableView) {
        List<Long> columnIndices = new ArrayList<Long>();
        for (int i = 0; i < fieldNames.length; i++) {
          String fieldName = fieldNames[i];
          long columnIndex = getColumnIndex(fieldName);
          columnIndices.add(columnIndex);
        }
        ((TableView) table).sort(columnIndices, sortOrders);
      }
    }
  }
Ejemplo n.º 24
0
  public void testUpdateRealmResultInAdapter() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    resultList.sort(FIELD_STRING);
    RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, false);
    assertEquals(
        resultList.first().getColumnString(),
        realmAdapter.getRealmResults().first().getColumnString());
    assertEquals(resultList.size(), realmAdapter.getRealmResults().size());

    testRealm.beginTransaction();
    AllTypes allTypes = testRealm.createObject(AllTypes.class);
    allTypes.setColumnString("test data " + TEST_DATA_SIZE);
    testRealm.commitTransaction();
    assertEquals(
        resultList.last().getColumnString(),
        realmAdapter.getRealmResults().last().getColumnString());
    assertEquals(resultList.size(), realmAdapter.getRealmResults().size());

    RealmResults<AllTypes> emptyResultList =
        testRealm.where(AllTypes.class).equalTo(FIELD_STRING, "Not there").findAll();
    realmAdapter.updateRealmResults(emptyResultList);
    assertEquals(emptyResultList.size(), realmAdapter.getRealmResults().size());
  }
Ejemplo n.º 25
0
 public void testSubList() {
   RealmResults<AllTypes> list = testRealm.allObjects(AllTypes.class);
   list.sort("columnLong");
   List<AllTypes> sublist = list.subList(Math.max(list.size() - 20, 0), list.size());
   assertEquals(TEST_DATA_SIZE - 1, sublist.get(sublist.size() - 1).getColumnLong());
 }
Ejemplo n.º 26
0
 /**
  * Sorts existing {@link io.realm.RealmResults} using two fields.
  *
  * @param fieldName1 first field name.
  * @param sortOrder1 sort order for first field.
  * @param fieldName2 second field name.
  * @param sortOrder2 sort order for second field.
  * @throws java.lang.IllegalArgumentException if a field name does not exist.
  */
 public void sort(String fieldName1, Sort sortOrder1, String fieldName2, Sort sortOrder2) {
   sort(new String[] {fieldName1, fieldName2}, new Sort[] {sortOrder1, sortOrder2});
 }