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.apache.flex.compiler.internal.css.semantics.CSSSemanticAnalyzer.java

/**
 * Collect all the selectors in the CSS document including the subjects and
 * the combination selectors.//ww  w  . j  a v  a 2s .  c o  m
 * 
 * @param document CSS document
 * @return All the selectors in the CSS.
 */
public static ImmutableSet<ICSSSelector> getAllSelectors(final ICSSDocument document) {
    assert document != null : "Expected CSS document";

    final ImmutableSet.Builder<ICSSSelector> builder = new ImmutableSet.Builder<ICSSSelector>();
    for (final ICSSRule rule : document.getRules()) {
        for (final ICSSSelector subject : rule.getSelectorGroup()) {
            ICSSSelector selector = subject;
            while (selector != null) {
                builder.add(selector);
                if (selector.getCombinator() != null)
                    selector = selector.getCombinator().getSelector();
                else
                    selector = null;
            }
        }
    }
    return builder.build();
}

From source file:com.publictransitanalytics.scoregenerator.workflow.ProgressiveRangeExecutor.java

private static Set<PointLocation> updateRow(final Set<ReachabilityOutput> reachabilities,
        final Map<PointLocation, DynamicProgrammingRecord> stateMap, final PointLocation priorLocation,
        final TimeTracker timeTracker) {
    final ImmutableSet.Builder<PointLocation> builder = ImmutableSet.builder();
    for (final ReachabilityOutput reachability : reachabilities) {
        final PointLocation newLocation = reachability.getLocation();
        final LocalDateTime newTime = reachability.getReachTime();

        final ModeInfo mode = reachability.getModeInfo();

        final DynamicProgrammingRecord newRecord = new DynamicProgrammingRecord(newTime, mode, priorLocation);

        if (stateMap.containsKey(newLocation)) {
            final DynamicProgrammingRecord currentRecord = stateMap.get(newLocation);
            if (timeTracker.shouldReplace(currentRecord.getReachTime(), newTime)) {
                stateMap.put(newLocation, newRecord);
                builder.add(newLocation);
            }//  w  w w  .  ja  v  a 2s. c  o  m
        } else {
            stateMap.put(newLocation, newRecord);
            builder.add(newLocation);
        }

    }
    return builder.build();
}

From source file:com.google.javascript.jscomp.newtypes.ObjectType.java

static ImmutableSet<ObjectType> withLooseObjects(Set<ObjectType> objs) {
    ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder();
    for (ObjectType obj : objs) {
        newObjs.add(obj.withLoose());
    }//from w  w w . j a  v a2s. co m
    return newObjs.build();
}

From source file:com.google.javascript.jscomp.newtypes.ObjectType.java

static ImmutableSet<ObjectType> withoutProperty(Set<ObjectType> objs, QualifiedName qname) {
    ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder();
    for (ObjectType obj : objs) {
        newObjs.add(obj.withProperty(qname, null));
    }/*w  w  w.  ja v a  2  s  . c  o m*/
    return newObjs.build();
}

From source file:com.google.javascript.jscomp.newtypes.ObjectType.java

static ImmutableSet<ObjectType> withProperty(Set<ObjectType> objs, QualifiedName qname, JSType type) {
    ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder();
    for (ObjectType obj : objs) {
        newObjs.add(obj.withProperty(qname, type));
    }/*from   w  w w  .j a v a  2 s .c  o m*/
    return newObjs.build();
}

From source file:com.google.javascript.jscomp.newtypes.ObjectType.java

static ImmutableSet<ObjectType> withPropertyRequired(Set<ObjectType> objs, String pname) {
    ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder();
    for (ObjectType obj : objs) {
        newObjs.add(obj.withPropertyRequired(pname));
    }/*from   w  ww  .  j  av  a  2  s  .  com*/
    return newObjs.build();
}

From source file:com.google.javascript.jscomp.newtypes.ObjectType.java

static ImmutableSet<ObjectType> withDeclaredProperty(Set<ObjectType> objs, QualifiedName qname, JSType type,
        boolean isConstant) {
    ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder();
    for (ObjectType obj : objs) {
        newObjs.add(obj.withPropertyHelper(qname, type, true, isConstant));
    }/*from  w w w  .ja  va2s.c  o  m*/
    return newObjs.build();
}

From source file:com.publictransitanalytics.scoregenerator.workflow.DynamicProgrammingAlgorithm.java

private static Set<PointLocation> updateRow(final Set<ReachabilityOutput> reachabilities,
        final Map<PointLocation, DynamicProgrammingRecord> stateMap, final PointLocation priorLocation,
        final TimeTracker timeTracker) {
    final ImmutableSet.Builder<PointLocation> builder = ImmutableSet.builder();
    for (final ReachabilityOutput reachability : reachabilities) {
        final PointLocation newLocation = reachability.getLocation();
        final LocalDateTime newTime = reachability.getReachTime();

        final ModeInfo mode = reachability.getModeInfo();

        final DynamicProgrammingRecord record = new DynamicProgrammingRecord(newTime, mode, priorLocation);

        if (stateMap.containsKey(newLocation)) {
            final DynamicProgrammingRecord earlierThisRoundReach = stateMap.get(newLocation);
            final LocalDateTime earlierThisRoundTime = earlierThisRoundReach.getReachTime();

            if (timeTracker.shouldReplace(earlierThisRoundTime, newTime)) {
                stateMap.put(newLocation, record);
                builder.add(newLocation);
            }//from   w w w  .j  a va  2s. c  o  m
        } else {
            stateMap.put(newLocation, record);
            builder.add(newLocation);
        }
    }
    return builder.build();
}

From source file:com.google.errorprone.dataflow.nullnesspropagation.inference.NullnessQualifierInference.java

private static void findUnannotatedTypeVarRefs(TypeVariableSymbol typeVar, Tree sourceNode, Type type,
        @Nullable Symbol decl, ArrayDeque<Integer> partialSelector,
        ImmutableSet.Builder<InferenceVariable> resultBuilder) {
    checkArgument(decl == null || partialSelector.isEmpty());
    List<Type> typeArguments = type.getTypeArguments();
    for (int i = 0; i < typeArguments.size(); i++) {
        partialSelector.push(i);//from   w w  w  . j  av a2s  .c  om
        findUnannotatedTypeVarRefs(typeVar, sourceNode, typeArguments.get(i), /*decl=*/ null, partialSelector,
                resultBuilder);
        partialSelector.pop();
    }
    if (type.tsym.equals(typeVar) && !extractExplicitNullness(type, decl).isPresent()) {
        resultBuilder.add(TypeArgInferenceVar.create(ImmutableList.copyOf(partialSelector), sourceNode));
    }
}

From source file:com.facebook.buck.jvm.java.intellij.IjProjectTemplateDataPreparer.java

public static ImmutableSet<Path> createPackageLookupPathSet(IjModuleGraph moduleGraph) {
    ImmutableSet.Builder<Path> builder = ImmutableSet.builder();

    for (IjModule module : moduleGraph.getModuleNodes()) {
        for (IjFolder folder : module.getFolders()) {
            if (!folder.getWantsPackagePrefix()) {
                continue;
            }//from  w w w  .  j  ava 2  s . co  m
            Optional<Path> firstJavaFile = folder.getInputs().stream()
                    .filter(input -> input.getFileName().toString().endsWith(".java")).findFirst();
            if (firstJavaFile.isPresent()) {
                builder.add(firstJavaFile.get());
            }
        }
    }

    return builder.build();
}