List of usage examples for com.google.common.collect ImmutableSet.Builder add
boolean add(E e);
From source file:net.techcable.pineapple.collect.ImmutableSets.java
public static <T, U> ImmutableSet<U> transform(ImmutableSet<T> set, Function<T, U> transformer) { ImmutableSet.Builder<U> resultBuilder = builder(checkNotNull(set, "Null set").size()); ImmutableList<T> list = set.asList(); for (int i = 0; i < list.size(); i++) { T oldElement = list.get(i);//www . j av a 2 s. co m U newElement = checkNotNull(transformer, "Null transformer").apply(oldElement); if (newElement == null) throw new NullPointerException( "Transformer " + transformer.getClass().getTypeName() + " returned null."); resultBuilder.add(newElement); } return resultBuilder.build(); }
From source file:paperparcel.PaperParcelDescriptor.java
private static ImmutableSet<String> possibleSetterNames(String name) { ImmutableSet.Builder<String> possibleSetterNames = new ImmutableSet.Builder<>(); if (startsWithPrefix(IS_PREFIX, name)) { possibleSetterNames.add(SET_PREFIX + name.substring(IS_PREFIX.length())); }//from www . j av a2s.c om if (startsWithPrefix(HAS_PREFIX, name)) { possibleSetterNames.add(SET_PREFIX + name.substring(HAS_PREFIX.length())); } possibleSetterNames.add(name); possibleSetterNames.add(SET_PREFIX + Strings.capitalizeAsciiOnly(name)); possibleSetterNames.add(SET_PREFIX + Strings.capitalizeFirstWordAsciiOnly(name)); return possibleSetterNames.build(); }
From source file:org.sonar.java.se.ProgramState.java
private static void addLearnedConstraint(ImmutableSet.Builder<LearnedConstraint> result, SymbolicValue sv, Constraint c) {/*from www . ja va 2 s . co m*/ result.add(new LearnedConstraint(sv, c)); // FIXME this might end up adding twice the same SV in learned constraints. Safe because null constraints are filtered anyway if (sv instanceof BinarySymbolicValue) { BinarySymbolicValue binarySymbolicValue = (BinarySymbolicValue) sv; addLearnedConstraint(result, binarySymbolicValue.getLeftOp(), null); addLearnedConstraint(result, binarySymbolicValue.getRightOp(), null); } }
From source file:io.crate.operation.user.UserManagerService.java
static Set<User> getUsers(@Nullable UsersMetaData metaData, @Nullable UsersPrivilegesMetaData privilegesMetaData) { ImmutableSet.Builder<User> usersBuilder = new ImmutableSet.Builder<User>().add(CRATE_USER); if (metaData != null) { for (String userName : metaData.users()) { Set<Privilege> privileges = null; if (privilegesMetaData != null) { privileges = privilegesMetaData.getUserPrivileges(userName); }//from w ww. j av a 2s .c o m usersBuilder.add( new User(userName, ImmutableSet.of(), privileges == null ? ImmutableSet.of() : privileges)); } } return usersBuilder.build(); }
From source file:com.facebook.buck.cxx.toolchain.nativelink.NativeLinkables.java
/** @return the nodes found from traversing the given roots in topologically sorted order. */ public static ImmutableList<NativeLinkable> getTopoSortedNativeLinkables( Iterable<? extends NativeLinkable> roots, Function<? super NativeLinkable, Stream<? extends NativeLinkable>> depsFn) { Map<BuildTarget, NativeLinkable> nativeLinkables = new HashMap<>(); for (NativeLinkable nativeLinkable : roots) { nativeLinkables.put(nativeLinkable.getBuildTarget(), nativeLinkable); }/*from w w w . j av a 2 s . com*/ MutableDirectedGraph<BuildTarget> graph = new MutableDirectedGraph<>(); AbstractBreadthFirstTraversal<BuildTarget> visitor = new AbstractBreadthFirstTraversal<BuildTarget>( nativeLinkables.keySet()) { @Override public ImmutableSet<BuildTarget> visit(BuildTarget target) { NativeLinkable nativeLinkable = Objects.requireNonNull(nativeLinkables.get(target)); graph.addNode(target); // Process all the traversable deps. ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder(); depsFn.apply(nativeLinkable).forEach(dep -> { BuildTarget depTarget = dep.getBuildTarget(); graph.addEdge(target, depTarget); deps.add(depTarget); nativeLinkables.put(depTarget, dep); }); return deps.build(); } }; visitor.start(); // Topologically sort the rules. ImmutableList<BuildTarget> ordered = TopologicalSort.sort(graph).reverse(); return ordered.stream().map(nativeLinkables::get).collect(ImmutableList.toImmutableList()); }
From source file:org.apache.aurora.benchmark.JobUpdates.java
/** * Saves job updates into provided storage. * * @param storage {@link Storage} instance. * @param updates updates to save.//w w w .j ava 2s . c o m * @return update keys. */ static Set<IJobUpdateKey> saveUpdates(Storage storage, Iterable<IJobUpdateDetails> updates) { ImmutableSet.Builder<IJobUpdateKey> keyBuilder = ImmutableSet.builder(); storage.write((Storage.MutateWork.NoResult.Quiet) store -> { JobUpdateStore.Mutable updateStore = store.getJobUpdateStore(); updateStore.deleteAllUpdatesAndEvents(); for (IJobUpdateDetails details : updates) { IJobUpdateKey key = details.getUpdate().getSummary().getKey(); keyBuilder.add(key); String lockToken = UUID.randomUUID().toString(); store.getLockStore().saveLock(ILock.build(new Lock().setKey(LockKey.job(key.getJob().newBuilder())) .setToken(lockToken).setUser(Builder.USER).setTimestampMs(0L))); updateStore.saveJobUpdate(details.getUpdate(), Optional.of(lockToken)); for (IJobUpdateEvent updateEvent : details.getUpdateEvents()) { updateStore.saveJobUpdateEvent(key, updateEvent); } for (IJobInstanceUpdateEvent instanceEvent : details.getInstanceEvents()) { updateStore.saveJobInstanceUpdateEvent(key, instanceEvent); } } }); return keyBuilder.build(); }
From source file:com.google.devtools.build.android.idlclass.IdlClass.java
/** * For each top-level class in the compilation, determine the path prefix of classes corresponding * to that compilation unit./* w ww . j a va 2s . c o m*/ * * <p>Prefixes are used to correctly handle inner classes, e.g. the top-level class "c.g.Foo" may * correspond to "c/g/Foo.class" and also "c/g/Foo$Inner.class" or "c/g/Foo$0.class". */ @VisibleForTesting static ImmutableSet<String> getIdlPrefixes(Manifest manifest, Set<Path> idlSources) { ImmutableSet.Builder<String> prefixes = ImmutableSet.builder(); for (CompilationUnit unit : manifest.getCompilationUnitList()) { if (!idlSources.contains(Paths.get(unit.getPath()))) { continue; } String pkg; if (unit.hasPkg()) { pkg = unit.getPkg().replace('.', '/') + "/"; } else { pkg = ""; } for (String toplevel : unit.getTopLevelList()) { prefixes.add(pkg + toplevel); } } return prefixes.build(); }
From source file:org.apache.aurora.common.args.Args.java
/** * Loads arg info from the given sources in addition to the default compile-time configuration. * * @param filter A predicate to select fields with. * @param sources Classes or object instances to scan for {@link Arg} fields. * @return The args info describing all discovered {@link Arg args}. * @throws IOException If there was a problem loading the default Args configuration. *//*www .ja v a 2 s . c o m*/ public static ArgsInfo from(Predicate<Field> filter, Iterable<?> sources) throws IOException { Preconditions.checkNotNull(filter); Preconditions.checkNotNull(sources); Configuration configuration = Configuration.load(); ArgsInfo staticInfo = Args.fromConfiguration(configuration, filter); final ImmutableSet.Builder<OptionInfo<?>> optionInfos = ImmutableSet.<OptionInfo<?>>builder() .addAll(staticInfo.getOptionInfos()); for (Object source : sources) { Class<?> clazz = source instanceof Class ? (Class) source : source.getClass(); for (Field field : clazz.getDeclaredFields()) { if (filter.apply(field) && field.isAnnotationPresent(CmdLine.class)) { optionInfos.add(OptionInfo.createFromField(field, source)); } } } return new ArgsInfo(configuration, optionInfos.build()); }
From source file:com.facebook.buck.apple.AppleBuildRules.java
public static ImmutableSet<AppleAssetCatalogDescription.Arg> collectDirectAssetCatalogs(TargetGraph targetGraph, TargetNode<?, ?> targetNode) { ImmutableSet.Builder<AppleAssetCatalogDescription.Arg> builder = ImmutableSet.builder(); Iterable<TargetNode<?, ?>> deps = targetGraph.getAll(targetNode.getDeps()); for (TargetNode<?, ?> node : deps) { if (node.getDescription() instanceof AppleAssetCatalogDescription) { builder.add((AppleAssetCatalogDescription.Arg) node.getConstructorArg()); }//from ww w . j a va 2 s. c o m } return builder.build(); }
From source file:google.registry.model.domain.DomainCommand.java
private static Set<DesignatedContact> linkContacts(Set<ForeignKeyedDesignatedContact> contacts, DateTime now) throws InvalidReferencesException { if (contacts == null) { return null; }//from w w w . j a v a 2 s . c o m ImmutableSet.Builder<String> foreignKeys = new ImmutableSet.Builder<>(); for (ForeignKeyedDesignatedContact contact : contacts) { foreignKeys.add(contact.contactId); } ImmutableMap<String, Key<ContactResource>> loadedContacts = loadByForeignKey(foreignKeys.build(), ContactResource.class, now); ImmutableSet.Builder<DesignatedContact> linkedContacts = new ImmutableSet.Builder<>(); for (ForeignKeyedDesignatedContact contact : contacts) { linkedContacts.add(DesignatedContact.create(contact.type, loadedContacts.get(contact.contactId))); } return linkedContacts.build(); }