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

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

Introduction

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

Prototype



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

Source Link

Document

Returns an ordering that treats null as greater than all other values and uses this ordering to compare non-null values.

Usage

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   ww w  . ja v  a 2s .c om*/
    }

    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,// w  w  w.jav  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));
}

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

private static Ordering<ComponentDto> stringOrdering(boolean isAscending,
        Function<ComponentDto, String> function) {
    Ordering<String> ordering = Ordering.from(CASE_INSENSITIVE_ORDER);
    if (!isAscending) {
        ordering = ordering.reverse();/* w  w w. j  a  v  a2 s .  c  om*/
    }

    return ordering.nullsLast().onResultOf(function);
}

From source file:org.apache.phoenix.iterate.OrderedResultIterator.java

/**
 * Builds a comparator from the list of columns in ORDER BY clause.
 * @param orderByExpressions the columns in ORDER BY clause.
 * @return the comparator built from the list of columns in ORDER BY clause.
 *//*ww  w.ja va2  s.co  m*/
// ImmutableBytesWritable.Comparator doesn't implement generics
@SuppressWarnings("unchecked")
private static Comparator<ResultEntry> buildComparator(List<OrderByExpression> orderByExpressions) {
    Ordering<ResultEntry> ordering = null;
    int pos = 0;
    for (OrderByExpression col : orderByExpressions) {
        Expression e = col.getExpression();
        Comparator<ImmutableBytesWritable> comparator = e.getSortOrder() == SortOrder.DESC
                && !e.getDataType().isFixedWidth() ? buildDescVarLengthComparator()
                        : new ImmutableBytesWritable.Comparator();
        Ordering<ImmutableBytesWritable> o = Ordering.from(comparator);
        if (!col.isAscending())
            o = o.reverse();
        o = col.isNullsLast() ? o.nullsLast() : o.nullsFirst();
        Ordering<ResultEntry> entryOrdering = o.onResultOf(new NthKey(pos++));
        ordering = ordering == null ? entryOrdering : ordering.compound(entryOrdering);
    }
    return ordering;
}

From source file:org.sonar.server.component.ws.TreeAction.java

private static Ordering<ComponentDto> stringOrdering(boolean isAscending,
        Function<ComponentDto, String> function) {
    Ordering<String> ordering = Ordering.from(CASE_INSENSITIVE_ORDER);
    if (!isAscending) {
        ordering = ordering.reverse();//  w  w w . j  av a  2 s  .c  o m
    }
    return ordering.nullsLast().onResultOf(function);
}

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

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

    // inverse the order of org.sonar.api.measures.Metric.Level
    if (isAscending) {
        ordering = ordering.reverse();/*ww w . j a v a2 s.  c  o  m*/
    }

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

From source file:org.syncany.plugins.transfer.TransferPluginOptions.java

private static List<Field> getOrderedFields(Class<? extends TransferSettings> transferSettingsClass) {
    Ordering<Field> byOrderAnnotation = new Ordering<Field>() {
        @Override//from  w w w.  j a  v a  2 s.  com
        public int compare(Field leftField, Field rightField) {
            int leftOrderValue = (leftField.getAnnotation(Setup.class) != null)
                    ? leftField.getAnnotation(Setup.class).order()
                    : -1;
            int rightOrderValue = (rightField.getAnnotation(Setup.class) != null)
                    ? rightField.getAnnotation(Setup.class).order()
                    : -1;

            return Ints.compare(leftOrderValue, rightOrderValue);
        }
    };

    List<Field> fields = Lists
            .newArrayList(ReflectionUtil.getAllFieldsWithAnnotation(transferSettingsClass, Element.class));
    return ImmutableList.copyOf(byOrderAnnotation.nullsLast().sortedCopy(fields));
}

From source file:io.crate.execution.engine.sort.OrderingByPosition.java

private OrderingByPosition(int position, boolean reverse, @Nullable Boolean nullFirst) {
    this.position = position;

    // note, that we are reverse for the queue so this conditional is by intent
    Ordering<Comparable> ordering;
    nullFirst = nullFirst != null ? !nullFirst : null; // swap because queue is reverse
    if (reverse) {
        ordering = Ordering.natural();//from  w  w w  .  j  av  a2  s.  c  om
        if (nullFirst == null || !nullFirst) {
            ordering = ordering.nullsLast();
        } else {
            ordering = ordering.nullsFirst();
        }
    } else {
        ordering = Ordering.natural().reverse();
        if (nullFirst == null || nullFirst) {
            ordering = ordering.nullsFirst();
        } else {
            ordering = ordering.nullsLast();
        }
    }
    this.ordering = ordering;
}

From source file:com.ibm.common.activitystreams.actions.Parameter.java

public <O extends Comparable<? super O>> Range<O> bounds() {
    O mini = minInclusive();/*  w ww.  j  a  v  a  2  s  .c om*/
    O mine = minExclusive();
    O maxi = maxInclusive();
    O maxe = maxExclusive();
    Ordering<O> ordering = Ordering.<O>natural();
    O min = ordering.nullsLast().min(mini, mine);
    O max = ordering.nullsFirst().max(maxi, maxe);
    BoundType lower = min == null ? null : min == mini ? BoundType.CLOSED : BoundType.OPEN;
    BoundType upper = max == null ? null : max == maxi ? BoundType.CLOSED : BoundType.OPEN;
    if (lower == null && upper == null)
        return Range.<O>all();
    else if (lower != null && upper == null)
        return lower == BoundType.CLOSED ? Range.atLeast(min) : Range.greaterThan(min);
    else if (lower == null && upper != null)
        return upper == BoundType.CLOSED ? Range.atMost(max) : Range.lessThan(max);
    else {
        return Range.range(min, lower, max, upper);
    }
}