Example usage for com.google.common.collect ImmutableSet builder

List of usage examples for com.google.common.collect ImmutableSet builder

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet builder.

Prototype

public static <E> Builder<E> builder() 

Source Link

Usage

From source file:com.proofpoint.event.monitor.MonitorLoader.java

public Set<Monitor> load(String json) {
    ImmutableSet.Builder<Monitor> monitors = ImmutableSet.builder();
    Map<String, MonitorJson> monitorJsonMap = codec.fromJson(json);
    for (Entry<String, MonitorJson> entry : monitorJsonMap.entrySet()) {
        String name = entry.getKey();
        MonitorJson monitorJson = entry.getValue();
        Monitor monitor = new Monitor(name, monitorJson.getEventType(), executor,
                monitorJson.getEventPredicate(), monitorJson.getMinOneMinuteRate(),
                monitorJson.getMaxOneMinuteRate(), alerter);
        monitors.add(monitor);//from  w  w  w  .ja v  a  2  s.  c  om
    }
    return monitors.build();
}

From source file:com.proofpoint.discovery.client.balancing.HttpServiceBalancerListenerAdapter.java

@Override
public void updateServiceDescriptors(Iterable<ServiceDescriptor> newDescriptors) {
    Builder<URI> builder = ImmutableSet.builder();

    for (ServiceDescriptor serviceDescriptor : newDescriptors) {
        String https = serviceDescriptor.getProperties().get("https");
        if (https != null) {
            try {
                builder.add(new URI(https));
                continue;
            } catch (URISyntaxException ignored) {
            }/*  w  ww . j  a  v  a 2  s .  co m*/
        }

        String http = serviceDescriptor.getProperties().get("http");
        if (http != null) {
            try {
                builder.add(new URI(http));
            } catch (URISyntaxException ignored) {
            }
        }
    }

    balancer.updateHttpUris(builder.build());
}

From source file:com.publictransitanalytics.scoregenerator.schedule.patching.PatchingTripCreator.java

public PatchingTripCreator(final List<Patch> patches, final TransitNetwork baseNetwork) {

    final ImmutableSet.Builder<Trip> builder = ImmutableSet.builder();
    for (final Trip originalTrip : baseNetwork.getTrips()) {
        Trip trip = originalTrip;//from   ww w .  j a  v  a  2s .c  o m
        boolean retain = true;
        for (final Patch patch : patches) {
            final Optional<Trip> result = patch.patch(trip);
            if (!result.isPresent()) {
                retain = false;
                break;
            }
            trip = result.get();
        }
        if (retain) {
            builder.add(trip);
        }
    }
    trips = builder.build();
}

From source file:com.google.idea.blaze.base.lang.buildfile.language.semantics.BuiltInNamesProvider.java

/** Returns all built-in rules and function names. */
public static ImmutableSet<String> getBuiltInFunctionNames(Project project) {
    ImmutableSet.Builder<String> builder = ImmutableSet.<String>builder().addAll(FUNCTIONS);
    BuildLanguageSpec spec = BuildLanguageSpecProvider.getInstance().getLanguageSpec(project);
    if (spec != null) {
        builder = builder.addAll(spec.getKnownRuleNames());
    }/*from   w w  w  .  j av a  2  s . c o  m*/
    return builder.build();
}

From source file:com.facebook.buck.rules.visibility.VisibilityPatternFactory.java

@SuppressWarnings("unchecked")
public ImmutableSet<VisibilityPattern> createFromStringList(CellPathResolver cellNames, String paramName,
        @Nullable Object value, BuildTarget target) {
    if (value == null) {
        return ImmutableSet.of();
    }/*from ww w  .  ja  va 2 s .  c  o  m*/
    if (!(value instanceof List)) {
        throw new RuntimeException(String.format("Expected an array for %s but was %s", paramName, value));
    }
    ImmutableSet.Builder<VisibilityPattern> patterns = new ImmutableSet.Builder<>();
    VisibilityPatternParser parser = new VisibilityPatternParser();
    for (String visibility : (List<String>) value) {
        try {
            patterns.add(parser.parse(cellNames, visibility));
        } catch (IllegalArgumentException e) {
            throw new HumanReadableException(e,
                    "Bad visibility expression: %s listed %s in its %s argument, but only %s "
                            + "or fully qualified target patterns are allowed (i.e. those starting with "
                            + "// or a cell).",
                    target.getFullyQualifiedName(), visibility, paramName,
                    VisibilityPatternParser.VISIBILITY_PUBLIC);
        }
    }
    return patterns.build();
}

