List of usage examples for com.google.common.collect Ordering natural
@GwtCompatible(serializable = true) @SuppressWarnings("unchecked") public static <C extends Comparable> Ordering<C> natural()
From source file:de.iteratec.iteraplan.businesslogic.exchange.common.contextoverview.DirectConnect.java
@Override public List<NameUriPair> getBuildingBlocks(int insId) { BigInteger mainId = BigInteger.valueOf(insId); ObjectExpression mainIns = model.findById(insType, mainId); RRelationshipEndExpression endExpression = insType.findRelationshipEndByPersistentName(relEndPoint); RStructuredTypeExpression connectedType = endExpression.getType(); Set<ObjectExpression> connectedOEs = (Set<ObjectExpression>) mainIns.getConnecteds(endExpression).getMany(); final RPropertyExpression connectedTypeNameProp = connectedType .findPropertyByPersistentName(ElasticMiConstants.PERSISTENT_NAME_NAME); Function<ObjectExpression, String> nameExtract = new Function<ObjectExpression, String>() { @Override/*from w w w. j av a2 s . c o m*/ public String apply(ObjectExpression input) { return connectedTypeNameProp.apply(input).getOne().asString(); } }; List<ObjectExpression> sortedOes = Ordering.natural().onResultOf(nameExtract).sortedCopy(connectedOEs); for (int i = 0; i < sortedOes.size(); i++) { ObjectExpression oe = sortedOes.get(i); String name = oe.getValues(connectedTypeNameProp).getOne().asString(); pairs.add(extractPair(name, oe, connectedType, serverURL)); } return pairs; }
From source file:com.facebook.buck.rules.macros.BuildTargetsMacroExpander.java
@Override public Object extractRuleKeyAppendables(BuildTarget target, CellPathResolver cellNames, BuildRuleResolver resolver, String input) throws MacroException { return FluentIterable.from(parse(target, cellNames, input)) .transform(new Function<BuildTarget, SourcePath>() { @Override/*from ww w .j a v a 2 s. c o m*/ public SourcePath apply(BuildTarget name) { return new BuildTargetSourcePath(name); } }).toSortedSet(Ordering.natural()); }
From source file:com.facebook.buck.android.WriteAppModuleMetadataStep.java
@Override public StepExecutionResult execute(ExecutionContext context) { try {// w w w . j a v a2 s . co m // Get module to classes map in sorted order for build determinism and testing ProguardTranslatorFactory translatorFactory = ProguardTranslatorFactory.create(filesystem, proguardFullConfigFile, proguardMappingFile, skipProguard); ImmutableMultimap<APKModule, String> moduleToClassesMap = APKModuleGraph.getAPKModuleToClassesMap( apkModuleToJarPathMap, translatorFactory.createObfuscationFunction(), filesystem); TreeMultimap<APKModule, String> orderedModuleToClassesMap = sortModuleToStringsMultimap( moduleToClassesMap); TreeMultimap<APKModule, String> orderedModuleToTargetsMap = TreeMultimap .create((left, right) -> left.getName().compareTo(right.getName()), Ordering.natural()); for (APKModule module : apkModuleGraph.getAPKModules()) { for (BuildTarget target : apkModuleGraph.getBuildTargets(module)) { orderedModuleToTargetsMap.put(module, target.getFullyQualifiedName()); } } // Module to module deps map is already sorted SortedMap<APKModule, ? extends SortedSet<APKModule>> moduleToDepsMap = apkModuleGraph .toOutgoingEdgesMap(); // Write metdata lines to output LinkedList<String> metadataLines = new LinkedList<>(); metadataLines.add(CLASS_SECTION_HEADER); writeModuleToStringsMultimap(orderedModuleToClassesMap, metadataLines); metadataLines.add(TARGETS_SECTION_HEADER); writeModuleToStringsMultimap(orderedModuleToTargetsMap, metadataLines); metadataLines.add(DEPS_SECTION_HEADER); writeModuleToModulesMap(moduleToDepsMap, metadataLines); filesystem.writeLinesToPath(metadataLines, metadataOutput); return StepExecutionResults.SUCCESS; } catch (IOException e) { context.logError(e, "There was an error running WriteAppModuleMetadataStep."); return StepExecutionResults.ERROR; } }
From source file:com.facebook.buck.rules.modern.builders.IsolatedExecutionStrategy.java
IsolatedExecutionStrategy(IsolatedExecution executionStrategy, SourcePathRuleFinder ruleFinder, CellPathResolver cellResolver, Cell rootCell, ThrowingFunction<Path, HashCode, IOException> fileHasher) { this.executionStrategy = executionStrategy; this.cellResolver = cellResolver; this.rootCell = rootCell; this.fileHasher = fileHasher; this.nodeMap = new ConcurrentHashMap<>(); Delegate delegate = (instance, data, children) -> { HashCode hash = Hashing.sha1().hashBytes(data); Node node = new Node(data, children.stream().collect( ImmutableSortedMap.toImmutableSortedMap(Ordering.natural(), HashCode::toString, nodeMap::get))); nodeMap.put(hash, node);/*from w ww . ja v a2s.c om*/ return hash; }; this.serializer = new Serializer(ruleFinder, cellResolver, delegate); this.cellNames = rootCell.getCellProvider().getLoadedCells().values().stream().map(Cell::getCanonicalName) .collect(ImmutableSet.toImmutableSet()); this.cellToConfig = cellNames.stream().collect(ImmutableMap.toImmutableMap(v -> v, name -> serializeConfig( rootCell.getCellProvider().getCellByPath(cellResolver.getCellPath(name).get()).getBuckConfig()))); HashFunction hasher = Hashing.sha1(); this.configHashes = cellToConfig.entrySet().stream().collect(ImmutableMap .toImmutableMap(entry -> entry.getKey(), entry -> hasher.hashBytes(entry.getValue()).toString())); this.cellPathPrefix = MorePaths.splitOnCommonPrefix(cellNames.stream() .map(name -> cellResolver.getCellPath(name).get()).collect(ImmutableList.toImmutableList())).get() .getFirst(); }
From source file:org.obiba.opal.web.ws.provider.AbstractProtobufProvider.java
private Iterable<Message> sortMessages(Descriptor descriptor, Iterable<Message> msgs, String field, SortDir sortDir) {//from w w w . ja v a2 s.c o m Preconditions.checkNotNull(sortDir); Preconditions.checkNotNull(field); FieldDescriptor sortField = descriptor.findFieldByName(field); // Can't sort on repeated fields if (sortField.isRepeated()) return msgs; // Can't sort on complex types switch (sortField.getJavaType()) { case MESSAGE: return msgs; } // Default ordering is natural order with null values last Ordering<Comparable<?>> ordering = Ordering.natural().nullsLast(); if (sortDir == SortDir.DESC) ordering = ordering.reverse(); return sortMessages(msgs, sortField, ordering); }
From source file:org.apache.druid.client.CoordinatorServerView.java
private void serverAddedSegment(final DruidServerMetadata server, final DataSegment segment) { String segmentId = segment.getIdentifier(); synchronized (lock) { log.debug("Adding segment[%s] for server[%s]", segment, server); SegmentLoadInfo segmentLoadInfo = segmentLoadInfos.get(segmentId); if (segmentLoadInfo == null) { // servers escape the scope of this object so use ConcurrentSet segmentLoadInfo = new SegmentLoadInfo(segment); VersionedIntervalTimeline<String, SegmentLoadInfo> timeline = timelines .get(segment.getDataSource()); if (timeline == null) { timeline = new VersionedIntervalTimeline<>(Ordering.natural()); timelines.put(segment.getDataSource(), timeline); }//www . java 2 s . c o m timeline.add(segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk(segmentLoadInfo)); segmentLoadInfos.put(segmentId, segmentLoadInfo); } segmentLoadInfo.addServer(server); } }
From source file:edu.illinois.cs.cogcomp.bigdata.mapdb.MapDB.java
public static <K extends Comparable<K>, V> BTreeMap<K, V> batchCreate(final Map<K, V> map, BTreeMapMaker maker) {/*from ww w .j a v a2 s .c om*/ List<K> keys = Ordering.natural().reverse().sortedCopy(map.keySet()); return maker.pumpSource(keys.iterator(), new Fun.Function1<V, K>() { @Override public V run(K a) { return map.get(a); } }).make(); }
From source file:edu.udo.scaffoldhunter.data.ConnectionDataManager.java
/** * Creates a ConnectionDataManager containing the connections stored in the * preferences.// ww w . j a v a 2 s .c o m */ public ConnectionDataManager() { this.preferences = Preferences.userNodeForPackage(ScaffoldHunter.class); load(); if (language == null) { language = Language.getDefault(); } for (String name : Ordering.natural().immutableSortedCopy(connections.keySet())) { model.addElement(name); } model.setSelectedItem(selectedConnection); model.addListDataListener(new ListDataListener() { @Override public void intervalRemoved(ListDataEvent e) { } @Override public void intervalAdded(ListDataEvent e) { } @Override public void contentsChanged(ListDataEvent e) { selectedConnection = (String) model.getSelectedItem(); } }); }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.operation.RefreshGraphicalOrderingOperation.java
/** * Recomputes the graphical ordering of events. * /* w w w . java 2s .co m*/ * @param sequenceDiagram * the diagram. * * @param verticalPosition * the function to use to obtain the vertical position of the * event ends. */ private boolean refreshGlobalOrdering(EventEndsOrdering graphicalOrdering, VerticalPositionFunction verticalPosition) { final LoadingCache<EventEnd, Integer> positions = CacheBuilder.newBuilder() .build(CacheLoader.from(verticalPosition)); Predicate<EventEnd> isValidEnd = new Predicate<EventEnd>() { @Override public boolean apply(EventEnd input) { try { Integer pos = positions.get(input); return pos != VerticalPositionFunction.INVALID_POSITION && pos != -VerticalPositionFunction.INVALID_POSITION; } catch (ExecutionException e) { return false; } } }; List<EventEnd> allEnds = Lists.newArrayList(Iterables.filter(getAllEventEnds(), isValidEnd)); Collections.sort(allEnds, Ordering.natural().onResultOf(new Function<EventEnd, Integer>() { @Override public Integer apply(EventEnd input) { try { return positions.get(input); } catch (ExecutionException e) { return VerticalPositionFunction.INVALID_POSITION; } } })); return RefreshOrderingHelper.updateIfNeeded(graphicalOrdering.getEventEnds(), allEnds); }
From source file:org.smartparam.repository.memory.InMemoryParamRepository.java
@Override public List<String> listParameters(ParameterFilter filter) { if (filter.applyNameFilter()) { final Pattern pattern = Pattern.compile(filter.nameFilter()); Set<String> filteredSet = Sets.filter(listParameters(), new Predicate<String>() { @Override// www .j ava 2 s .com public boolean apply(String input) { return pattern.matcher(input).matches(); } }); Ordering<String> ordering = Ordering.natural(); if (filter.sortDirection() == SortDirection.DESC) { ordering = ordering.reverse(); } return ordering.sortedCopy(filteredSet); } else { return new ArrayList<String>(listParameters()); } }