Example usage for com.google.common.collect ImmutableSet.Builder add

List of usage examples for com.google.common.collect ImmutableSet.Builder add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:org.onos.yangtools.yang.parser.impl.util.YangModelDependencyInfo.java

private static ImmutableSet<ModuleImport> parseIncludes(final List<Include_stmtContext> importStatements) {
    ImmutableSet.Builder<ModuleImport> builder = ImmutableSet.builder();
    for (Include_stmtContext importStmt : importStatements) {
        String moduleName = getArgumentString(importStmt);
        Date revision = getRevision(importStmt.revision_date_stmt());
        builder.add(new ModuleImportImpl(moduleName, revision));
    }//from w ww .  ja  v  a  2s  .  c  o  m
    return builder.build();
}

From source file:org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter.java

private static final Iterable<YangInstanceIdentifier> getChildrenPaths(final YangInstanceIdentifier entry,
        final Iterable<YangInstanceIdentifier> paths) {
    ImmutableSet.Builder<YangInstanceIdentifier> children = ImmutableSet.builder();
    for (YangInstanceIdentifier potential : paths) {
        if (entry.contains(potential)) {
            children.add(entry);
        }//from  w w w  .ja  va 2 s .  com
    }
    return children.build();
}

From source file:com.cloudera.csd.validation.references.components.ReflectionHelper.java

/**
 * Return the set of getter methods for the class.
 *
 * @param clazz the class.//  w  w  w  .j a  v a 2  s.  c  o m
 * @return the set of getter methods.
 */
public static Set<Method> getterMethods(Class<?> clazz) {
    Preconditions.checkNotNull(clazz);
    try {
        ImmutableSet.Builder<Method> builder = ImmutableSet.builder();
        BeanInfo info = Introspector.getBeanInfo(clazz);
        for (PropertyDescriptor p : info.getPropertyDescriptors()) {
            Method getter = p.getReadMethod();
            if (getter != null) {
                // Don't want to include any of the methods inherited from object.
                if (!getter.getDeclaringClass().equals(Object.class)) {
                    builder.add(getter);
                }
            }
        }
        return builder.build();
    } catch (IntrospectionException e) {
        throw new IllegalStateException("Could not introspect on " + clazz, e);
    }
}

From source file:org.jboss.weld.util.Decorators.java

/**
 * Determines the set of {@link InvokableAnnotatedMethod}s representing decorated methods of the specified decorator. A decorated method
 * is any method declared by a decorated type which is implemented by the decorator.
 *
 * @param beanManager the bean manager//from  w  w  w. java  2  s  .  com
 * @param decorator the specified decorator
 * @return the set of {@link InvokableAnnotatedMethod}s representing decorated methods of the specified decorator
 */
public static Set<InvokableAnnotatedMethod<?>> getDecoratorMethods(BeanManagerImpl beanManager,
        WeldDecorator<?> decorator) {
    ImmutableSet.Builder<InvokableAnnotatedMethod<?>> builder = ImmutableSet.builder();
    for (Type type : decorator.getDecoratedTypes()) {
        EnhancedAnnotatedType<?> weldClass = getWeldClassOfDecoratedType(beanManager, type);
        for (EnhancedAnnotatedMethod<?, ?> method : weldClass.getDeclaredEnhancedMethods()) {
            if (decorator.getEnhancedAnnotated().getEnhancedMethod(method.getSignature()) != null) {
                builder.add(InvokableAnnotatedMethod.of(method.slim()));
            }
        }
    }
    return builder.build();
}

From source file:ca.cutterslade.match.scheduler.Scheduler.java

private static ImmutableSet<Team> padWithByes(ImmutableSet<Tier> tiers, ImmutableSet<Team> realTeams,
        int teamsPerTier) {
    ImmutableSet.Builder<Team> b = ImmutableSet.builder();
    for (Tier tier : tiers) {
        ImmutableSet<Team> tierTeams = ImmutableSet.copyOf(tier.getTeams(realTeams));
        b.addAll(tierTeams);//from   www.jav a 2  s  . co m
        if (tierTeams.size() > teamsPerTier)
            throw new AssertionError("More than allowed number of teams");
        if (tierTeams.size() < teamsPerTier)
            for (int i = 0, n = teamsPerTier - tierTeams.size(); i < n; i++)
                b.add(new Team("B" + i, tier));
    }
    return b.build();
}

From source file:com.twitter.aurora.scheduler.base.Numbers.java

/**
 * Converts a set of integers into a set of contiguous closed ranges that equally represent the
 * input integers.//  w  ww. j a  v a2  s. c om
 * <p>
 * The resulting ranges will be in ascending order.
 *
 * @param values Values to transform to ranges.
 * @return Closed ranges with identical members to the input set.
 */
public static Set<Range<Integer>> toRanges(Iterable<Integer> values) {
    ImmutableSet.Builder<Range<Integer>> builder = ImmutableSet.builder();

    PeekingIterator<Integer> iterator = Iterators.peekingIterator(Sets.newTreeSet(values).iterator());

    // Build ranges until there are no numbers left.
    while (iterator.hasNext()) {
        // Start a new range.
        int start = iterator.next();
        int end = start;
        // Increment the end until the range is non-contiguous.
        while (iterator.hasNext() && (iterator.peek() == (end + 1))) {
            end++;
            iterator.next();
        }

        builder.add(Range.closed(start, end));
    }

    return builder.build();
}

