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:com.google.inject.spi.InjectionPoint.java

private static Set<InjectionPoint> getInjectionPoints(final TypeLiteral<?> type, boolean statics,
        Errors errors) {//from  ww  w  .j  a  v a2 s.  c o m

    InjectableMembers injectableMembers = new InjectableMembers();
    final OverrideIndex overrideIndex = new OverrideIndex(injectableMembers);
    overrideIndex.position = Position.BOTTOM; // we start at the bottom of inheritance hierarchy

    filter.reset();
    try {
        computeInjectableMembers(type, statics, errors, injectableMembers, overrideIndex, filter);
    } catch (AnnotationFieldNotFoundException e) {
        errors.addMessage(e.getMessage());
    }

    if (injectableMembers.isEmpty()) {
        return Collections.emptySet();
    }

    ImmutableSet.Builder<InjectionPoint> builder = ImmutableSet.builder();
    for (InjectableMember im = injectableMembers.head; im != null; im = im.next) {
        try {
            builder.add(im.toInjectionPoint());
        } catch (ConfigurationException ignorable) {
            if (!im.optional) {
                errors.merge(ignorable.getErrorMessages());
            }
        }
    }
    return builder.build();
}

From source file:com.example.processor.common.MoreTypes.java

/**
 * Returns the set of {@linkplain TypeElement types} that are referenced by the given
 * {@link TypeMirror}.//from   ww w  .ja va  2 s  .co m
 */
public static ImmutableSet<TypeElement> referencedTypes(TypeMirror type) {
    checkNotNull(type);
    ImmutableSet.Builder<TypeElement> elements = ImmutableSet.builder();
    type.accept(new SimpleTypeVisitor6<Void, ImmutableSet.Builder<TypeElement>>() {
        @Override
        public Void visitArray(ArrayType t, ImmutableSet.Builder<TypeElement> p) {
            t.getComponentType().accept(this, p);
            return null;
        }

        @Override
        public Void visitDeclared(DeclaredType t, ImmutableSet.Builder<TypeElement> p) {
            p.add(com.google.auto.common.MoreElements.asType(t.asElement()));
            for (TypeMirror typeArgument : t.getTypeArguments()) {
                typeArgument.accept(this, p);
            }
            return null;
        }

        @Override
        public Void visitTypeVariable(TypeVariable t, ImmutableSet.Builder<TypeElement> p) {
            t.getLowerBound().accept(this, p);
            t.getUpperBound().accept(this, p);
            return null;
        }

        @Override
        public Void visitWildcard(WildcardType t, ImmutableSet.Builder<TypeElement> p) {
            TypeMirror extendsBound = t.getExtendsBound();
            if (extendsBound != null) {
                extendsBound.accept(this, p);
            }
            TypeMirror superBound = t.getSuperBound();
            if (superBound != null) {
                superBound.accept(this, p);
            }
            return null;
        }
    }, elements);
    return elements.build();
}

From source file:net.fabricmc.loom.mixin.ObfuscationServiceFabric.java

private void addSupportedOptions(ImmutableSet.Builder builder, String from, String to) {
    builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_FILE, from, to));
    builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_EXTRA_FILES, from, to));
    builder.add(asSuffixed(ObfuscationServiceFabric.OUT_MAP_FILE, from, to));
}

From source file:zipkin2.storage.cassandra.v1.CompositeIndexer.java

CompositeIndexer(CassandraStorage storage, CacheBuilderSpec spec, int indexTtl) {
    this.sharedState = CacheBuilder.from(spec).<PartitionKeyToTraceId, Pair>build().asMap();
    Indexer.Factory factory = new Indexer.Factory(storage.session(), indexTtl, sharedState);
    ImmutableSet.Builder<Indexer> indexers = ImmutableSet.builder();
    indexers.add(factory.create(new InsertTraceIdByServiceName(storage.bucketCount)));
    if (storage.metadata().hasRemoteService) {
        indexers.add(factory.create(new InsertTraceIdByRemoteServiceName()));
    }/*www . jav  a  2s.c  om*/
    indexers.add(factory.create(new InsertTraceIdBySpanName()));
    indexers.add(factory.create(new InsertTraceIdByAnnotation(storage.bucketCount)));
    this.indexers = indexers.build();
}

From source file:com.facebook.buck.apple.project_generator.XCodeProjectCommandHelper.java

