Beispiel #1
0
  public void testReverse() {
    Ordering<Number> reverseOrder = numberOrdering.reverse();
    Helpers.testComparator(reverseOrder, Integer.MAX_VALUE, 1, 0, -1, Integer.MIN_VALUE);

    new EqualsTester()
        .addEqualityGroup(reverseOrder, numberOrdering.reverse())
        .addEqualityGroup(Ordering.natural().reverse())
        .addEqualityGroup(Collections.reverseOrder())
        .testEquals();
  }
  @Override
  public Iterator<? extends T> iterator(long first, long count) {
    Collection<T> data = dataModel.getObject();
    if (data == null || data.size() == 0) return Iterators.emptyIterator();
    Iterator<T> it;
    final SortParam<S> sortParam = getSort();
    if (sortParam != null && sortParam.getProperty() != null) {
      Ordering<T> ordering =
          Ordering.natural()
              .nullsFirst()
              .onResultOf(
                  new Function<T, Comparable<?>>() {

                    @Override
                    public Comparable<?> apply(T input) {
                      return comparableValue(input, sortParam.getProperty());
                    }
                  });
      if (!sortParam.isAscending()) ordering = ordering.reverse();
      it = ordering.sortedCopy(data).iterator();
    } else {
      it = data.iterator();
    }
    if (first > 0) Iterators.advance(it, (int) first);
    return count >= 0 ? Iterators.limit(it, (int) count) : it;
  }
 @Override
 Ordering sortFieldOrdering(boolean ascending) {
   Ordering<Integer> ordering = Ordering.<Integer>natural().nullsLast();
   if (!ascending) {
     ordering = ordering.reverse();
   }
   return ordering;
 }
 @Override
 Ordering sortFieldOrdering(boolean ascending) {
   Ordering<String> ordering = Ordering.from(String.CASE_INSENSITIVE_ORDER);
   if (!ascending) {
     ordering = ordering.reverse();
   }
   return ordering;
 }
Beispiel #5
0
 public MarkMarkers(Configuration conf) throws IOException {
   InputStream in = conf.openModelStream("discourse-markers", "en-discourse-markers");
   try {
     // sort so that we prefer the longest markers
     markers = CompareLength.reverse().sortedCopy(read(in));
   } finally {
     in.close();
   }
 }
Beispiel #6
0
  public void testAllEqual() {
    Ordering<Object> comparator = Ordering.allEqual();
    assertSame(comparator, comparator.reverse());

    assertEquals(comparator.compare(null, null), 0);
    assertEquals(comparator.compare(new Object(), new Object()), 0);
    assertEquals(comparator.compare("apples", "oranges"), 0);
    assertSame(comparator, reserialize(comparator));
    assertEquals("Ordering.allEqual()", comparator.toString());

    List<String> strings = ImmutableList.of("b", "a", "d", "c");
    assertEquals(strings, comparator.sortedCopy(strings));
    assertEquals(strings, comparator.immutableSortedCopy(strings));
  }
Beispiel #7
0
 public void testReverseOfReverseSameAsForward() {
   // Not guaranteed by spec, but it works, and saves us from testing
   // exhaustively
   assertSame(numberOrdering, numberOrdering.reverse().reverse());
 }
 @Override
 public List<MyBusinessObject> findByNegativeAccountBalanceOrderedByIdDescending() {
   return getHelper()
       .findAllOrderedWhere(ASCENDING_ID.reverse(), Predicates.not(POSITIVE_ACCOUNT_BALANCE));
 }