List of usage examples for com.google.common.collect ImmutableSortedSet naturalOrder
public static <E extends Comparable<?>> Builder<E> naturalOrder()
From source file:com.proofpoint.jmx.JmxInspector.java
@Inject public JmxInspector(Injector injector) throws Exception { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); Set<ObjectInstance> instances = mBeanServer.queryMBeans(null, null); Multimap<String, String> nameMap = ArrayListMultimap.create(); for (ObjectInstance i : instances) { nameMap.put(i.getClassName(), i.getObjectName().getCanonicalName()); }//from w w w .jav a2 s . com ImmutableSortedSet.Builder<InspectorRecord> builder = ImmutableSortedSet.naturalOrder(); GuiceInjectorIterator injectorIterator = new GuiceInjectorIterator(injector); for (Class<?> clazz : injectorIterator) { addConfig(nameMap, clazz, builder); } inspectorRecords = builder.build(); }
From source file:com.ibm.common.geojson.BoundingBox.java
/** * Calculate the Bounding Box for a collection of Polygon objects * @param polygons Iterable<Polygon> * @return BoundingBox/*w ww . ja v a 2 s .c o m*/ */ public static BoundingBox calculateBoundingBoxPolygons(Iterable<Polygon> polygons) { ImmutableSortedSet.Builder<Float> xset = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet.Builder<Float> yset = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet.Builder<Float> zset = ImmutableSortedSet.naturalOrder(); for (Polygon polygon : polygons) { for (LineString line : polygon) { for (Position pos : line) { xset.add(pos.northing()); yset.add(pos.easting()); if (pos.hasAltitude()) zset.add(pos.altitude()); } } } return buildBoundingBox(xset.build(), yset.build(), zset.build()); }
From source file:org.gradle.api.internal.changedetection.state.TaskExecutionSnapshotSerializer.java
public TaskExecutionSnapshot read(Decoder decoder) throws Exception { boolean successful = decoder.readBoolean(); UniqueId buildId = UniqueId.from(decoder.readString()); ImmutableSortedMap<String, Long> inputFilesSnapshotIds = readSnapshotIds(decoder); ImmutableSortedMap<String, Long> outputFilesSnapshotIds = readSnapshotIds(decoder); Long discoveredFilesSnapshotId = decoder.readLong(); ImplementationSnapshot taskImplementation = readImplementation(decoder); // We can't use an immutable list here because some hashes can be null int taskActionsCount = decoder.readSmallInt(); ImmutableList.Builder<ImplementationSnapshot> taskActionImplementationsBuilder = ImmutableList.builder(); for (int j = 0; j < taskActionsCount; j++) { ImplementationSnapshot actionImpl = readImplementation(decoder); taskActionImplementationsBuilder.add(actionImpl); }// w w w . ja v a2s. c o m ImmutableList<ImplementationSnapshot> taskActionImplementations = taskActionImplementationsBuilder.build(); int cacheableOutputPropertiesCount = decoder.readSmallInt(); ImmutableSortedSet.Builder<String> cacheableOutputPropertiesBuilder = ImmutableSortedSet.naturalOrder(); for (int j = 0; j < cacheableOutputPropertiesCount; j++) { cacheableOutputPropertiesBuilder.add(decoder.readString()); } ImmutableSortedSet<String> cacheableOutputProperties = cacheableOutputPropertiesBuilder.build(); int outputFilesCount = decoder.readSmallInt(); ImmutableSet.Builder<String> declaredOutputFilePathsBuilder = ImmutableSet.builder(); for (int j = 0; j < outputFilesCount; j++) { declaredOutputFilePathsBuilder.add(stringInterner.intern(decoder.readString())); } ImmutableSet<String> declaredOutputFilePaths = declaredOutputFilePathsBuilder.build(); ImmutableSortedMap<String, ValueSnapshot> inputProperties = inputPropertiesSerializer.read(decoder); return new TaskExecutionSnapshot(successful, buildId, taskImplementation, taskActionImplementations, cacheableOutputProperties, declaredOutputFilePaths, inputProperties, inputFilesSnapshotIds, discoveredFilesSnapshotId, outputFilesSnapshotIds); }
From source file:com.facebook.buck.rules.TargetNodeFactory.java
@SuppressWarnings("unchecked") public <T, U extends Description<T>> TargetNode<T, U> create(HashCode rawInputsHashCode, U description, T constructorArg, ProjectFilesystem filesystem, BuildTarget buildTarget, ImmutableSet<BuildTarget> declaredDeps, ImmutableSet<VisibilityPattern> visibilityPatterns, CellPathResolver cellRoots) throws NoSuchBuildTargetException { ImmutableSortedSet.Builder<BuildTarget> extraDepsBuilder = ImmutableSortedSet.naturalOrder(); ImmutableSet.Builder<Path> pathsBuilder = ImmutableSet.builder(); // Scan the input to find possible BuildTargets, necessary for loading dependent rules. T arg = description.createUnpopulatedConstructorArg(); for (Field field : arg.getClass().getFields()) { ParamInfo info = new ParamInfo(typeCoercerFactory, arg.getClass(), field); if (info.isDep() && info.isInput() && info.hasElementTypes(BuildTarget.class, SourcePath.class, Path.class)) { detectBuildTargetsAndPathsForConstructorArg(extraDepsBuilder, pathsBuilder, info, constructorArg); }/*from w ww . j a v a 2s.com*/ } if (description instanceof ImplicitDepsInferringDescription) { extraDepsBuilder.addAll(((ImplicitDepsInferringDescription<T>) description) .findDepsForTargetFromConstructorArgs(buildTarget, cellRoots, constructorArg)); } if (description instanceof ImplicitInputsInferringDescription) { pathsBuilder.addAll(((ImplicitInputsInferringDescription<T>) description) .inferInputsFromConstructorArgs(buildTarget.getUnflavoredBuildTarget(), constructorArg)); } return new TargetNode<>(this, rawInputsHashCode, description, constructorArg, filesystem, buildTarget, declaredDeps, ImmutableSortedSet.copyOf(Sets.difference(extraDepsBuilder.build(), declaredDeps)), visibilityPatterns, pathsBuilder.build(), cellRoots, Optional.empty()); }
From source file:com.facebook.buck.jvm.java.DirectToJarOutputSettingsSerializer.java
@SuppressWarnings("unchecked") public static DirectToJarOutputSettings deserialize(Map<String, Object> data) { Preconditions.checkArgument(data.containsKey(OUTPUT_PATH)); Preconditions.checkArgument(data.containsKey(CLASSES_TO_REMOVE)); Preconditions.checkArgument(data.containsKey(ENTRIES)); Path outputPath = Paths.get((String) data.get(OUTPUT_PATH)); ImmutableSet.Builder<Pattern> classesToRemove = ImmutableSet.builder(); for (Map<String, Object> patternData : (List<Map<String, Object>>) data.get(CLASSES_TO_REMOVE)) { Preconditions.checkArgument(patternData.containsKey(CLASSES_TO_REMOVE_PATTERN)); Preconditions.checkArgument(patternData.containsKey(CLASSES_TO_REMOVE_PATTERN_FLAGS)); classesToRemove.add(Pattern.compile((String) patternData.get(CLASSES_TO_REMOVE_PATTERN), (int) patternData.get(CLASSES_TO_REMOVE_PATTERN_FLAGS))); }/* w w w . j a v a 2 s .co m*/ ImmutableSortedSet.Builder<Path> entries = ImmutableSortedSet.naturalOrder(); for (String entry : (List<String>) data.get(ENTRIES)) { entries.add(Paths.get(entry)); } Optional<String> mainClass = Optional.empty(); if (data.containsKey(MAIN_CLASS)) { mainClass = Optional.of((String) data.get(MAIN_CLASS)); } Optional<Path> manifestFile = Optional.empty(); if (data.containsKey(MANIFEST_FILE)) { manifestFile = Optional.of(Paths.get((String) data.get(MANIFEST_FILE))); } return DirectToJarOutputSettings.of(outputPath, classesToRemove.build(), entries.build(), mainClass, manifestFile); }
From source file:org.obm.provisioning.processing.impl.users.sieve.NewSieveContent.java
public Set<String> getAllRequires() { // The 'ordered' part is only useful for testing the serializer ImmutableSortedSet.Builder<String> requiresBuilder = ImmutableSortedSet.naturalOrder(); Optional<OldSieveContent> oldSieveContent = this.getMaybeOldSieveContent(); if (oldSieveContent.isPresent()) { requiresBuilder.addAll(oldSieveContent.get().getRequires()); }/* w w w . j a v a 2s . c o m*/ for (ObmRule obmRule : this.getObmRules()) { requiresBuilder.addAll(obmRule.getRequires()); } return requiresBuilder.build(); }
From source file:com.facebook.buck.java.JavaFileParser.java
public ImmutableSortedSet<String> getExportedSymbolsFromString(String code) throws IOException { ASTParser parser = ASTParser.newParser(jlsLevel); parser.setSource(code.toCharArray()); parser.setKind(ASTParser.K_COMPILATION_UNIT); @SuppressWarnings("unchecked") Map<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(javaVersion, options); parser.setCompilerOptions(options);//from w w w. ja v a 2 s. c o m final CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(/* monitor */ null); final ImmutableSortedSet.Builder<String> symbolsBuilder = ImmutableSortedSet.naturalOrder(); compilationUnit.accept(new ASTVisitor() { @Override public boolean visit(TypeDeclaration node) { // Local classes can be declared inside of methods. Skip over these. if (node.getParent() instanceof TypeDeclarationStatement) { return true; } symbolsBuilder.add(getFullyQualifiedTypeName(node)); return true; } @Override public boolean visit(EnumDeclaration node) { symbolsBuilder.add(getFullyQualifiedTypeName(node)); return true; } }); return symbolsBuilder.build(); }
From source file:org.voltcore.utils.COWNavigableSet.java
@Override public boolean add(E e) { while (true) { ImmutableSortedSet<E> snapshot = m_set.get(); if (snapshot.contains(e)) return false; ImmutableSortedSet.Builder<E> builder = ImmutableSortedSet.naturalOrder(); builder.addAll(snapshot);// w ww. java 2s . c o m builder.add(e); if (m_set.compareAndSet(snapshot, builder.build())) { return true; } } }
From source file:com.facebook.buck.android.AndroidLibraryGraphEnhancer.java
public Result createBuildableForAndroidResources(BuildRuleResolver ruleResolver, boolean createBuildableIfEmptyDeps) { ImmutableSortedSet<BuildRule> originalDeps = originalBuildRuleParams.getDeps(); ImmutableList<HasAndroidResourceDeps> androidResourceDeps = UberRDotJavaUtil .getAndroidResourceDeps(originalDeps); if (androidResourceDeps.isEmpty() && !createBuildableIfEmptyDeps) { return new Result(originalBuildRuleParams, Optional.<DummyRDotJava>absent()); }/* www . j a v a2 s . c om*/ // The androidResourceDeps may contain Buildables, but we need the actual BuildRules. Since this // is going to be used to modify the build graph, we can't just wrap the buildables. Fortunately // we know that the buildables come from the originalDeps. ImmutableSortedSet.Builder<BuildRule> actualDeps = ImmutableSortedSet.naturalOrder(); for (HasAndroidResourceDeps dep : androidResourceDeps) { // If this ever returns null, something has gone horrifically awry. actualDeps.add(ruleResolver.get(dep.getBuildTarget())); } DummyRDotJava dummyRDotJava = new DummyRDotJava(androidResourceDeps, dummyRDotJavaBuildTarget, javacOptions); BuildRule dummyRDotJavaBuildRule = Buildables.createRuleFromBuildable(dummyRDotJava, BuildRuleType.DUMMY_R_DOT_JAVA, dummyRDotJavaBuildTarget, actualDeps.build(), originalBuildRuleParams); ruleResolver.addToIndex(dummyRDotJavaBuildTarget, dummyRDotJavaBuildRule); ImmutableSortedSet<BuildRule> totalDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(originalDeps) .add(dummyRDotJavaBuildRule).build(); BuildRuleParams newBuildRuleParams = originalBuildRuleParams.copyWithChangedDeps(totalDeps); return new Result(newBuildRuleParams, Optional.of(dummyRDotJava)); }
From source file:com.facebook.buck.gwt.GwtBinaryDescription.java
@Override public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver resolver, A args) { SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver); SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder); final ImmutableSortedSet.Builder<BuildRule> extraDeps = ImmutableSortedSet.naturalOrder(); // Find all of the reachable JavaLibrary rules and grab their associated GwtModules. final ImmutableSortedSet.Builder<Path> gwtModuleJarsBuilder = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet<BuildRule> moduleDependencies = resolver.getAllRules(args.moduleDeps); new AbstractBreadthFirstTraversal<BuildRule>(moduleDependencies) { @Override//w ww. j av a 2 s . co m public ImmutableSet<BuildRule> visit(BuildRule rule) { if (!(rule instanceof JavaLibrary)) { return ImmutableSet.of(); } // If the java library doesn't generate any output, it doesn't contribute a GwtModule JavaLibrary javaLibrary = (JavaLibrary) rule; if (javaLibrary.getPathToOutput() == null) { return rule.getDeps(); } BuildTarget gwtModuleTarget = BuildTargets.createFlavoredBuildTarget( javaLibrary.getBuildTarget().checkUnflavored(), JavaLibrary.GWT_MODULE_FLAVOR); Optional<BuildRule> gwtModule = resolver.getRuleOptional(gwtModuleTarget); if (!gwtModule.isPresent() && javaLibrary.getPathToOutput() != null) { ImmutableSortedSet<SourcePath> filesForGwtModule = ImmutableSortedSet.<SourcePath>naturalOrder() .addAll(javaLibrary.getSources()).addAll(javaLibrary.getResources()).build(); ImmutableSortedSet<BuildRule> deps = ImmutableSortedSet .copyOf(ruleFinder.filterBuildRuleInputs(filesForGwtModule)); BuildRule module = resolver.addToIndex(new GwtModule( params.copyWithChanges(gwtModuleTarget, Suppliers.ofInstance(deps), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, ruleFinder, filesForGwtModule)); gwtModule = Optional.of(module); } // Note that gwtModule could be absent if javaLibrary is a rule with no srcs of its own, // but a rule that exists only as a collection of deps. if (gwtModule.isPresent()) { extraDeps.add(gwtModule.get()); gwtModuleJarsBuilder.add(Preconditions.checkNotNull(gwtModule.get().getPathToOutput())); } // Traverse all of the deps of this rule. return rule.getDeps(); } }.start(); return new GwtBinary(params.copyWithExtraDeps(Suppliers.ofInstance(extraDeps.build())), pathResolver, args.modules, javaOptions.getJavaRuntimeLauncher(), args.vmArgs, args.style.orElse(DEFAULT_STYLE), args.draftCompile.orElse(DEFAULT_DRAFT_COMPILE), args.optimize.orElse(DEFAULT_OPTIMIZE), args.localWorkers.orElse(DEFAULT_NUM_LOCAL_WORKERS), args.strict.orElse(DEFAULT_STRICT), args.experimentalArgs, gwtModuleJarsBuilder.build()); }