Example usage for com.google.common.collect Ordering compare

List of usage examples for com.google.common.collect Ordering compare

Introduction

In this page you can find the example usage for com.google.common.collect Ordering compare.

Prototype

@Override
    public abstract int compare(@Nullable T left, @Nullable T right);

Source Link

Usage

From source file:net.oneandone.maven.plugins.cycles.graph.FeedbackArcSet.java

private static <V, E> Predicate<E> isBackwardEdge(final Ordering<V> ordering, final DirectedGraph<V, E> graph) {
    return new Predicate<E>() {
        public boolean apply(E edge) {
            V from = graph.getSource(edge);
            V to = graph.getDest(edge);//from  w  w  w.  j a v a  2s  . c o m
            return ordering.compare(from, to) > 0;
        }
    };
}

From source file:au.edu.uq.nmerge.mvd.KMPSearchState.java

/**
 * Initialise the next table//from  ww w  . j  a v a  2  s  .  c  om
 *
 * @param pattern the pattern as a byte array in any encoding
 * @return an array of next indices
 */
private static <T> int[] initNext(Ordering<T> ordering, List<T> pattern) {
    int[] next = new int[pattern.size()];
    int i = 0, j = -1;
    next[0] = -1;
    while (i < pattern.size() - 1) {
        while (j >= 0 && ordering.compare(pattern.get(i), pattern.get(j)) != 0) {
            j = next[j];
        }
        i++;
        j++;
        next[i] = j;
    }
    next[0] = 0;
    return next;
}

From source file:org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.CollectionContentsSortableDataProvider.java

private static Ordering<ObjectAdapter> orderingBy(final ObjectAssociation sortProperty,
        final boolean ascending) {
    final Ordering<ObjectAdapter> ordering = new Ordering<ObjectAdapter>() {

        @Override/*  ww  w  . j  av  a  2 s .  c o m*/
        public int compare(final ObjectAdapter p, final ObjectAdapter q) {
            final ObjectAdapter pSort = sortProperty.get(p, InteractionInitiatedBy.FRAMEWORK);
            final ObjectAdapter qSort = sortProperty.get(q, InteractionInitiatedBy.FRAMEWORK);
            Ordering<ObjectAdapter> naturalOrdering;
            if (ascending) {
                naturalOrdering = ORDERING_BY_NATURAL.nullsFirst();
            } else {
                naturalOrdering = ORDERING_BY_NATURAL.reverse().nullsLast();
            }
            return naturalOrdering.compare(pSort, qSort);
        }
    };
    return ordering;
}

From source file:com.google.errorprone.refaster.testdata.template.IfFallthroughTemplate.java

@BeforeTemplate
public int before(T left, T right, Ordering<? super T> ordering) {
    if (left == null && right == null) {
        return 0;
    } else if (left == null) {
        return -1;
    } else if (right == null) {
        return 1;
    } else {//from   w w w .j  a v a 2 s  . c o m
        return ordering.compare(left, right);
    }
}

From source file:org.geogit.api.plumbing.diff.DiffCounter.java

private DiffObjectCount countChildrenDiffs(Iterator<Node> leftTree, Iterator<Node> rightTree) {

    final Ordering<Node> storageOrder = new NodeStorageOrder();

    DiffObjectCount count = new DiffObjectCount();

    PeekingIterator<Node> left = Iterators.peekingIterator(leftTree);
    PeekingIterator<Node> right = Iterators.peekingIterator(rightTree);

    while (left.hasNext() && right.hasNext()) {
        Node peekLeft = left.peek();
        Node peekRight = right.peek();

        if (0 == storageOrder.compare(peekLeft, peekRight)) {
            // same path, consume both
            peekLeft = left.next();// ww  w .j ava2 s  .c o  m
            peekRight = right.next();
            if (!peekLeft.getObjectId().equals(peekRight.getObjectId())) {
                // find the diffs between these two specific refs
                if (RevObject.TYPE.FEATURE.equals(peekLeft.getType())) {
                    checkState(RevObject.TYPE.FEATURE.equals(peekRight.getType()));
                    count.addFeatures(1);
                } else {
                    checkState(RevObject.TYPE.TREE.equals(peekLeft.getType()));
                    checkState(RevObject.TYPE.TREE.equals(peekRight.getType()));
                    ObjectId leftTreeId = peekLeft.getObjectId();
                    ObjectId rightTreeId = peekRight.getObjectId();
                    count.add(countDiffs(leftTreeId, rightTreeId));
                }
            }
        } else if (peekLeft == storageOrder.min(peekLeft, peekRight)) {
            peekLeft = left.next();// consume only the left value
            count.add(aggregateSize(ImmutableList.of(peekLeft)));
        } else {
            peekRight = right.next();// consume only the right value
            count.add(aggregateSize(ImmutableList.of(peekRight)));
        }
    }

    if (left.hasNext()) {
        count.add(countRemaining(left));
    } else if (right.hasNext()) {
        count.add(countRemaining(right));
    }
    Preconditions.checkState(!left.hasNext());
    Preconditions.checkState(!right.hasNext());
    return count;
}

From source file:org.apache.druid.query.groupby.GroupByQuery.java

@Override
public Ordering getResultOrdering() {
    final Ordering<Row> rowOrdering = getRowOrdering(false);

    return Ordering.from((lhs, rhs) -> {
        if (lhs instanceof Row) {
            return rowOrdering.compare((Row) lhs, (Row) rhs);
        } else {//from  w ww.ja  v  a2s  .c  o  m
            // Probably bySegment queries
            return ((Ordering) Comparators.naturalNullsFirst()).compare(lhs, rhs);
        }
    });
}