@VisibleForTesting
static ImmutableSet<BuildTarget> replaceWorkspacesWithSourceTargetsIfPossible(
        ImmutableSet<BuildTarget> buildTargets, TargetGraph projectGraph) {
    Iterable<TargetNode<?, ?>> targetNodes = projectGraph.getAll(buildTargets);
    ImmutableSet.Builder<BuildTarget> resultBuilder = ImmutableSet.builder();
    for (TargetNode<?, ?> node : targetNodes) {
        if (node.getDescription() instanceof XcodeWorkspaceConfigDescription) {
            TargetNode<XcodeWorkspaceConfigDescriptionArg, ?> castedWorkspaceNode = castToXcodeWorkspaceTargetNode(
                    node);//from  ww w . j av  a2  s . c  om
            Optional<BuildTarget> srcTarget = castedWorkspaceNode.getConstructorArg().getSrcTarget();
            if (srcTarget.isPresent()) {
                resultBuilder.add(srcTarget.get());
            } else {
                resultBuilder.add(node.getBuildTarget());
            }
        } else {
            resultBuilder.add(node.getBuildTarget());
        }
    }
    return resultBuilder.build();
}

From source file:org.apache.gobblin.metrics.context.filter.AllContextFilter.java

private void addContextsRecursively(ImmutableSet.Builder<MetricContext> builder, MetricContext metricContext) {
    builder.add(metricContext);
    for (MetricContext context : metricContext.getChildContextsAsMap().values()) {
        addContextsRecursively(builder, context);
    }/* w  ww.j  av a  2s  .c  o  m*/
}

From source file:com.google.devtools.build.lib.rules.objc.ObjcCommon.java

/**
 * Returns the Xcode structured resource directory paths.
 *
 * <p>For a checked-in source artifact "//a/b/res/sub_dir/d" included by objc rule "//a/b:c",
 * "a/b/res" will be returned. For a generated source artifact "res/sub_dir/d" owned by genrule
 * "//a/b:c", "bazel-out/.../genfiles/a/b/res" will be returned.
 *
 * <p>When XCode sees a included resource directory of "a/b/res", the entire directory structure
 * up to "res" will be copied into the app bundle.
 *///  w w  w  .  ja v a2  s .c  o m
static Iterable<PathFragment> xcodeStructuredResourceDirs(Iterable<Artifact> artifacts) {
    ImmutableSet.Builder<PathFragment> containers = new ImmutableSet.Builder<>();
    for (Artifact artifact : artifacts) {
        PathFragment ownerRuleDirectory = artifact.getArtifactOwner().getLabel().getPackageFragment();
        String containerName = artifact.getRootRelativePath().relativeTo(ownerRuleDirectory).getSegment(0);
        PathFragment rootExecPath = artifact.getRoot().getExecPath();
        containers.add(rootExecPath.getRelative(ownerRuleDirectory.getRelative(containerName)));
    }

    return containers.build();
}

From source file:com.twitter.common.args.Args.java

/**
 * Loads arg info from the given sources in addition to the default compile-time configuration.
 *
 * @param filter A predicate to select fields with.
 * @param sources Classes or object instances to scan for {@link Arg} fields.
 * @return The args info describing all discovered {@link Arg args}.
 * @throws IOException If there was a problem loading the default Args configuration.
 *//*from   w  ww. j av a  2 s. co m*/
public static ArgsInfo from(Predicate<Field> filter, Iterable<?> sources) throws IOException {
    Preconditions.checkNotNull(filter);
    Preconditions.checkNotNull(sources);

    Configuration configuration = Configuration.load();
    ArgsInfo staticInfo = Args.fromConfiguration(configuration, filter);

    final ImmutableSet.Builder<PositionalInfo<?>> positionalInfos = ImmutableSet.<PositionalInfo<?>>builder()
            .addAll(staticInfo.getPositionalInfo().asSet());
    final ImmutableSet.Builder<OptionInfo<?>> optionInfos = ImmutableSet.<OptionInfo<?>>builder()
            .addAll(staticInfo.getOptionInfos());

    for (Object source : sources) {
        Class<?> clazz = source instanceof Class ? (Class) source : source.getClass();
        for (Field field : clazz.getDeclaredFields()) {
            if (filter.apply(field)) {
                boolean cmdLine = field.isAnnotationPresent(CmdLine.class);
                boolean positional = field.isAnnotationPresent(Positional.class);
                if (cmdLine && positional) {
                    throw new IllegalArgumentException(
                            "An Arg cannot be annotated with both @CmdLine and @Positional, found bad Arg "
                                    + "field: " + field);
                } else if (cmdLine) {
                    optionInfos.add(OptionInfo.createFromField(field, source));
                } else if (positional) {
                    positionalInfos.add(PositionalInfo.createFromField(field, source));
                }
            }
        }
    }

    @Nullable
    PositionalInfo<?> positionalInfo = Iterables.getOnlyElement(positionalInfos.build(), null);
    return new ArgsInfo(configuration, Optional.fromNullable(positionalInfo), optionInfos.build());
}

