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

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

Introduction

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

Prototype

@GwtCompatible(serializable = true)
@SuppressWarnings("unchecked") 
public static <C extends Comparable> Ordering<C> natural() 

Source Link

Document

Returns a serializable ordering that uses the natural order of the values.

Usage

From source file:guru.qas.martini.step.DefaultStep.java

protected boolean isKeywordMatch(Step that) {
    String normalizedThat = getNormalizedKeyword(that);
    int comparison = Ordering.natural().nullsFirst().compare(keyword, normalizedThat);
    return 0 == comparison;
}

From source file:se.sics.caracaldb.utils.ExtremeKMap.java

public ExtremeKMap(int k, Comparator<K> inverseComparator) {
    Comparator<K> comparator = Ordering.natural();
    this.k = k;/*from  ww w. j a  v a2s  .c  o  m*/
    tops = new TopKMap(k, comparator);
    bottoms = new TopKMap(k, inverseComparator);
}

From source file:com.insightml.data.features.stats.FeaturesImportance.java

@Override
public String getText(final ISamples<?, Double> instances, final int labelIndex) {
    final FeatureStatistics stats = new FeatureStatistics(instances, labelIndex);
    final Map<String, Double> mi = new MutualInformation(0.1).run(stats);
    final Map<String, Double> chi = new ChiSquare(0.1).run(stats);
    final StringBuilder builder = new StringBuilder(1024);
    final SimpleFormatter formatter = new SimpleFormatter(5, true);
    for (final Entry<String, Double> feature : ImmutableSortedMap
            .copyOf(mi, Ordering.natural().reverse().onResultOf(Functions.forMap(mi))).entrySet()) {
        builder.append(UiUtils.fill(feature.getKey(), 25) + "\t");
        builder.append("MutualInformation: " + UiUtils.fill(formatter.format(feature.getValue()), 12));
        builder.append("ChiSquare: " + UiUtils.fill(formatter.format(chi.get(feature.getKey())), 12));
        builder.append("\n");
    }/*from w w w  . jav  a  2s.  co  m*/
    return builder.toString();
}

From source file:org.immutables.value.processor.meta.Visibility.java

public Visibility min(Visibility visibility) {
    return Ordering.natural().min(this, visibility);
}

From source file:com.facebook.buck.jvm.java.MavenUberJar.java

private static BuildRuleParams adjustParams(BuildRuleParams params, TraversedDeps traversedDeps) {
    return params.copyWithDeps(
            Suppliers.ofInstance(ImmutableSortedSet.copyOf(Ordering.natural(), traversedDeps.packagedDeps)),
            Suppliers.ofInstance(ImmutableSortedSet.of()));
}

From source file:com.metamx.druid.index.v1.CompressedLongBufferObjectStrategy.java

private CompressedLongBufferObjectStrategy(final ByteOrder order) {
    super(order, new BufferConverter<LongBuffer>() {
        @Override/*  w ww . j a  va  2s  .c om*/
        public LongBuffer convert(ByteBuffer buf) {
            return buf.asLongBuffer();
        }

        @Override
        public int compare(LongBuffer lhs, LongBuffer rhs) {
            return Ordering.natural().nullsFirst().compare(lhs, rhs);
        }

        @Override
        public int sizeOf(int count) {
            return count * Longs.BYTES;
        }

        @Override
        public LongBuffer combine(ByteBuffer into, LongBuffer from) {
            return into.asLongBuffer().put(from);
        }
    });
}

From source file:io.druid.server.coordinator.DruidCluster.java

public void add(ServerHolder serverHolder) {
    ImmutableDruidServer server = serverHolder.getServer();
    MinMaxPriorityQueue<ServerHolder> tierServers = cluster.get(server.getTier());
    if (tierServers == null) {
        tierServers = MinMaxPriorityQueue.orderedBy(Ordering.natural().reverse()).create();
        cluster.put(server.getTier(), tierServers);
    }// w ww  .  j a v a 2  s .c  om
    tierServers.add(serverHolder);
}

