List of usage examples for com.google.common.collect ImmutableSortedMap naturalOrder
public static <K extends Comparable<?>, V> Builder<K, V> naturalOrder()
From source file:com.netflix.exhibitor.core.config.EncodedConfigParser.java
/** * Return a sorted map of the fields/values * * @return map//from ww w . j a v a 2 s .c om */ public Map<String, String> getSortedMap() { ImmutableSortedMap.Builder<String, String> builder = ImmutableSortedMap.naturalOrder(); for (FieldValue fv : fieldValues) { builder.put(fv.getField(), fv.getValue()); } return builder.build(); }
From source file:com.facebook.buck.android.NativeLibraryMergeEnhancer.java
@SuppressWarnings("PMD.PrematureDeclaration") static NativeLibraryMergeEnhancementResult enhance(CxxBuckConfig cxxBuckConfig, BuildRuleResolver ruleResolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, BuildRuleParams buildRuleParams, ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> nativePlatforms, Map<String, List<Pattern>> mergeMap, Optional<BuildTarget> nativeLibraryMergeGlue, ImmutableMultimap<APKModule, NativeLinkable> linkables, ImmutableMultimap<APKModule, NativeLinkable> linkablesAssets) throws NoSuchBuildTargetException { NativeLibraryMergeEnhancer.ruleFinder = ruleFinder; NativeLibraryMergeEnhancementResult.Builder builder = NativeLibraryMergeEnhancementResult.builder(); ImmutableSet<APKModule> modules = ImmutableSet.<APKModule>builder().addAll(linkables.keySet()) .addAll(linkablesAssets.keySet()).build(); ImmutableSortedMap.Builder<String, String> sonameMapBuilder = ImmutableSortedMap.naturalOrder(); for (APKModule module : modules) { // Sort by build target here to ensure consistent behavior. Iterable<NativeLinkable> allLinkables = FluentIterable .from(Iterables.concat(linkables.get(module), linkablesAssets.get(module))) .toSortedList(HasBuildTarget.BUILD_TARGET_COMPARATOR); final ImmutableSet<NativeLinkable> linkableAssetSet = ImmutableSet.copyOf(linkablesAssets.get(module)); Map<NativeLinkable, MergedNativeLibraryConstituents> linkableMembership = makeConstituentMap( buildRuleParams, mergeMap, allLinkables, linkableAssetSet); sonameMapBuilder.putAll(makeSonameMap( // sonames can *theoretically* differ per-platform, but right now they don't on Android, // so just pick the first platform and use that to get all the sonames. nativePlatforms.values().iterator().next().getCxxPlatform(), linkableMembership)); Iterable<MergedNativeLibraryConstituents> orderedConstituents = getOrderedMergedConstituents( buildRuleParams, linkableMembership); Optional<NativeLinkable> glueLinkable = Optional.empty(); if (nativeLibraryMergeGlue.isPresent()) { BuildRule rule = ruleResolver.getRule(nativeLibraryMergeGlue.get()); if (!(rule instanceof NativeLinkable)) { throw new RuntimeException("Native library merge glue " + rule.getBuildTarget() + " for application " + buildRuleParams.getBuildTarget() + " is not linkable."); }/*from ww w.jav a2s . c o m*/ glueLinkable = Optional.of(((NativeLinkable) rule)); } Set<MergedLibNativeLinkable> mergedLinkables = createLinkables(cxxBuckConfig, ruleResolver, pathResolver, buildRuleParams, glueLinkable, orderedConstituents); for (MergedLibNativeLinkable linkable : mergedLinkables) { if (Collections.disjoint(linkable.constituents.getLinkables(), linkableAssetSet)) { builder.putMergedLinkables(module, linkable); } else if (linkableAssetSet.containsAll(linkable.constituents.getLinkables())) { builder.putMergedLinkablesAssets(module, linkable); } } } builder.setSonameMapping(sonameMapBuilder.build()); return builder.build(); }
From source file:org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.java
private static ImmutableSortedMap<String, ValueSnapshot> snapshotTaskInputProperties(TaskInternal task, TaskProperties taskProperties, ImmutableSortedMap<String, ValueSnapshot> previousInputProperties, ValueSnapshotter valueSnapshotter) { ImmutableSortedMap.Builder<String, ValueSnapshot> builder = ImmutableSortedMap.naturalOrder(); Map<String, Object> inputPropertyValues = taskProperties.getInputPropertyValues().create(); assert inputPropertyValues != null; for (Map.Entry<String, Object> entry : inputPropertyValues.entrySet()) { String propertyName = entry.getKey(); Object value = entry.getValue(); try {//from w w w. jav a2 s . c o m ValueSnapshot previousSnapshot = previousInputProperties.get(propertyName); if (previousSnapshot == null) { builder.put(propertyName, valueSnapshotter.snapshot(value)); } else { builder.put(propertyName, valueSnapshotter.snapshot(value, previousSnapshot)); } } catch (Exception e) { throw new UncheckedIOException(String.format( "Unable to store input properties for %s. Property '%s' with value '%s' cannot be serialized.", task, propertyName, value), e); } } return builder.build(); }
From source file:org.voltdb.expressions.HashRangeExpression.java
@Override protected void loadFromJSONObject(JSONObject obj, Database db) throws JSONException { m_hashColumn = obj.getInt(Members.HASH_COLUMN.name()); JSONArray array = obj.getJSONArray(Members.RANGES.name()); ImmutableSortedMap.Builder<Long, Long> b = ImmutableSortedMap.naturalOrder(); for (int ii = 0; ii < array.length(); ii++) { JSONObject range = array.getJSONObject(ii); b.put(range.getLong(Members.RANGE_START.name()), range.getLong(Members.RANGE_END.name())); }//ww w . jav a 2 s. c om m_ranges = b.build(); }
From source file:io.airlift.log.Logging.java
@SuppressWarnings("MethodMayBeStatic") public Map<String, Level> getAllLevels() { ImmutableSortedMap.Builder<String, Level> levels = ImmutableSortedMap.naturalOrder(); for (String loggerName : Collections.list(LogManager.getLogManager().getLoggerNames())) { java.util.logging.Level level = java.util.logging.Logger.getLogger(loggerName).getLevel(); if (level != null) { levels.put(loggerName, Level.fromJulLevel(level)); }/* w w w. j a va 2 s. co m*/ } return levels.build(); }
From source file:org.gradle.internal.execution.history.impl.DefaultPreviousExecutionStateSerializer.java
public ImmutableSortedMap<String, ValueSnapshot> readInputProperties(Decoder decoder) throws Exception { int size = decoder.readSmallInt(); if (size == 0) { return ImmutableSortedMap.of(); }/*w w w . j av a 2s . co m*/ if (size == 1) { return ImmutableSortedMap.of(decoder.readString(), readValueSnapshot(decoder)); } ImmutableSortedMap.Builder<String, ValueSnapshot> builder = ImmutableSortedMap.naturalOrder(); for (int i = 0; i < size; i++) { builder.put(decoder.readString(), readValueSnapshot(decoder)); } return builder.build(); }
From source file:org.gradle.api.internal.changedetection.state.TaskExecutionSnapshotSerializer.java
private static ImmutableSortedMap<String, Long> readSnapshotIds(Decoder decoder) throws IOException { int count = decoder.readSmallInt(); ImmutableSortedMap.Builder<String, Long> builder = ImmutableSortedMap.naturalOrder(); for (int snapshotIdx = 0; snapshotIdx < count; snapshotIdx++) { String property = decoder.readString(); long id = decoder.readLong(); builder.put(property, id);/*from www . jav a 2 s . c om*/ } return builder.build(); }
From source file:com.facebook.buck.java.AccumulateClassNamesStep.java
/** * @return an Optional that will be absent if there was an error. *//*from w w w . j a v a 2 s . c om*/ private Optional<ImmutableSortedMap<String, HashCode>> calculateClassHashes(ExecutionContext context, Path path) { final ImmutableSortedMap.Builder<String, HashCode> classNamesBuilder = ImmutableSortedMap.naturalOrder(); ClasspathTraversal traversal = new ClasspathTraversal(Collections.singleton(path), context.getProjectFilesystem()) { @Override public void visit(final FileLike fileLike) throws IOException { // When traversing a JAR file, it may have resources or directory entries that do not // end in .class, which should be ignored. if (!FileLikes.isClassFile(fileLike)) { return; } String key = FileLikes.getFileNameWithoutClassSuffix(fileLike); InputSupplier<InputStream> input = new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return fileLike.getInput(); } }; HashCode value = ByteStreams.hash(input, Hashing.sha1()); classNamesBuilder.put(key, value); } }; try { new DefaultClasspathTraverser().traverse(traversal); } catch (IOException e) { context.logError(e, "Error accumulating class names for %s.", pathToJarOrClassesDirectory); return Optional.absent(); } return Optional.of(classNamesBuilder.build()); }
From source file:org.gradle.api.internal.changedetection.state.TaskExecutionFingerprintSerializer.java
private ImmutableSortedMap<String, HistoricalFileCollectionFingerprint> readFingerprints(Decoder decoder) throws Exception { int count = decoder.readSmallInt(); ImmutableSortedMap.Builder<String, HistoricalFileCollectionFingerprint> builder = ImmutableSortedMap .naturalOrder();//from w w w . j a v a 2s. co m for (int fingerprintIdx = 0; fingerprintIdx < count; fingerprintIdx++) { String property = decoder.readString(); HistoricalFileCollectionFingerprint fingerprint = fileCollectionFingerprintSerializer.read(decoder); builder.put(property, fingerprint); } return builder.build(); }
From source file:org.gradle.api.internal.changedetection.state.LazyTaskExecution.java
private ImmutableSortedMap<String, FileCollectionSnapshot> loadSnapshot(Map<String, Long> snapshotIds) { ImmutableSortedMap.Builder<String, FileCollectionSnapshot> builder = ImmutableSortedMap.naturalOrder(); for (Map.Entry<String, Long> entry : snapshotIds.entrySet()) { String propertyName = entry.getKey(); Long snapshotId = entry.getValue(); FileCollectionSnapshot fileCollectionSnapshot = snapshotRepository.get(snapshotId); builder.put(propertyName, fileCollectionSnapshot); }/*from w w w . ja va2 s . com*/ return builder.build(); }