List of usage examples for com.google.common.collect ImmutableSet builder
public static <E> Builder<E> builder()
From source file:com.twitter.common.net.pool.DynamicHostSetUtil.java
/** * Gets a snapshot of a set of dynamic hosts (e.g. a ServerSet) and returns a readable copy of * the underlying actual endpoints.//w ww. j ava 2 s.c o m * * @param hostSet The hostSet to snapshot. * @throws MonitorException if there was a problem obtaining the snapshot. */ public static <T> ImmutableSet<T> getSnapshot(DynamicHostSet<T> hostSet) throws MonitorException { final ImmutableSet.Builder<T> snapshot = ImmutableSet.builder(); Command unwatch = hostSet.watch(new HostChangeMonitor<T>() { @Override public void onChange(ImmutableSet<T> hostSet) { snapshot.addAll(hostSet); } }); unwatch.execute(); return snapshot.build(); }
From source file:com.facebook.presto.sql.planner.optimizations.AggregationNodeUtils.java
public static Set<Symbol> extractUnique(AggregationNode.Aggregation aggregation) { ImmutableSet.Builder<Symbol> builder = ImmutableSet.builder(); aggregation.getArguments().forEach(argument -> builder.addAll(SymbolsExtractor.extractAll(argument))); aggregation.getFilter().ifPresent(filter -> builder.addAll(SymbolsExtractor.extractAll(filter))); aggregation.getOrderBy().ifPresent(orderingScheme -> builder.addAll(orderingScheme.getOrderBy().stream() .map(VariableReferenceExpression::getName).map(Symbol::new).collect(toImmutableSet()))); return builder.build(); }
From source file:com.spectralogic.ds3autogen.utils.ArgumentsUtil.java
/** * Retrieves the set of all types within a list of Arguments *//*from w w w. j a va 2s . co m*/ public static ImmutableSet<String> getAllArgumentTypes(final ImmutableList<Arguments> args) { if (isEmpty(args)) { return ImmutableSet.of(); } final ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (final Arguments arg : args) { builder.add(arg.getType()); } return builder.build(); }
From source file:com.google.caliper.runner.target.TargetModule.java
@Provides static ImmutableSet<VmType> vmTypes(ImmutableSet<Target> targets) { ImmutableSet.Builder<VmType> builder = ImmutableSet.builder(); for (Target target : targets) { builder.add(target.vm().type()); }//from ww w .j a v a2 s. com return builder.build(); }
From source file:com.google.cloud.dataflow.sdk.options.PipelineOptionsReflector.java
/** * Retrieve metadata for the full set of pipeline options visible within the type hierarchy * of a single {@link PipelineOptions} interface. * * @see PipelineOptionsReflector#getOptionSpecs(Iterable) *///ww w.j av a 2 s .c o m static Set<PipelineOptionSpec> getOptionSpecs(Class<? extends PipelineOptions> optionsInterface) { Iterable<Method> methods = ReflectHelpers.getClosureOfMethodsOnInterface(optionsInterface); Multimap<String, Method> propsToGetters = getPropertyNamesToGetters(methods); ImmutableSet.Builder<PipelineOptionSpec> setBuilder = ImmutableSet.builder(); for (Map.Entry<String, Method> propAndGetter : propsToGetters.entries()) { String prop = propAndGetter.getKey(); Method getter = propAndGetter.getValue(); @SuppressWarnings("unchecked") Class<? extends PipelineOptions> declaringClass = (Class<? extends PipelineOptions>) getter .getDeclaringClass(); if (!PipelineOptions.class.isAssignableFrom(declaringClass)) { continue; } if (declaringClass.isAnnotationPresent(Hidden.class)) { continue; } setBuilder.add(PipelineOptionSpec.of(declaringClass, prop, getter)); } return setBuilder.build(); }
From source file:com.facebook.buck.query.QueryTargetAccessor.java
public static <T> ImmutableSet<QueryTarget> getTargetsInAttribute(TargetNode<T, ?> node, String attribute) { try {/* w w w.j a v a2s . c o m*/ final ImmutableSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder(); Class<?> constructorArgClass = node.getConstructorArg().getClass(); Field field = constructorArgClass.getField(attribute); ParamInfo info = new ParamInfo(typeCoercerFactory, constructorArgClass, field); info.traverse(value -> { if (value instanceof Path) { builder.add(QueryFileTarget.of((Path) value)); } else if (value instanceof SourcePath) { builder.add(extractSourcePath((SourcePath) value)); } else if (value instanceof HasBuildTarget) { builder.add(extractBuildTargetContainer((HasBuildTarget) 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.doubleclick.openrtb.CompanionTypeMapper.java
public static ImmutableSet<CompanionType> toOpenRtb(Collection<CreativeFormat> dcList) { ImmutableSet.Builder<CompanionType> openrtbSet = ImmutableSet.builder(); for (CreativeFormat dc : dcList) { openrtbSet.add(toOpenRtb(dc));//w w w . ja v a 2 s .co m } return openrtbSet.build(); }
From source file:net.techcable.pineapple.collect.ImmutableSets.java
public static <T, U> ImmutableSet<U> transform(Set<T> set, Function<T, U> transformer) { ImmutableSet.Builder<U> resultBuilder = builder(checkNotNull(set, "Null list").size()); set.forEach((oldElement) -> {/* w w w . java 2 s. c om*/ 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:org.immutables.value.processor.meta.CaseStructure.java
private static Set<String> buildImplementedTypesSet(List<ValueType> implementationTypes) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (ValueType discoveredValue : implementationTypes) { builder.add(discoveredValue.typeValue().toString()); }/*from w ww.ja va 2 s. c om*/ return builder.build(); }
From source file:com.google.doubleclick.openrtb.ExpandableDirectionMapper.java
public static ImmutableSet<ExpandableDirection> toOpenRtb(List<Integer> dcList) { boolean left = true, right = true, up = true, down = true; for (int dc : dcList) { switch (dc) { case 13 /* ExpandingDirection: ExpandingUp */: up = false;// w ww. j a v a2s . com break; case 14 /* ExpandingDirection: ExpandingDown */: down = false; break; case 15 /* ExpandingDirection: ExpandingLeft */: left = false; break; case 16 /* ExpandingDirection: ExpandingRight */: right = false; break; default: } } ImmutableSet.Builder<ExpandableDirection> openrtbSet = ImmutableSet.builder(); if (left) { openrtbSet.add(ExpandableDirection.LEFT); } if (right) { openrtbSet.add(ExpandableDirection.RIGHT); } if (up) { openrtbSet.add(ExpandableDirection.UP); } if (down) { openrtbSet.add(ExpandableDirection.DOWN); } return openrtbSet.build(); }