com.google.common.collect.Ordering#max ( )源码实例Demo

下面列出了com.google.common.collect.Ordering#max ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: stratio-cassandra   文件: ReplayPosition.java
/**
 * Convenience method to compute the replay position for a group of SSTables.
 * @param sstables
 * @return the most recent (highest) replay position
 */
public static ReplayPosition getReplayPosition(Iterable<? extends SSTableReader> sstables)
{
    if (Iterables.isEmpty(sstables))
        return NONE;

    Function<SSTableReader, ReplayPosition> f = new Function<SSTableReader, ReplayPosition>()
    {
        public ReplayPosition apply(SSTableReader sstable)
        {
            return sstable.getReplayPosition();
        }
    };
    Ordering<ReplayPosition> ordering = Ordering.from(ReplayPosition.comparator);
    return ordering.max(Iterables.transform(sstables, f));
}
 
@Override
public void enter(CssNode n) {
  SourceCodeLocation loc = n.getSourceCodeLocation();
  if (loc == null || loc.isUnknown()) {
    return;
  }
  if (result == null || result.isUnknown()) {
    result = loc;
  } else {
    Ordering<SourceCodePoint> o = Ordering.natural();
    SourceCodePoint lowerBound = o.min(result.getBegin(), loc.getBegin());
    SourceCodePoint upperBound = o.max(result.getEnd(), loc.getEnd());
    result = new SourceCodeLocationBuilder()
        .setSourceCode(result.getSourceCode())
        .setBeginLocation(lowerBound)
        .setEndLocation(upperBound)
        .getSourceCodeLocation();
  }
}
 
源代码3 项目: stratio-cassandra   文件: CommitLogReplayer.java
public CommitLogReplayer()
{
    this.keyspacesRecovered = new NonBlockingHashSet<Keyspace>();
    this.futures = new ArrayList<Future<?>>();
    this.buffer = new byte[4096];
    this.invalidMutations = new HashMap<UUID, AtomicInteger>();
    // count the number of replayed mutation. We don't really care about atomicity, but we need it to be a reference.
    this.replayedCount = new AtomicInteger();
    this.checksum = new PureJavaCrc32();

    // compute per-CF and global replay positions
    cfPositions = new HashMap<UUID, ReplayPosition>();
    Ordering<ReplayPosition> replayPositionOrdering = Ordering.from(ReplayPosition.comparator);
    for (ColumnFamilyStore cfs : ColumnFamilyStore.all())
    {
        // it's important to call RP.gRP per-cf, before aggregating all the positions w/ the Ordering.min call
        // below: gRP will return NONE if there are no flushed sstables, which is important to have in the
        // list (otherwise we'll just start replay from the first flush position that we do have, which is not correct).
        ReplayPosition rp = ReplayPosition.getReplayPosition(cfs.getSSTables());

        // but, if we've truncted the cf in question, then we need to need to start replay after the truncation
        ReplayPosition truncatedAt = SystemKeyspace.getTruncatedPosition(cfs.metadata.cfId);
        if (truncatedAt != null)
            rp = replayPositionOrdering.max(Arrays.asList(rp, truncatedAt));

        cfPositions.put(cfs.metadata.cfId, rp);
    }
    globalPosition = replayPositionOrdering.min(cfPositions.values());
    logger.debug("Global replay position is {} from columnfamilies {}", globalPosition, FBUtilities.toString(cfPositions));
}
 
源代码4 项目: bazel   文件: MethodLibrary.java
/** Returns the maximum element from this list, as determined by maxOrdering. */
private static Object findExtreme(Sequence<?> args, Ordering<Object> maxOrdering)
    throws EvalException {
  // Args can either be a list of items to compare, or a singleton list whose element is an
  // iterable of items to compare. In either case, there must be at least one item to compare.
  try {
    Iterable<?> items = (args.size() == 1) ? Starlark.toIterable(args.get(0)) : args;
    return maxOrdering.max(items);
  } catch (NoSuchElementException ex) {
    throw new EvalException(null, "expected at least one item", ex);
  }
}
 
源代码5 项目: jpmml-evaluator   文件: Classification.java
static
public <K, V extends Number> Map.Entry<K, Value<V>> getWinner(Type type, Collection<Map.Entry<K, Value<V>>> entries){
	Ordering<Map.Entry<K, Value<V>>> ordering = Classification.<K, V>createOrdering(type);

	try {
		return ordering.max(entries);
	} catch(NoSuchElementException nsee){
		return null;
	}
}
 
源代码6 项目: levelup-java-examples   文件: OrderingExample.java
@Test
public void order_by_object_field () {
	
	List<GlassWare> beerGlasses = Lists.newArrayList(
			new GlassWare("Flute Glass", "Enhances and showcases..."),
			new GlassWare("Pilsner Glass (or Pokal)", "showcases color, ..."),
			new GlassWare("Pint Glass", "cheap to make..."),
			new GlassWare("Goblet (or Chalice)", "Eye candy..."),
			new GlassWare("Mug (or Seidel, Stein)", "Easy to drink..."),
			new GlassWare(null, null)
		);
	
	Ordering<GlassWare> byGlassWareName = Ordering.natural().nullsFirst()
			.onResultOf(new Function<GlassWare, String>() {
				public String apply(GlassWare glassWare) {
					return glassWare.getName();
				}
			});
	
	GlassWare firstBeerGlass = byGlassWareName.min(beerGlasses);
	
	// first element will be null
	assertNull(firstBeerGlass.getName());

	GlassWare lastBeerGlass = byGlassWareName.max(beerGlasses);
	assertEquals("Pint Glass", lastBeerGlass.getName());
}