From source file:org.apache.beam.sdk.options.PipelineOptionsValidator.java

/**
 * Validates that the passed {@link PipelineOptions} conforms to all the validation criteria from
 * the passed in interface./* w ww  .  j av a2s.c o m*/
 *
 * <p>Note that the interface requested must conform to the validation criteria specified on
 * {@link PipelineOptions#as(Class)}.
 *
 * @param klass The interface to fetch validation criteria from.
 * @param options The {@link PipelineOptions} to validate.
 * @return The type
 */
public static <T extends PipelineOptions> T validate(Class<T> klass, PipelineOptions options) {
    checkNotNull(klass);
    checkNotNull(options);
    checkArgument(Proxy.isProxyClass(options.getClass()));
    checkArgument(Proxy.getInvocationHandler(options) instanceof ProxyInvocationHandler);

    // Ensure the methods for T are registered on the ProxyInvocationHandler
    T asClassOptions = options.as(klass);

    ProxyInvocationHandler handler = (ProxyInvocationHandler) Proxy.getInvocationHandler(asClassOptions);

    SortedSetMultimap<String, Method> requiredGroups = TreeMultimap.create(Ordering.natural(),
            PipelineOptionsFactory.MethodNameComparator.INSTANCE);
    for (Method method : ReflectHelpers.getClosureOfMethodsOnInterface(klass)) {
        Required requiredAnnotation = method.getAnnotation(Validation.Required.class);
        if (requiredAnnotation != null) {
            if (requiredAnnotation.groups().length > 0) {
                for (String requiredGroup : requiredAnnotation.groups()) {
                    requiredGroups.put(requiredGroup, method);
                }
            } else {
                checkArgument(handler.invoke(asClassOptions, method, null) != null,
                        "Missing required value for [%s, \"%s\"]. ", method, getDescription(method));
            }
        }
    }

    for (String requiredGroup : requiredGroups.keySet()) {
        if (!verifyGroup(handler, asClassOptions, requiredGroups.get(requiredGroup))) {
            throw new IllegalArgumentException("Missing required value for group [" + requiredGroup
                    + "]. At least one of the following properties "
                    + Collections2.transform(requiredGroups.get(requiredGroup), ReflectHelpers.METHOD_FORMATTER)
                    + " required. Run with --help=" + klass.getSimpleName() + " for more information.");
        }
    }

    return asClassOptions;
}

From source file:io.druid.segment.data.CompressedLongBufferObjectStrategy.java

private CompressedLongBufferObjectStrategy(final ByteOrder order, final CompressionStrategy compression,
        final int sizePer) {
    super(order, new BufferConverter<LongBuffer>() {
        @Override/*from  w w w.  ja v  a  2 s  .c om*/
        public LongBuffer convert(ByteBuffer buf) {
            return buf.asLongBuffer();
        }

        @Override
        public int compare(LongBuffer lhs, LongBuffer rhs) {
            return Ordering.natural().nullsFirst().compare(lhs, rhs);
        }

        @Override
        public int sizeOf(int count) {
            return count * Longs.BYTES;
        }

        @Override
        public LongBuffer combine(ByteBuffer into, LongBuffer from) {
            return into.asLongBuffer().put(from);
        }
    }, compression, sizePer);
}

From source file:com.metamx.druid.index.v1.CompressedFloatBufferObjectStrategy.java

private CompressedFloatBufferObjectStrategy(final ByteOrder order) {
    super(order, new BufferConverter<FloatBuffer>() {
        @Override//from w ww .  j a v  a 2s .com
        public FloatBuffer convert(ByteBuffer buf) {
            return buf.asFloatBuffer();
        }

        @Override
        public int compare(FloatBuffer lhs, FloatBuffer rhs) {
            return Ordering.natural().nullsFirst().compare(lhs, rhs);
        }

        @Override
        public int sizeOf(int count) {
            return count * Floats.BYTES;
        }

        @Override
        public FloatBuffer combine(ByteBuffer into, FloatBuffer from) {
            return into.asFloatBuffer().put(from);
        }
    });
}