From source file:org.sosy_lab.cpachecker.util.expressions.ExpressionTrees.java

public static <LeafType> ExpressionTreeFactory<LeafType> newCachingFactory() {
    return new ExpressionTreeFactory<LeafType>() {

        private final Map<Object, ExpressionTree<LeafType>> leafCache = Maps.newHashMap();

        private final Map<Object, ExpressionTree<LeafType>> andCache = Maps.newHashMap();

        private final Map<Object, ExpressionTree<LeafType>> orCache = Maps.newHashMap();

        @Override/* w w  w  .  ja v  a 2  s  . co  m*/
        public ExpressionTree<LeafType> leaf(LeafType pLeafType) {
            return leaf(pLeafType, true);
        }

        @Override
        public ExpressionTree<LeafType> leaf(LeafType pLeafExpression, boolean pAssumeTruth) {
            ExpressionTree<LeafType> potentialResult = LeafExpression.of(pLeafExpression, pAssumeTruth);
            ExpressionTree<LeafType> cachedResult = leafCache.get(potentialResult);
            if (cachedResult == null) {
                leafCache.put(potentialResult, potentialResult);
                return potentialResult;
            }
            return cachedResult;
        }

        @Override
        public ExpressionTree<LeafType> and(ExpressionTree<LeafType> pOp1, ExpressionTree<LeafType> pOp2) {
            return and(ImmutableSet.of(pOp1, pOp2));
        }

        @Override
        public ExpressionTree<LeafType> and(Iterable<ExpressionTree<LeafType>> pOperands) {
            final Set<ExpressionTree<LeafType>> key;
            if (pOperands instanceof Set) {
                key = (Set<ExpressionTree<LeafType>>) pOperands;
            } else {
                Iterator<ExpressionTree<LeafType>> operandIterator = pOperands.iterator();
                if (!operandIterator.hasNext()) {
                    return getTrue();
                }
                ExpressionTree<LeafType> first = operandIterator.next();
                if (!operandIterator.hasNext()) {
                    return first;
                }
                ImmutableSet.Builder<ExpressionTree<LeafType>> keyBuilder = ImmutableSet.builder();
                keyBuilder.add(first);
                while (operandIterator.hasNext()) {
                    keyBuilder.add(operandIterator.next());
                }
                key = keyBuilder.build();
            }
            ExpressionTree<LeafType> result = andCache.get(key);
            if (result != null) {
                return result;
            }
            result = And.of(key);
            andCache.put(key, result);
            return result;
        }

        @Override
        public ExpressionTree<LeafType> or(ExpressionTree<LeafType> pOp1, ExpressionTree<LeafType> pOp2) {
            return or(ImmutableSet.of(pOp1, pOp2));
        }

        @Override
        public ExpressionTree<LeafType> or(Iterable<ExpressionTree<LeafType>> pOperands) {
            final Set<ExpressionTree<LeafType>> key;
            if (pOperands instanceof Set) {
                key = (Set<ExpressionTree<LeafType>>) pOperands;
            } else {
                Iterator<ExpressionTree<LeafType>> operandIterator = pOperands.iterator();
                if (!operandIterator.hasNext()) {
                    return getFalse();
                }
                ExpressionTree<LeafType> first = operandIterator.next();
                if (!operandIterator.hasNext()) {
                    return first;
                }
                ImmutableSet.Builder<ExpressionTree<LeafType>> keyBuilder = ImmutableSet.builder();
                keyBuilder.add(first);
                while (operandIterator.hasNext()) {
                    keyBuilder.add(operandIterator.next());
                }
                key = keyBuilder.build();
            }
            ExpressionTree<LeafType> result = orCache.get(key);
            if (result != null) {
                return result;
            }
            result = Or.of(key);
            orCache.put(key, result);
            return result;
        }
    };

}

From source file:org.sonar.plugins.protobuf.api.visitors.SyntaxHighlighterVisitor.java

public SyntaxHighlighterVisitor(ResourcePerspectives resourcePerspectives, FileSystem fs) {
    super(resourcePerspectives, fs);

    ImmutableSet.Builder<String> keywordsBuilder = ImmutableSet.builder();
    keywordsBuilder.add(ProtoBufKeyword.getKeywordValues());
    keywords = keywordsBuilder.build();/*from www. j a va2s  . c  om*/
}