List of usage examples for com.google.common.collect ImmutableSet builder
public static <E> Builder<E> builder()
From source file:de.dennishoersch.util.inspection.InstanceCollector.java
public InstanceCollector(Class<T> interfaceClass, String basePackage) { Collection<Class<? extends T>> implementations = ClassInspectionUtil.findClassesImplementing(interfaceClass, basePackage);// w ww . jav a 2 s.c o m ImmutableSet.Builder<T> instances = ImmutableSet.builder(); for (Class<? extends T> impl : filter(implementations, not(isAnonymous()))) { instances.addAll(getInstances(impl)); } _instances = instances.build(); }
From source file:edu.mit.streamjit.util.ReflectionUtils.java
/** * Returns an immutable set of all fields in the given class or its * superclasses and superinterfaces, with any access modifier, static or * nonstatic./* w ww. ja v a2 s .com*/ * @param klass the class to get fields of * @return an immutable set of all fields in the class, including inherited * and static fields */ public static ImmutableSet<Field> getAllFields(Class<?> klass) { checkNotNull(klass); ImmutableSet.Builder<Field> builder = ImmutableSet.builder(); while (klass != null) { builder.addAll(Arrays.asList(klass.getDeclaredFields())); for (Class<?> i : klass.getInterfaces()) builder.addAll(Arrays.asList(i.getDeclaredFields())); klass = klass.getSuperclass(); } return builder.build(); }
From source file:org.locationtech.geogig.api.plumbing.ForEachRef.java
/** * @return the new value of the ref//from w ww .j av a 2s.co m */ @Override protected ImmutableSet<Ref> _call() { @SuppressWarnings("unchecked") final Predicate<Ref> filter = (Predicate<Ref>) (this.filter == null ? Predicates.alwaysTrue() : this.filter); ImmutableSet.Builder<Ref> refs = new ImmutableSet.Builder<Ref>(); for (String refName : refDatabase().getAll().keySet()) { Optional<Ref> ref = command(RefParse.class).setName(refName).call(); if (ref.isPresent() && filter.apply(ref.get())) { Ref accepted = ref.get(); refs.add(accepted); } } return refs.build(); }
From source file:com.google.api.server.spi.auth.EndpointsPeerAuthenticator.java
private static ImmutableSet<String> getLocalHostAddresses() { ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<>(); try {//from w w w .java2 s. co m builder.add(InetAddress.getLocalHost().getHostAddress()); } catch (IOException e) { // try next. } try { builder.add(InetAddress.getByName(null).getHostAddress()); } catch (IOException e) { // try next. } try { for (InetAddress inetAddress : InetAddress.getAllByName("localhost")) { builder.add(inetAddress.getHostAddress()); } } catch (IOException e) { // check at the end. } ImmutableSet<String> localHostSet = builder.build(); if (localHostSet.isEmpty()) { logger.warning("Unable to lookup local addresses."); } return localHostSet; }
From source file:org.springframework.ide.eclipse.boot.dash.livexp.MapSet.java
@Override protected ImmutableSet<T> compute() { ImmutableSet.Builder<T> builder = ImmutableSet.builder(); for (S a : input.getValues()) { T v = function.apply(a);//from w w w. jav a 2 s .com //Check for null, generally google collections don't allow nulls (which is good) // and we can take advantage of returning nulls to combine mapping and filtering with // a single function. if (v != null) { builder.add(v); } } return builder.build(); }
From source file:org.obiba.onyx.magma.ScriptedVariableValueSourceFactory.java
public Set<VariableValueSource> createSources() { if (resource.exists() == false) { return ImmutableSet.of(); }/*from w w w. ja v a 2s . com*/ try { ImmutableSet.Builder<VariableValueSource> sources = new ImmutableSet.Builder<VariableValueSource>(); ObjectInputStream ois = getXStream().createObjectInputStream(resource.getInputStream()); try { while (true) { Variable variable = (Variable) ois.readObject(); sources.add(new JavascriptVariableValueSource(variable)); } } catch (EOFException e) { // Reached the end of the file. } finally { ois.close(); } return sources.build(); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.facebook.buck.cxx.CxxInferCaptureRulesAggregator.java
public ImmutableSet<CxxInferCapture> getAllTransitiveCaptures() { ImmutableSet.Builder<CxxInferCapture> captureBuilder = ImmutableSet.builder(); captureBuilder.addAll(captureAndTransitiveAggregatingRules.captureRules); for (CxxInferCaptureRulesAggregator aggregator : captureAndTransitiveAggregatingRules.aggregatingRules) { captureBuilder.addAll(aggregator.getCaptureRules()); }//from ww w . j av a2 s.c o m return captureBuilder.build(); }
From source file:google.registry.flows.domain.DomainTransferUtils.java
/** * Sets up {@link TransferData} for a domain with links to entities for server approval. */// w w w .j a v a 2 s. c o m public static TransferData createPendingTransferData(TransferData.Builder transferDataBuilder, ImmutableSet<TransferServerApproveEntity> serverApproveEntities) { ImmutableSet.Builder<Key<? extends TransferServerApproveEntity>> serverApproveEntityKeys = new ImmutableSet.Builder<>(); for (TransferServerApproveEntity entity : serverApproveEntities) { serverApproveEntityKeys.add(Key.create(entity)); } return transferDataBuilder.setTransferStatus(TransferStatus.PENDING) .setServerApproveBillingEvent( Key.create(getOnlyElement(filter(serverApproveEntities, BillingEvent.OneTime.class)))) .setServerApproveAutorenewEvent( Key.create(getOnlyElement(filter(serverApproveEntities, BillingEvent.Recurring.class)))) .setServerApproveAutorenewPollMessage( Key.create(getOnlyElement(filter(serverApproveEntities, PollMessage.Autorenew.class)))) .setServerApproveEntities(serverApproveEntityKeys.build()).build(); }
From source file:com.google.inject.internal.util.SourceProvider.java
private SourceProvider(SourceProvider parent, Iterable<String> classesToSkip) { this.parent = parent; ImmutableSet.Builder<String> classNamesToSkipBuilder = ImmutableSet.builder(); for (String classToSkip : classesToSkip) { if (parent == null || !parent.shouldBeSkipped(classToSkip)) { classNamesToSkipBuilder.add(classToSkip); }/*w ww.ja va 2s .c om*/ } this.classNamesToSkip = classNamesToSkipBuilder.build(); }
From source file:com.spotify.heroic.aggregation.Chain.java
@Override public AggregationInstance apply(final AggregationContext context) { ListIterator<Aggregation> it = chain.listIterator(chain.size()); AggregationContext current = context; final ImmutableSet.Builder<String> tags = ImmutableSet.builder(); final ImmutableList.Builder<AggregationInstance> chain = ImmutableList.builder(); while (it.hasPrevious()) { final AggregationInstance instance = it.previous().apply(current); tags.addAll(instance.requiredTags()); current = current.withRequiredTags(tags.build()); chain.add(instance);/* w w w . j a va2 s . c o m*/ } return ChainInstance.fromList(Lists.reverse(chain.build())); }