From source file:com.opengamma.strata.product.swap.ResolvedSwap.java

private static ImmutableSet<Currency> buildCurrencies(List<ResolvedSwapLeg> legs) {
    // avoid streams as profiling showed a hotspot
    ImmutableSet.Builder<Currency> builder = ImmutableSet.builder();
    for (ResolvedSwapLeg leg : legs) {
        builder.add(leg.getCurrency());
    }/*from  ww w  .j  a  v a 2 s. c o  m*/
    return builder.build();
}

From source file:org.basepom.mojo.duplicatefinder.artifact.ArtifactFileResolver.java

private static Set<Artifact> findRepoArtifacts(final MavenProject project,
        final Map<Artifact, File> repoArtifactCache) {
    final ImmutableSet.Builder<Artifact> builder = ImmutableSet.builder();

    for (final Artifact artifact : repoArtifactCache.keySet()) {
        if (Objects.equals(project.getArtifact().getGroupId(), artifact.getGroupId())
                && Objects.equals(project.getArtifact().getArtifactId(), artifact.getArtifactId())
                && Objects.equals(project.getArtifact().getBaseVersion(), artifact.getBaseVersion())) {
            builder.add(artifact);
        }/*from   ww w  .j  a  v a  2  s .  c om*/
    }
    return builder.build();
}

From source file:com.facebook.buck.apple.simulator.SimctlListOutputParsing.java

private static void parseLine(String line, ImmutableSet.Builder<AppleSimulator> simulatorsBuilder) {
    LOG.debug("Parsing simctl list output line: %s", line);
    Matcher matcher = SIMCTL_LIST_DEVICES_PATTERN.matcher(line);
    if (matcher.matches() && matcher.group(DEVICE_UNAVAILABLE_GROUP) == null) {
        AppleSimulator simulator = AppleSimulator.builder().setName(matcher.group(DEVICE_NAME_GROUP))
                .setUdid(matcher.group(DEVICE_UDID_GROUP))
                .setSimulatorState(AppleSimulatorState.fromString(matcher.group(DEVICE_STATE_GROUP))).build();
        LOG.debug("Got simulator: %s", simulator);
        simulatorsBuilder.add(simulator);
    }//from   ww  w  . ja  v  a  2  s.  c  om
}

From source file:com.facebook.buck.cxx.platform.NativeLinkables.java

/**
 * Extract from the dependency graph all the libraries which must be considered for linking.
 *
 * <p>Traversal proceeds depending on whether each dependency is to be statically or dynamically
 * linked./*w w w  . j  a  va  2 s. com*/
 *
 * @param linkStyle how dependencies should be linked, if their preferred_linkage is {@code
 *     NativeLinkable.Linkage.ANY}.
 */
public static ImmutableMap<BuildTarget, NativeLinkable> getNativeLinkables(final CxxPlatform cxxPlatform,
        Iterable<? extends NativeLinkable> inputs, final Linker.LinkableDepType linkStyle,
        final Predicate<? super NativeLinkable> traverse) {

    final Map<BuildTarget, NativeLinkable> nativeLinkables = new HashMap<>();
    for (NativeLinkable nativeLinkable : inputs) {
        nativeLinkables.put(nativeLinkable.getBuildTarget(), nativeLinkable);
    }

    final MutableDirectedGraph<BuildTarget> graph = new MutableDirectedGraph<>();
    AbstractBreadthFirstTraversal<BuildTarget> visitor = new AbstractBreadthFirstTraversal<BuildTarget>(
            nativeLinkables.keySet()) {
        @Override
        public ImmutableSet<BuildTarget> visit(BuildTarget target) {
            NativeLinkable nativeLinkable = Preconditions.checkNotNull(nativeLinkables.get(target));
            graph.addNode(target);

            // We always traverse a rule's exported native linkables.
            Iterable<? extends NativeLinkable> nativeLinkableDeps = nativeLinkable
                    .getNativeLinkableExportedDepsForPlatform(cxxPlatform);

            boolean shouldTraverse = true;
            switch (nativeLinkable.getPreferredLinkage(cxxPlatform)) {
            case ANY:
                shouldTraverse = linkStyle != Linker.LinkableDepType.SHARED;
                break;
            case SHARED:
                shouldTraverse = false;
                break;
            case STATIC:
                shouldTraverse = true;
                break;
            }

            // If we're linking this dependency statically, we also need to traverse its deps.
            if (shouldTraverse) {
                nativeLinkableDeps = Iterables.concat(nativeLinkableDeps,
                        nativeLinkable.getNativeLinkableDepsForPlatform(cxxPlatform));
            }

            // Process all the traversable deps.
            ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();
            for (NativeLinkable dep : nativeLinkableDeps) {
                if (traverse.apply(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.
    Iterable<BuildTarget> ordered = TopologicalSort.sort(graph).reverse();

    // Return a map of of the results.
    ImmutableMap.Builder<BuildTarget, NativeLinkable> result = ImmutableMap.builder();
    for (BuildTarget target : ordered) {
        result.put(target, nativeLinkables.get(target));
    }
    return result.build();
}