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

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

Introduction

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

Prototype



@GwtCompatible(serializable = true)
public <S extends T> Ordering<S> reverse() 

Source Link

Document

Returns the reverse of this ordering; the Ordering equivalent to Collections#reverseOrder(Comparator) .

Usage

From source file:io.crate.execution.engine.collect.RowsTransformer.java

public static Iterable<Row> sortRows(Iterable<Object[]> rows, RoutedCollectPhase collectPhase) {
    ArrayList<Object[]> objects = Lists.newArrayList(rows);
    Ordering<Object[]> ordering = OrderingByPosition.arrayOrdering(collectPhase);
    objects.sort(ordering.reverse());
    return Iterables.transform(objects, Buckets.arrayToRowFunction());
}

From source file:io.crate.operation.collect.RowsTransformer.java

public static Iterable<Row> sortRows(Iterable<Object[]> rows, RoutedCollectPhase collectPhase) {
    ArrayList<Object[]> objects = Lists.newArrayList(rows);
    Ordering<Object[]> ordering = OrderingByPosition.arrayOrdering(collectPhase);
    Collections.sort(objects, ordering.reverse());
    return Iterables.transform(objects, Buckets.arrayToRowFunction());
}

From source file:com.seven7.util.PropertyOrderingFactory.java

public static <T> Ordering<T> createOrdering(String propertyName, SortDirection sortDirection) {
    try {/*from  w  w w. j  ava 2 s  . c  o m*/
        Ordering<T> ordering = new PropertyOrdering<>(propertyName);

        if (sortDirection == SortDirection.DESCENDING) {
            ordering = ordering.reverse();
        }

        return ordering;
    } catch (ParseException e) {
        return null;
    }
}

From source file:com.palantir.atlasdb.keyvalue.api.RowResult.java

public static <T> Ordering<RowResult<T>> getOrderingByRowName(boolean reverse) {
    Ordering<RowResult<T>> ordering = getOrderingByRowName();
    if (reverse) {
        return ordering.reverse();
    }//w  w w  . j a  v  a 2 s  .c  o  m
    return ordering;
}

From source file:org.grouplens.samantha.server.evaluator.metric.AUC.java

static public double computeAUC(List<double[]> list, double threshold) {
    Ordering<double[]> ordering = SortingUtilities.pairDoubleSecondOrdering();
    ImmutableList<double[]> sorted = ordering.reverse().immutableSortedCopy(list);
    double numPos = 0;
    double numNeg = 0;
    double area = 0;
    for (double[] ele : sorted) {
        if (ele[0] >= threshold) {
            numPos += 1;/* www  . jav  a2  s  .c o m*/
        } else {
            numNeg += 1;
            area += numPos;
        }
    }
    return area / (numNeg * numPos);
}

From source file:org.nmdp.ngs.range.Ranges.java

/**
 * Return a reverse ordering by lower endpoint over ranges.
 *
 * @param <C> range endpoint type//from w  w w .j  a v a 2  s.com
 * @return a reverse ordering by lower endpoint over ranges
 */
public static <C extends Comparable> Ordering<Range<C>> reverseOrderingByLowerEndpoint() {
    Ordering<Range<C>> orderingByLowerEndpoint = orderingByLowerEndpoint();
    return orderingByLowerEndpoint.reverse();
}

From source file:org.nmdp.ngs.range.Ranges.java

/**
 * Return a reverse ordering by upper endpoint over ranges.
 *
 * @param <C> range endpoint type/*from  ww w  .  jav a2  s.  co  m*/
 * @return a reverse ordering by upper endpoint over ranges
 */
public static <C extends Comparable> Ordering<Range<C>> reverseOrderingByUpperEndpoint() {
    Ordering<Range<C>> orderingByUpperEndpoint = orderingByUpperEndpoint();
    return orderingByUpperEndpoint.reverse();
}

From source file:com.palantir.atlasdb.keyvalue.impl.ClosableMergedIterator.java

static <T> Iterator<RowResult<T>> mergeIterators(Iterator<RowResult<T>> writeIter,
        Iterator<RowResult<T>> readIter, boolean isReversed) {
    Ordering<RowResult<T>> comparator = RowResult.getOrderingByRowName();
    if (isReversed) {
        comparator = comparator.reverse();
    }/*from  ww w .j a va  2 s . c om*/
    return IteratorUtils.mergeIterators(writeIter, readIter, comparator,
            new Function<Pair<RowResult<T>, RowResult<T>>, RowResult<T>>() {
                @Override
                public RowResult<T> apply(Pair<RowResult<T>, RowResult<T>> rows) {
                    RowResult<T> writeResult = rows.getLhSide();
                    RowResult<T> readResult = rows.getRhSide();
                    for (Entry<byte[], T> entry : writeResult.getColumns().entrySet()) {
                        T readValue = readResult.getColumns().get(entry.getKey());
                        if (readValue instanceof Value) {
                            long writeTimestamp = ((Value) entry.getValue()).getTimestamp();
                            long readTimestamp = ((Value) readValue).getTimestamp();
                            if (writeTimestamp < readTimestamp) {
                                throw new IllegalArgumentException(
                                        "The read only kvs has a row with timestamp " + writeTimestamp
                                                + ", while the same row in the writing kvs has timestamp. "
                                                + readTimestamp);
                            }
                        }
                    }
                    // Order is important here, overwrite results from the
                    // secondary tier with results from the primary tier.
                    return RowResults.merge(readResult, writeResult);
                }
            });
}

From source file:org.sonar.server.measure.ws.ComponentTreeSort.java

private static Ordering<ComponentDto> numericalMetricOrdering(boolean isAscending, @Nullable MetricDto metric,
        Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric) {
    Ordering<Double> ordering = Ordering.natural();

    if (!isAscending) {
        ordering = ordering.reverse();
    }//from w  w  w .j a v a  2s.  com

    return ordering.nullsLast()
            .onResultOf(new ComponentDtoToNumericalMeasureValue(metric, measuresByComponentUuidAndMetric));
}

From source file:org.sonar.server.measure.ws.ComponentTreeSort.java

private static Ordering<ComponentDto> numericalMetricPeriodOrdering(ComponentTreeWsRequest request,
        @Nullable MetricDto metric,//ww  w. ja v a  2 s.c  om
        Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric) {
    Ordering<Double> ordering = Ordering.natural();

    if (!request.getAsc()) {
        ordering = ordering.reverse();
    }

    return ordering.nullsLast()
            .onResultOf(new ComponentDtoToMeasureVariationValue(metric, measuresByComponentUuidAndMetric));
}