List of usage examples for com.google.common.collect ImmutableSet builder
public static <E> Builder<E> builder()
From source file:com.facebook.buck.android.dalvik.DalvikStatsTool.java
/** CLI wrapper to run against every class in a set of JARs. */ public static void main(String[] args) throws IOException { ImmutableSet.Builder<DalvikMemberReference> allFields = ImmutableSet.builder(); for (String fname : args) { try (ZipFile inJar = new ZipFile(fname)) { for (ZipEntry entry : Collections.list(inJar.entries())) { if (!entry.getName().endsWith(".class")) { continue; }// w w w. jav a 2 s .c om InputStream rawClass = inJar.getInputStream(entry); Stats stats = getEstimate(rawClass); System.out .println(stats.estimatedLinearAllocSize + "\t" + entry.getName().replace(".class", "")); allFields.addAll(stats.fieldReferences); } } } // Uncomment to debug fields. // System.out.println(); // // for (DalvikMemberReference field : allFields.build()) { // System.out.println(field); // } }
From source file:com.github.hilcode.versionator.Main.java
public static final void main(final String[] args) throws Exception { final PomParser pomParser = new DefaultPomParser(); final PomFinder pomFinder = new DefaultPomFinder(pomParser); final CommandLineInterface.Basics basics = new CommandLineInterface.Basics(); final JCommander commander = new JCommander(basics); final CommandLineInterface.CommandList commandList = new CommandLineInterface.CommandList(); commander.addCommand(CommandLineInterface.CommandList.COMMAND, commandList); final CommandSetVersion commandSetVersion = new CommandSetVersion(); commander.addCommand(CommandSetVersion.COMMAND, commandSetVersion); final CommandRelease commandRelease = new CommandRelease(); commander.addCommand(CommandRelease.COMMAND, commandRelease); try {/*from w ww. ja v a2 s .c o m*/ commander.parse(args); if (basics.help != null || basics.version != null) { if (basics.version != null) { System.out.println( String.format("Versionator %s\n%s", Versionator.VERSION, Versionator.RELEASE_DATE)); } if (basics.help != null) { commander.usage(); } return; } if (CommandLineInterface.CommandList.COMMAND.equals(commander.getParsedCommand())) { final Command.List list = new Command.List(new File(commandList.rootDir), ImmutableList.copyOf(commandList.patterns), commandList.verbose ? Command.Verbosity.VERBOSE : Command.Verbosity.NORMAL, commandList.groupByPom ? Command.Grouping.BY_POM : Command.Grouping.BY_GAV); new ListExecutor(pomParser, pomFinder, list).execute(); } else if (CommandSetVersion.COMMAND.equals(commander.getParsedCommand())) { final Command.SetVersion setVersion = new Command.SetVersion(new File(commandSetVersion.rootDir), commandSetVersion.dryRun ? Command.RunType.DRY_RUN : Command.RunType.ACTUAL, commandSetVersion.interactive ? Command.Interactivity.INTERACTIVE : Command.Interactivity.NOT_INTERACTIVE, commandSetVersion.colourless ? Command.Colour.NO_COLOUR : Command.Colour.COLOUR, ImmutableList.<String>copyOf(commandSetVersion.gavs)); final Model model = Model.BUILDER.build(pomFinder.findAllPoms(setVersion.rootDir)); final ImmutableList.Builder<Gav> changedGavsBuilder = ImmutableList.builder(); for (final String gavAsText : setVersion.gavs) { changedGavsBuilder.add(Gav.BUILDER.build(gavAsText)); } final Model result = model.apply(changedGavsBuilder.build()); final ModelWriter modelWriter = new ModelWriter(new VersionSetter(), new PropertySetter()); modelWriter.write(model, result); } else if (CommandRelease.COMMAND.equals(commander.getParsedCommand())) { final Command.Release release = new Command.Release(new File(commandRelease.rootDir), commandRelease.dryRun ? Command.RunType.DRY_RUN : Command.RunType.ACTUAL, commandRelease.interactive ? Command.Interactivity.INTERACTIVE : Command.Interactivity.NOT_INTERACTIVE, commandRelease.colourless ? Command.Colour.NO_COLOUR : Command.Colour.COLOUR, ImmutableList.<String>copyOf(commandRelease.exclusions)); final ImmutableSet.Builder<GroupArtifact> exclusionsBuilder = ImmutableSet.builder(); for (final String exclusionAsText : release.exclusions) { exclusionsBuilder.add(GroupArtifact.BUILDER.build(exclusionAsText)); } final ImmutableSet<GroupArtifact> exclusions = exclusionsBuilder.build(); final Model model = Model.BUILDER.build(pomFinder.findAllPoms(release.rootDir)); final Model result = model.release(exclusions); final ModelWriter modelWriter = new ModelWriter(new VersionSetter(), new PropertySetter()); modelWriter.write(model, result); } else { System.err.println("No command provided. Perhaps try --help?"); } } catch (final ParameterException e) { System.err.println(e.getMessage()); } }
From source file:ca.cutterslade.match.scheduler.Time.java
static ImmutableSet<Time> forNames(Set<String> names) { ImmutableSet.Builder<Time> b = ImmutableSet.builder(); for (String name : names) b.add(new Time(name)); return b.build(); }
From source file:com.stackframe.sarariman.Utilities.java
public static <K, V extends Object> Set<K> allKeys(Iterable<Map<K, V>> maps) { ImmutableSet.Builder<K> builder = ImmutableSet.<K>builder(); for (Map<K, V> map : maps) { builder.addAll(map.keySet());// w w w. j av a 2 s . com } return builder.build(); }
From source file:com.codingopus.guava.custom.collectors.ImmutableSetCollector.java
/** * @returns a {@link Collector} that collects data in * {@link ImmutableSet}.//from w w w . j a v a2 s.com * * @param <T> The type of input elements for the new * collector. * */ public static <T> Collector<T, ImmutableSet.Builder<T>, ImmutableSet<T>> toSetCollector() { return Collector.of(ImmutableSet.Builder<T>::new, ImmutableSet.Builder<T>::add, (left, right) -> left.addAll(right.build()), ImmutableSet.Builder<T>::build); }
From source file:ca.cutterslade.match.scheduler.Court.java
static ImmutableSet<Court> forNames(Set<String> names, Set<Gym> gyms) { ImmutableSet.Builder<Court> b = ImmutableSet.builder(); for (Gym gym : gyms) for (String name : names) b.add(new Court(name, gym)); return b.build(); }
From source file:com.facebook.buck.ide.intellij.aggregation.ModuleAggregator.java
public static AggregationModule aggregate(AggregationModule rootModule, Collection<AggregationModule> modulesToAggregate, ImmutableSet<Path> excludes) { ImmutableSet.Builder<TargetNode<?, ?>> targets = ImmutableSet.<TargetNode<?, ?>>builder() .addAll(rootModule.getTargets()); modulesToAggregate.forEach(module -> targets.addAll(module.getTargets())); ImmutableSet.Builder<Path> excludesBuilder = ImmutableSet.<Path>builder().addAll(excludes); modulesToAggregate.forEach(module -> { Path modulePath = rootModule.getModuleBasePath().relativize(module.getModuleBasePath()); module.getExcludes().stream().map(modulePath::resolve).forEach(excludesBuilder::add); });//from w ww.j a v a2 s . c o m return AggregationModule.builder().from(rootModule).addAllTargets(targets.build()) .setExcludes(excludesBuilder.build()).build(); }
From source file:dk.ilios.spanner.util.Reflection.java
public static ImmutableSet<Method> getAnnotatedMethods(Class<?> clazz, Class<? extends Annotation> annotationClass) { Method[] methods = clazz.getDeclaredMethods(); ImmutableSet.Builder<Method> builder = ImmutableSet.builder(); for (Method method : methods) { if (method.isAnnotationPresent(annotationClass)) { method.setAccessible(true);/*from ww w .j a v a 2s.c om*/ builder.add(method); } } return builder.build(); }
From source file:com.google.template.soy.types.parse.ParseErrors.java
/** Pretty prints the parse exception message. */ static String formatParseException(ParseException e) { Token errorToken = e.currentToken;//from www . j a v a 2s. c om if (errorToken.next != null) { errorToken = errorToken.next; } ImmutableSet.Builder<String> expectedTokenImages = ImmutableSet.builder(); for (int[] expected : e.expectedTokenSequences) { // We only display the first token expectedTokenImages.add(getTokenDisplayName(expected[0])); } return formatParseExceptionDetails(errorToken.image, expectedTokenImages.build().asList()); }
From source file:org.mule.module.extension.internal.util.CapabilityUtils.java
/** * Returns the items in {@code capabilities} which * are instances of {@code capabilityType} * * @param capabilities a {@link Set} of capabilities * @param capabilityType the type of the capabilities you seek * @return a sub {@link Set} of {@code capabilities} *//*w w w . j ava2s . co m*/ public static <T> Set<T> getCapabilities(Set<?> capabilities, Class<T> capabilityType) { ImmutableSet.Builder<T> matches = ImmutableSet.builder(); for (Object capability : capabilities) { if (capabilityType.isInstance(capability)) { matches.add((T) capability); } } return matches.build(); }