List of usage examples for com.google.common.collect Ordering from
@GwtCompatible(serializable = true) @Deprecated public static <T> Ordering<T> from(Ordering<T> ordering)
From source file:com.github.jsdossier.Paths.java
/** * Returns the {@link Path} that represents the longest common prefix for the provided * {@code paths}. All paths will be resolved and normalized relative to the given {@code root} * directory before computing a common prefix. * * <p>If all of the provided {@code paths} do not designate *///www . ja v a 2s .c o m static Path getCommonPrefix(Path root, Iterable<Path> paths) { if (isEmpty(paths)) { return root; } root = root.toAbsolutePath(); paths = transform(paths, normalizeRelativeTo(root)); Path prefix = root.getRoot(); Path shortest = Ordering.from(length()).min(paths); for (Path part : shortest) { Path possiblePrefix = prefix.resolve(part); if (all(paths, startsWith(possiblePrefix))) { prefix = possiblePrefix; } else { break; } } return prefix; }
From source file:org.lenskit.util.collections.SortedListAccumulator.java
/** * Create a new sorted list accumulator that sorts in decreasing order. * @param n The number of results desired; negative for unlimited. * @param comp The comparator; items will be picked in *decreasing* order by this comparator. * @return An accumulator accumulator.//from w ww .j av a 2 s. com */ public static <T> SortedListAccumulator<T> decreasing(int n, Comparator<? super T> comp) { if (n < 0) { return new Unlimited<T>(Ordering.from(comp)); } else { return new TopN<T>(n, Ordering.from(comp)); } }
From source file:org.eclipse.sirius.table.business.internal.metamodel.spec.DLineSpec.java
@Override public EList<DCell> getOrderedCells() { Ordering<DCell> ordering = Ordering.from(new Comparator<DCell>() { Map<DColumn, Integer> columnIndices; @Override//from w w w . j a v a 2 s . co m public int compare(DCell a, DCell b) { int result = 0; DColumn columnA = a.getColumn(); DColumn columnB = b.getColumn(); // column.eContainer can be null in case of deletion in progress if (columnA == null || columnA.eContainer() == null) { result = -1; } else if (columnB == null || columnB.eContainer() == null) { result = 1; } else { if (columnIndices == null) { columnIndices = Maps.newHashMap(); int i = 0; for (DColumn col : columnA.getTable().getColumns()) { columnIndices.put(col, i++); } } Integer aIndex = columnIndices.get(columnA); Integer bIndex = columnIndices.get(columnB); if (aIndex == null || bIndex == null) { throw new RuntimeException(Messages.Table_UnexpectedExceptionMessage); } return aIndex - bIndex; } return result; } }); DCell[] data = new DCell[getCells().size()]; getCells().toArray(data); Arrays.sort(data, ordering); return new EcoreEList.UnmodifiableEList<DCell>(eInternalContainer(), TablePackage.eINSTANCE.getDLine_OrderedCells(), data.length, data); }
From source file:net.oneandone.maven.plugins.cycles.graph.GraphDotUtils.java
private static double getMaxEdgeWeight(DirectedGraph<String, WeightedEdge> component) { return Ordering.from(new WeightedEdgeComparator(component)).min(component.getEdges()).getWeight(); }
From source file:org.graylog2.streams.StreamListFingerprint.java
private String buildFingerprint(List<Stream> streams) { final MessageDigest sha1Digest = DigestUtils.getSha1Digest(); final StringBuilder sb = new StringBuilder(); for (Stream stream : Ordering.from(getStreamComparator()).sortedCopy(streams)) { sb.append(stream.hashCode());/*from ww w . java 2 s. com*/ for (StreamRule rule : Ordering.from(getStreamRuleComparator()).sortedCopy(stream.getStreamRules())) { sb.append(rule.hashCode()); } for (Output output : Ordering.from(getOutputComparator()).sortedCopy(stream.getOutputs())) { sb.append(output.hashCode()); } } return String.valueOf(Hex.encodeHex(sha1Digest.digest(sb.toString().getBytes(StandardCharsets.US_ASCII)))); }
From source file:org.opendaylight.groupbasedpolicy.dto.RuleGroup.java
public RuleGroup(List<Rule> rules, Integer order, Tenant contractTenant, Contract contract, SubjectName subject) {//w w w . ja v a2 s .c om super(); this.rules = Ordering.from(TenantUtils.RULE_COMPARATOR).immutableSortedCopy(rules); this.order = order; this.contractTenant = contractTenant; this.relatedContract = contract; this.relatedSubject = subject; }
From source file:io.v.baku.toolkit.bind.PrefixListAccumulator.java
public PrefixListAccumulator(final Comparator<? super RxTable.Row<T>> ordering) { // ensure deterministic ordering by always applying secondary order on row name mOrdering = Ordering.from(ordering).compound(Ordering.natural().onResultOf(RxTable.Row::getRowName)); }
From source file:dynamite.zafroshops.app.adapter.TypedZopListViewAdapter.java
public TypedZopListViewAdapter(Context context, int resource, ArrayList<MobileZop> objects) { super(context, resource, objects); this.setObjects(objects); rng = (rng == null) ? new Random() : rng; ordering = Ordering.from(new Comparator<MobileZop>() { @Override/*w ww.ja v a 2s .co m*/ public int compare(MobileZop zop, MobileZop z1) { if (zop.Distance < z1.Distance) { return -1; } else if (zop.Distance > z1.Distance) { return 1; } else { return 0; } } }); Collections.sort(objects, ordering); }
From source file:org.apache.druid.client.selector.ConnectionCountServerSelectorStrategy.java
@Override public List<QueryableDruidServer> pick(Set<QueryableDruidServer> servers, DataSegment segment, int numServersToPick) { if (servers.size() <= numServersToPick) { return ImmutableList.copyOf(servers); }//w ww .ja va 2 s. co m return Ordering.from(comparator).leastOf(servers, numServersToPick); }
From source file:com.jivesoftware.os.tasmo.view.reader.service.LatestTreeNode.java
@Override public JsonNode merge(JsonViewMerger merger, final Set<Id> permittedIds) throws IOException { Ordering<MapTreeNode> timestampOrdering = Ordering.from(new Comparator<MapTreeNode>() { @Override//from w w w. jav a 2 s .c o m public int compare(MapTreeNode o1, MapTreeNode o2) { long diff = o1.getHighWaterTimestamp() - o2.getHighWaterTimestamp(); return diff < 0 ? -1 : (diff > 0 ? 1 : 0); } }); Iterable permitted = Iterables.filter(arrayTreeNode.values(), new Predicate<MapTreeNode>() { @Override public boolean apply(MapTreeNode input) { return permittedIds.contains(input.getObjectId().getId()); } }); MapTreeNode latestTreeNode = null; if (permitted.iterator().hasNext()) { latestTreeNode = timestampOrdering.max(permitted); } if (latestTreeNode == null) { return null; } return latestTreeNode.merge(merger, permittedIds); }