From source file:uk.ac.ebi.mdk.io.text.kegg.KEGGReactionField.java

private KEGGReactionField(String... names) {
    ImmutableSet.Builder<String> ns = new ImmutableSet.Builder<String>();
    for (String name : names) {
        ns.add(name);/* w  ww  . j ava  2s  .c  o m*/
    }
    ns.add(name());
    this.names = ns.build();
}

From source file:com.flowlogix.security.cdi.AnnotatedTypeWrapper.java

public AnnotatedTypeWrapper(AnnotatedType<T> wrapped, boolean keepOriginalAnnotations,
        Annotation... additionalAnnotations) {
    this.wrapped = wrapped;
    ImmutableSet.Builder<Annotation> builder = ImmutableSet.<Annotation>builder();
    if (keepOriginalAnnotations) {
        builder.addAll(wrapped.getAnnotations());
    }//from   w w  w.jav  a2s.c  om
    annotations = builder.add(additionalAnnotations).build();
}

From source file:com.fatboyindustrial.omnium.ImmutableCollectors.java

/**
 * Gets a collector that returns an {@link ImmutableSet}.
 * @param <T> The type of element in the set.
 * @return The collector./* w ww.ja  v  a2  s  .co m*/
 */
public static <T> Collector<T, ImmutableSet.Builder<T>, ImmutableSet<T>> toImmutableSet() {
    return Collector.of(ImmutableSet::builder, (set, entry) -> set.add(entry),
            (builder1, builder2) -> builder1.addAll(builder2.build()), ImmutableSet.Builder::build, UNORDERED);
}

From source file:org.sonar.server.computation.ws.TaskTypesAction.java

public TaskTypesAction(CeTaskProcessor[] taskProcessors) {
    ImmutableSet.Builder<String> taskTypesBuilder = ImmutableSet.builder();
    for (CeTaskProcessor taskProcessor : taskProcessors) {
        taskTypesBuilder.addAll(taskProcessor.getHandledCeTaskTypes());
    }/*from  w  w  w  .  ja  va  2  s.c om*/
    this.taskTypes = taskTypesBuilder.build();
}

From source file:com.facebook.buck.android.UnsortedAndroidResourceDeps.java

/**
 * Returns transitive android resource deps which are _not_ sorted topologically, only to be used
 * when the order of the resource rules does not matter, for instance, when graph enhancing
 * UberRDotJava, DummyRDotJava, AaptPackageResources where we only need the deps to correctly
 * order the execution of those buildables.
 *//* www.j a  va 2  s.  c om*/
public static UnsortedAndroidResourceDeps createFrom(Collection<BuildRule> rules,
        final Optional<Callback> callback) {

    final ImmutableSet.Builder<HasAndroidResourceDeps> androidResources = ImmutableSet.builder();

    // This visitor finds all AndroidResourceRules that are reachable from the specified rules via
    // rules with types in the TRAVERSABLE_TYPES collection.
    AbstractBreadthFirstTraversal<BuildRule> visitor = new AbstractBreadthFirstTraversal<BuildRule>(rules) {

        @Override
        public ImmutableSet<BuildRule> visit(BuildRule rule) {
            HasAndroidResourceDeps androidResourceRule = null;
            if (rule instanceof HasAndroidResourceDeps) {
                androidResourceRule = (HasAndroidResourceDeps) rule;
            }
            if (androidResourceRule != null && androidResourceRule.getRes() != null) {
                androidResources.add(androidResourceRule);
            }

            // Only certain types of rules should be considered as part of this traversal.
            ImmutableSet<BuildRule> depsToVisit = BuildRuleDependencyVisitors.maybeVisitAllDeps(rule,
                    TRAVERSABLE_TYPES.contains(rule.getClass()));
            if (callback.isPresent()) {
                callback.get().onRuleVisited(rule, depsToVisit);
            }
            return depsToVisit;
        }

    };
    visitor.start();

    return new UnsortedAndroidResourceDeps(androidResources.build());
}