Exemplo n.º 1
0
  /** @throws Exception */
  @Test
  public void sortInMemory() throws Exception {
    List<Hoge> list = new ArrayList<Hoge>();
    Hoge hoge = new Hoge();
    hoge.setMyInteger(1);
    list.add(hoge);
    hoge = new Hoge();
    hoge.setMyInteger(3);
    list.add(hoge);
    hoge = new Hoge();
    hoge.setMyInteger(2);
    list.add(hoge);

    List<Hoge> sorted =
        DatastoreUtil.sortInMemory(
            list, Arrays.asList((InMemorySortCriterion) meta.myInteger.desc));
    assertThat(sorted.size(), is(3));
    assertThat(sorted.get(0).getMyInteger(), is(3));
    assertThat(sorted.get(1).getMyInteger(), is(2));
    assertThat(sorted.get(2).getMyInteger(), is(1));
  }
Exemplo n.º 2
0
  /** @throws Exception */
  @Test
  public void filterInMemory() throws Exception {
    List<Hoge> list = new ArrayList<Hoge>();
    Hoge hoge = new Hoge();
    hoge.setMyInteger(1);
    list.add(hoge);
    hoge = new Hoge();
    hoge.setMyInteger(3);
    list.add(hoge);
    hoge = new Hoge();
    hoge.setMyInteger(2);
    list.add(hoge);

    List<Hoge> filtered =
        DatastoreUtil.filterInMemory(
            list,
            Arrays.asList(
                (InMemoryFilterCriterion) meta.myInteger.greaterThanOrEqual(2),
                (InMemoryFilterCriterion) meta.myInteger.lessThan(3)));
    assertThat(filtered.size(), is(1));
    assertThat(filtered.get(0).getMyInteger(), is(2));
  }