List of usage examples for com.google.common.collect ImmutableSortedSet naturalOrder
public static <E extends Comparable<?>> Builder<E> naturalOrder()
From source file:edu.mit.streamjit.impl.compiler2.Storage.java
/** * Returns a set containing the indices live before the initialization * schedule; that is, the indices holding initial data. The returned set is * not cached so as to be responsive to changes in initial data index * functions./* w ww . jav a2s.com*/ * @return the indices holding initial data * @see #initialDataIndexSpan() */ public ImmutableSortedSet<Integer> initialDataIndices() { ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder(); for (Pair<ImmutableList<Object>, IndexFunction> p : initialData()) for (int i = 0; i < p.first.size(); ++i) try { builder.add(p.second.applyAsInt(i)); } catch (Throwable ex) { throw new AssertionError("index functions should not throw", ex); } return builder.build(); }
From source file:com.facebook.buck.android.UnzipAar.java
@Override public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) { ImmutableList.Builder<Step> steps = ImmutableList.builder(); steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), unpackDirectory)); steps.add(new UnzipStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(aarFile), unpackDirectory));/*from w ww .ja v a 2 s .co m*/ steps.add(new TouchStep(getProjectFilesystem(), getProguardConfig())); steps.add(new MkdirStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(getAssetsDirectory()))); steps.add(new MkdirStep(getProjectFilesystem(), getNativeLibsDirectory())); steps.add(new TouchStep(getProjectFilesystem(), getTextSymbolsFile())); // We take the classes.jar file that is required to exist in an .aar and merge it with any // .jar files under libs/ into an "uber" jar. We do this for simplicity because we do not know // how many entries there are in libs/ at graph enhancement time, but we need to make sure // that all of the .class files in the .aar get packaged. As it is implemented today, an // android_library that depends on an android_prebuilt_aar can compile against anything in the // .aar's classes.jar or libs/. steps.add(new MkdirStep(getProjectFilesystem(), uberClassesJar.getParent())); steps.add(new AbstractExecutionStep("create_uber_classes_jar") { @Override public StepExecutionResult execute(ExecutionContext context) { Path libsDirectory = unpackDirectory.resolve("libs"); boolean dirDoesNotExistOrIsEmpty; if (!getProjectFilesystem().exists(libsDirectory)) { dirDoesNotExistOrIsEmpty = true; } else { try { dirDoesNotExistOrIsEmpty = getProjectFilesystem().getDirectoryContents(libsDirectory) .isEmpty(); } catch (IOException e) { context.logError(e, "Failed to get directory contents of %s", libsDirectory); return StepExecutionResult.ERROR; } } Path classesJar = unpackDirectory.resolve("classes.jar"); JavacEventSinkToBuckEventBusBridge eventSink = new JavacEventSinkToBuckEventBusBridge( context.getBuckEventBus()); if (!getProjectFilesystem().exists(classesJar)) { try { JarDirectoryStepHelper.createEmptyJarFile(getProjectFilesystem(), classesJar, eventSink, context.getStdErr()); } catch (IOException e) { context.logError(e, "Failed to create empty jar %s", classesJar); return StepExecutionResult.ERROR; } } if (dirDoesNotExistOrIsEmpty) { try { getProjectFilesystem().copy(classesJar, uberClassesJar, ProjectFilesystem.CopySourceMode.FILE); } catch (IOException e) { context.logError(e, "Failed to copy from %s to %s", classesJar, uberClassesJar); return StepExecutionResult.ERROR; } } else { // Glob all of the contents from classes.jar and the entries in libs/ into a single JAR. ImmutableSortedSet.Builder<Path> entriesToJarBuilder = ImmutableSortedSet.naturalOrder(); entriesToJarBuilder.add(classesJar); try { entriesToJarBuilder.addAll(getProjectFilesystem().getDirectoryContents(libsDirectory)); } catch (IOException e) { context.logError(e, "Failed to get directory contents of %s", libsDirectory); return StepExecutionResult.ERROR; } ImmutableSortedSet<Path> entriesToJar = entriesToJarBuilder.build(); try { JarDirectoryStepHelper.createJarFile(getProjectFilesystem(), uberClassesJar, entriesToJar, /* mainClass */ Optional.empty(), /* manifestFile */ Optional.empty(), /* mergeManifests */ true, /* blacklist */ ImmutableSet.of(), eventSink, context.getStdErr()); } catch (IOException e) { context.logError(e, "Failed to jar %s into %s", entriesToJar, uberClassesJar); return StepExecutionResult.ERROR; } } return StepExecutionResult.SUCCESS; } }); steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTextSymbolsDir)); steps.add(new ExtractFromAndroidManifestStep(getAndroidManifest(), getProjectFilesystem(), buildableContext, METADATA_KEY_FOR_R_DOT_JAVA_PACKAGE, pathToRDotJavaPackageFile)); steps.add(CopyStep.forFile(getProjectFilesystem(), getTextSymbolsFile(), pathToTextSymbolsFile)); buildableContext.recordArtifact(unpackDirectory); buildableContext.recordArtifact(uberClassesJar); buildableContext.recordArtifact(pathToTextSymbolsFile); buildableContext.recordArtifact(pathToRDotJavaPackageFile); return steps.build(); }
From source file:com.google.auto.factory.processor.AutoFactoryProcessor.java
private void doProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (Element element : roundEnv.getElementsAnnotatedWith(Provided.class)) { providedChecker.checkProvidedParameter(element); }/*from www . java 2 s . co m*/ ImmutableListMultimap.Builder<String, FactoryMethodDescriptor> indexedMethods = ImmutableListMultimap .builder(); ImmutableSet.Builder<ImplemetationMethodDescriptor> implemetationMethodDescriptors = ImmutableSet.builder(); for (Element element : roundEnv.getElementsAnnotatedWith(AutoFactory.class)) { Optional<AutoFactoryDeclaration> declaration = declarationFactory.createIfValid(element); if (declaration.isPresent()) { TypeElement extendingType = declaration.get().extendingType(); List<ExecutableElement> supertypeMethods = ElementFilter .methodsIn(elements.getAllMembers(extendingType)); for (ExecutableElement supertypeMethod : supertypeMethods) { if (supertypeMethod.getModifiers().contains(Modifier.ABSTRACT)) { ExecutableType methodType = Elements2.getExecutableElementAsMemberOf(types, supertypeMethod, extendingType); implemetationMethodDescriptors .add(new ImplemetationMethodDescriptor.Builder() .name(supertypeMethod.getSimpleName().toString()) .returnType(getAnnotatedType(element).getQualifiedName().toString()) .publicMethod() .passedParameters(Parameter.forParameterList( supertypeMethod.getParameters(), methodType.getParameterTypes())) .build()); } } for (TypeElement implementingType : declaration.get().implementingTypes()) { List<ExecutableElement> interfaceMethods = ElementFilter .methodsIn(elements.getAllMembers(implementingType)); for (ExecutableElement interfaceMethod : interfaceMethods) { if (interfaceMethod.getModifiers().contains(Modifier.ABSTRACT)) { ExecutableType methodType = Elements2.getExecutableElementAsMemberOf(types, interfaceMethod, implementingType); implemetationMethodDescriptors.add(new ImplemetationMethodDescriptor.Builder() .name(interfaceMethod.getSimpleName().toString()) .returnType(getAnnotatedType(element).getQualifiedName().toString()) .publicMethod() .passedParameters(Parameter.forParameterList(interfaceMethod.getParameters(), methodType.getParameterTypes())) .build()); } } } } ImmutableSet<FactoryMethodDescriptor> descriptors = factoryDescriptorGenerator .generateDescriptor(element); indexedMethods.putAll(Multimaps.index(descriptors, new Function<FactoryMethodDescriptor, String>() { @Override public String apply(FactoryMethodDescriptor descriptor) { return descriptor.factoryName(); } })); } for (Entry<String, Collection<FactoryMethodDescriptor>> entry : indexedMethods.build().asMap().entrySet()) { ImmutableSet.Builder<String> extending = ImmutableSet.builder(); ImmutableSortedSet.Builder<String> implementing = ImmutableSortedSet.naturalOrder(); boolean publicType = false; for (FactoryMethodDescriptor methodDescriptor : entry.getValue()) { extending.add(methodDescriptor.declaration().extendingType().getQualifiedName().toString()); for (TypeElement implementingType : methodDescriptor.declaration().implementingTypes()) { implementing.add(implementingType.getQualifiedName().toString()); } publicType |= methodDescriptor.publicMethod(); } try { factoryWriter.writeFactory( new FactoryDescriptor(entry.getKey(), Iterables.getOnlyElement(extending.build()), implementing.build(), publicType, ImmutableSet.copyOf(entry.getValue()), // TODO(gak): this needs to be indexed too implemetationMethodDescriptors.build())); } catch (IOException e) { messager.printMessage(Kind.ERROR, "failed"); } } }
From source file:com.facebook.buck.cli.TargetPatternEvaluator.java
ImmutableMap<String, ImmutableSet<QueryTarget>> resolveBuildTargetPatterns(List<String> patterns, ListeningExecutorService executor) throws InterruptedException, BuildFileParseException, BuildTargetException, IOException { // Build up an ordered list of patterns and pass them to the parse to get resolved in one go. // The returned list of nodes maintains the spec list ordering. List<TargetNodeSpec> specs = new ArrayList<>(); for (String pattern : patterns) { specs.addAll(targetNodeSpecParser.parse(rootCell.getCellPathResolver(), pattern)); }// ww w . ja v a 2 s. c o m ImmutableList<ImmutableSet<BuildTarget>> buildTargets = parser.resolveTargetSpecs(eventBus, rootCell, enableProfiling, executor, specs, SpeculativeParsing.of(false), // We disable mapping //path/to:lib to //path/to:lib#default,static // because the query engine doesn't handle flavors very well. ParserConfig.ApplyDefaultFlavorsMode.DISABLED); LOG.verbose("Resolved target patterns %s -> targets %s", patterns, buildTargets); // Convert the ordered result into a result map of pattern to set of resolved targets. ImmutableMap.Builder<String, ImmutableSet<QueryTarget>> queryTargets = ImmutableMap.builder(); for (int index = 0; index < buildTargets.size(); index++) { ImmutableSet<BuildTarget> targets = buildTargets.get(index); // Sorting to have predictable results across different java libraries implementations. ImmutableSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder(); for (BuildTarget target : targets) { builder.add(QueryBuildTarget.of(target)); } queryTargets.put(patterns.get(index), builder.build()); } return queryTargets.build(); }
From source file:com.facebook.buck.core.build.engine.buildinfo.BuildInfoRecorder.java
private ImmutableSortedSet<Path> getRecordedOutputDirsAndFiles() throws IOException { ImmutableSortedSet.Builder<Path> paths = ImmutableSortedSet.naturalOrder(); // Add files from output directories. for (Path output : pathsToOutputs) { projectFilesystem.walkRelativeFileTree(output, new SimpleFileVisitor<Path>() { @Override//from w ww .j a v a 2s . c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { paths.add(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { paths.add(dir); return FileVisitResult.CONTINUE; } }); } return paths.build(); }
From source file:google.registry.tools.UniformRapidSuspensionCommand.java
private ImmutableSortedSet<String> getExistingLocks(DomainResource domain) { ImmutableSortedSet.Builder<String> locks = ImmutableSortedSet.naturalOrder(); for (StatusValue lock : domain.getStatusValues()) { if (URS_LOCKS.contains(lock.getXmlName())) { locks.add(lock.getXmlName()); }// ww w.j av a 2 s . co m } return locks.build(); }
From source file:org.basepom.mojo.duplicatefinder.artifact.ArtifactFileResolver.java
public ImmutableSortedSet<ClasspathElement> getClasspathElementsForElements(final Collection<File> elements) { final ImmutableSortedSet.Builder<ClasspathElement> builder = ImmutableSortedSet.naturalOrder(); for (final File element : elements) { resolveClasspathElementsForFile(element, builder); }//from w w w .j a v a2 s. c o m return builder.build(); }
From source file:com.facebook.buck.rules.modern.ModernBuildRule.java
private ImmutableSortedSet<BuildRule> computeDeps() { ImmutableSortedSet.Builder<BuildRule> depsBuilder = ImmutableSortedSet.naturalOrder(); classInfo.visit(buildable, new DepsComputingVisitor(inputRuleResolver, depsBuilder::add)); return depsBuilder.build(); }
From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java
/** * Returns the physical indices read from the given storage during the given * group iterations.//from ww w. j a v a 2 s .c om * @param s the storage being read from * @param iterations the group iterations * @return the physical indices read */ public ImmutableSortedSet<Integer> reads(Storage s, Range<Integer> iterations) { iterations = iterations.canonical(DiscreteDomain.integers()); ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder(); for (Actor a : actors()) builder.addAll(a.reads(s, Range.closedOpen(iterations.lowerEndpoint() * schedule.get(a), iterations.upperEndpoint() * schedule.get(a)))); return builder.build(); }
From source file:com.facebook.buck.core.model.targetgraph.AbstractNodeBuilder.java
@SuppressWarnings("unchecked") public ImmutableSortedSet<BuildTarget> findImplicitDeps() { ImplicitDepsInferringDescription<TArg> desc = (ImplicitDepsInferringDescription<TArg>) description; ImmutableSortedSet.Builder<BuildTarget> builder = ImmutableSortedSet.naturalOrder(); desc.findDepsForTargetFromConstructorArgs(target, cellRoots, getPopulatedArg(), builder, ImmutableSortedSet.naturalOrder()); return builder.build(); }