List of usage examples for com.google.common.collect ImmutableSet.Builder add
boolean add(E e);
From source file:de.metas.ui.web.window.datatypes.DocumentIdsSelection.java
public static DocumentIdsSelection ofStringSet(final Collection<String> stringDocumentIds) { if (stringDocumentIds == null || stringDocumentIds.isEmpty()) { return EMPTY; }//from w w w.ja v a 2s. c o m final ImmutableSet.Builder<DocumentId> documentIdsBuilder = ImmutableSet.builder(); for (final String documentIdStr : stringDocumentIds) { if (ALL_String.equals(documentIdStr)) { return ALL; } documentIdsBuilder.add(DocumentId.of(documentIdStr)); } final ImmutableSet<DocumentId> documentIds = documentIdsBuilder.build(); if (documentIds.isEmpty()) { return EMPTY; } return new DocumentIdsSelection(false, documentIds); }
From source file:com.facebook.buck.query.QueryTargetAccessor.java
/** * Filters the objects in the given attribute that satisfy the given predicate. *///from w w w . ja va2s .com public static <T> ImmutableSet<Object> filterAttributeContents(TargetNode<T, ?> node, String attribute, final Predicate<Object> predicate) { try { final ImmutableSet.Builder<Object> builder = ImmutableSet.builder(); Class<?> constructorArgClass = node.getConstructorArg().getClass(); Field field = constructorArgClass.getField(attribute); ParamInfo info = new ParamInfo(typeCoercerFactory, constructorArgClass, field); info.traverse(value -> { if (predicate.apply(value)) { builder.add(value); } }, node.getConstructorArg()); return builder.build(); } catch (NoSuchFieldException e) { // Ignore if the field does not exist in this rule. return ImmutableSet.of(); } }
From source file:com.google.caliper.runner.EffectiveClassPath.java
private static ImmutableSet<File> getClassPathFiles(ClassLoader classLoader) { ImmutableSet.Builder<File> files = ImmutableSet.builder(); @Nullable//from www . j av a 2 s. com ClassLoader parent = classLoader.getParent(); if (parent != null) { files.addAll(getClassPathFiles(parent)); } if (classLoader instanceof URLClassLoader) { URLClassLoader urlClassLoader = (URLClassLoader) classLoader; for (URL url : urlClassLoader.getURLs()) { try { files.add(new File(url.toURI())); } catch (URISyntaxException e) { // skip it then } catch (IllegalArgumentException e) { // skip it then } } } return files.build(); }
From source file:com.facebook.buck.cli.AuditBuildInfoCommand.java
private static ImmutableSet<BuildInfoFields> collectFieldsFromArguments(Collection<String> arguments) throws IllegalArgumentException { ImmutableSet.Builder<BuildInfoFields> fieldsFromArguments = ImmutableSet.builder(); for (String argument : Sets.newHashSet(arguments)) { boolean found = false; for (BuildInfoFields field : BuildInfoFields.values()) { if (field.toString().equalsIgnoreCase(argument)) { fieldsFromArguments.add(field); found = true;/*from ww w . j a v a 2 s .c om*/ break; } } if (!found) { throw new IllegalArgumentException(String.format("Unknown field: %s", argument)); } } return fieldsFromArguments.build(); }
From source file:com.netflix.genie.web.controllers.DtoConverters.java
/** * Convert the V4 values supplied to how the tags would have looked in Genie V3. * * @param id The id of the resource//from ww w .jav a 2 s. com * @param name The name of the resource * @param tags The tags on the resource * @return The set of tags as they would have been in Genie 3 */ public static ImmutableSet<String> toV3Tags(final String id, final String name, final Set<String> tags) { final ImmutableSet.Builder<String> v3Tags = ImmutableSet.builder(); v3Tags.addAll(tags); v3Tags.add(GENIE_ID_PREFIX + id); v3Tags.add(GENIE_NAME_PREFIX + name); return v3Tags.build(); }
From source file:org.opendaylight.yangtools.yang.data.impl.schema.InstanceIdToCompositeNodes.java
private static AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchema augmentation) { final ImmutableSet.Builder<QName> potentialChildren = ImmutableSet.builder(); for (final DataSchemaNode child : augmentation.getChildNodes()) { potentialChildren.add(child.getQName()); }//from w w w .j a va2 s. co m return new AugmentationIdentifier(potentialChildren.build()); }
From source file:com.spotify.heroic.metric.ShardedResultGroup.java
public static MultiSummary summarize(List<ShardedResultGroup> resultGroups) { final ImmutableSet.Builder<Map<String, String>> shardSummary = ImmutableSet.builder(); final Histogram.Builder keySize = Histogram.builder(); final SeriesSetsSummarizer seriesSummarizer = new SeriesSetsSummarizer(); final Histogram.Builder dataSize = Histogram.builder(); Optional<Long> cadence = Optional.empty(); for (ShardedResultGroup rg : resultGroups) { shardSummary.add(rg.getShard()); keySize.add(rg.getKey().size()); seriesSummarizer.add(rg.getSeries()); dataSize.add(rg.getMetrics().size()); cadence = Optional.of(rg.getCadence()); }/*from ww w. jav a2 s .c o m*/ return new MultiSummary(shardSummary.build(), keySize.build(), seriesSummarizer.end(), dataSize.build(), cadence); }
From source file:com.spectralogic.ds3autogen.converters.ResponseTypeConverter.java
/** * Gets a list of response Component Types and original type names that are being converted * into new models that are within the Ds3ResponseTypes list. *///from ww w . jav a 2s . co m protected static ImmutableSet<EncapsulatingTypeNames> getResponseTypesToUpdateFromResponseTypes( final ImmutableList<Ds3ResponseType> responseTypes) { if (isEmpty(responseTypes)) { LOG.debug("No response types for model generation of response component types"); return ImmutableSet.of(); } final ImmutableSet.Builder<EncapsulatingTypeNames> builder = ImmutableSet.builder(); for (final Ds3ResponseType responseType : responseTypes) { if (hasContent(responseType.getComponentType())) { builder.add(new EncapsulatingTypeNames(responseType.getComponentType(), responseType.getOriginalTypeName())); } } return builder.build(); }
From source file:com.netflix.genie.web.controllers.DtoConverters.java
/** * Convert a given V4 {@code criterion} to the equivalent representation in V3 set of tags. * * @param criterion The {@link Criterion} to convert * @return A set of String's representing the criterion tags as they would have looked in V3 *//*from www. ja v a2 s.co m*/ public static ImmutableSet<String> toV3CriterionTags(final Criterion criterion) { final ImmutableSet.Builder<String> tags = ImmutableSet.builder(); criterion.getId().ifPresent(id -> tags.add(GENIE_ID_PREFIX + id)); criterion.getName().ifPresent(name -> tags.add(GENIE_NAME_PREFIX + name)); tags.addAll(criterion.getTags()); return tags.build(); }
From source file:com.google.caliper.runner.target.EffectiveClassPath.java
private static Set<File> getClassPathFiles(ClassLoader classLoader) { ImmutableSet.Builder<File> files = ImmutableSet.builder(); @Nullable//from w w w. j av a2 s. com ClassLoader parent = classLoader.getParent(); if (parent != null) { files.addAll(getClassPathFiles(parent)); } if (classLoader instanceof URLClassLoader) { URLClassLoader urlClassLoader = (URLClassLoader) classLoader; for (URL url : urlClassLoader.getURLs()) { try { files.add(new File(url.toURI())); } catch (URISyntaxException e) { // skip it then } catch (IllegalArgumentException e) { // skip it then } } } return files.build(); }