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:io.ytcode.reflect.Reflect.java

public static ImmutableSet<Method> methods(Class<?> c, Predicate<Method> p) {
    checkNotNull(c);//www.j  a v  a2  s.c  o  m
    checkNotNull(p);

    ImmutableSet.Builder<Method> b = ImmutableSet.builder();
    for (Method method : c.getDeclaredMethods()) {
        if (p.apply(method)) {
            b.add(method);
        }
    }

    for (Class<?> cls : superTypes(c)) {
        for (Method method : cls.getDeclaredMethods()) {
            if (p.apply(method)) {
                b.add(method);
            }
        }
    }
    return b.build();
}

From source file:com.google.javascript.jscomp.Diagnostics.java

private static ImmutableSet<DiagnosticGroup> initJscheckerGroups() {
    ImmutableSet.Builder<DiagnosticGroup> builder = new ImmutableSet.Builder<>();
    for (String groupName : JSCHECKER_ONLY_ERRORS) {
        builder.add(GROUPS.forName(groupName));
    }/* w w w .  j  a  v a  2  s  .  co m*/
    return builder.build();
}

From source file:com.facebook.buck.cli.LabelSelector.java

static LabelSelector fromString(String raw) {
    Preconditions.checkNotNull(raw);//from   w ww.  java 2s .  c om
    Preconditions.checkState(!raw.isEmpty());

    boolean isInclusive = true;
    if (raw.charAt(0) == '!') {
        isInclusive = false;
        raw = raw.substring(1);
    }

    ImmutableSet.Builder<Label> labelBuilder = new ImmutableSet.Builder<>();
    Iterable<String> labelStrings = splitter.split(raw);
    for (String labelString : labelStrings) {
        BuckConfig.validateLabelName(labelString);
        labelBuilder.add(new Label(labelString));
    }

    return new LabelSelector(isInclusive, labelBuilder.build());
}

From source file:edu.uchicago.lowasser.flaginjection.Converters.java

private static <T> Converter<Set<T>> setConverter(final Converter<T> converter) {
    return new Converter<Set<T>>() {
        @Override// ww w.ja va  2s . co  m
        public Set<T> parse(String string) {
            Iterable<String> components = Splitter.on(',').trimResults().split(string);
            ImmutableSet.Builder<T> builder = ImmutableSet.builder();
            for (String s : components) {
                builder.add(converter.parse(s));
            }
            return builder.build();
        }
    };
}

From source file:com.facebook.buck.io.filesystem.impl.DefaultProjectFilesystemFactory.java

private static ImmutableSet<PathMatcher> extractIgnorePaths(Path root, Config config, BuckPaths buckPaths,
        Optional<EmbeddedCellBuckOutInfo> embeddedCellBuckOutInfo) {
    ImmutableSet.Builder<PathMatcher> builder = ImmutableSet.builder();

    FileSystem rootFs = root.getFileSystem();

    builder.add(RecursiveFileMatcher.of(rootFs.getPath(".idea")));

    String projectKey = "project";
    String ignoreKey = "ignore";

    String buckdDirProperty = System.getProperty(BUCK_BUCKD_DIR_KEY, ".buckd");
    if (!Strings.isNullOrEmpty(buckdDirProperty)) {
        addPathMatcherRelativeToRepo(root, builder, rootFs.getPath(buckdDirProperty));
    }//from  w ww  .j  a  va 2  s.com

    Path cacheDir = DefaultProjectFilesystem.getCacheDir(root, config.getValue("cache", "dir"), buckPaths);
    addPathMatcherRelativeToRepo(root, builder, cacheDir);

    Optional<Path> mainCellBuckOut = getMainCellBuckOut(root, embeddedCellBuckOutInfo);

    config.getListWithoutComments(projectKey, ignoreKey).forEach(input -> {
        // We don't really want to ignore the output directory when doing things like
        // filesystem walks, so return null
        if (buckPaths.getBuckOut().toString().equals(input)) {
            return; // root.getFileSystem().getPathMatcher("glob:**");
        }

        // For the same reason as above, we don't really want to ignore the buck-out of other
        // cells either. They may contain artifacts that we want to use in this cell.
        // TODO: The below does this for the root cell, but this should be true of all cells.
        if (mainCellBuckOut.isPresent() && mainCellBuckOut.get().toString().equals(input)) {
            return;
        }

        if (GLOB_CHARS.matcher(input).find()) {
            builder.add(GlobPatternMatcher.of(input));
            return;
        }
        addPathMatcherRelativeToRepo(root, builder, rootFs.getPath(input));
    });

    return builder.build();
}

From source file:io.ytcode.reflect.Reflect.java

public static ImmutableSet<Class<?>> superTypes(Class<?> c, Predicate<Class<?>> p) {
    checkNotNull(c);/*from w  w  w .j  av  a 2s.  c om*/
    checkNotNull(p);

    ImmutableSet.Builder<Class<?>> b = ImmutableSet.builder();
    Class<?> c1 = c.getSuperclass();
    if (c1 != null) {
        if (p.apply(c1)) {
            b.add(c1);
        }
        b.addAll(superTypes(c1, p));
    }

    Class<?>[] c2s = c.getInterfaces();
    if (c2s != null) {
        for (Class<?> c2 : c2s) {
            if (p.apply(c2)) {
                b.add(c2);
            }
            b.addAll(superTypes(c2, p));
        }
    }

    return b.build();
}

From source file:com.publictransitanalytics.scoregenerator.output.ComparativePointAccessibility.java

private static Set<MovementPath> getBestPathSet(final Map<LogicalTask, MovementPath> taskPaths) {
    final ImmutableSet.Builder<MovementPath> bestPathsBuilder = ImmutableSet.builder();

    for (final MovementPath taskPath : taskPaths.values()) {
        if (taskPath != null) {
            bestPathsBuilder.add(taskPath);
        }//  ww  w  .j  av  a2s . c om
    }
    return bestPathsBuilder.build();
}

From source file:com.google.template.soy.exprparse.ParseErrors.java

static void reportExprParseException(ErrorReporter reporter, String expectation, SourceLocation location,
        ParseException e) {//w  w  w .  j av  a 2s.  co m
    // currentToken is the 'last successfully consumed token', but the error is usually due to the
    // first unsuccessful token.  use that for the source location
    Token errorToken = e.currentToken;
    if (errorToken.next != null) {
        errorToken = errorToken.next;
    }

    // handle a few special cases that come up in v1->v2 migrations.  We have no production rules
    // that reference these tokens so they will always be unexpected.  Another option we could take
    // is add production rules/matchers for these in the expected places (e.q. allow '&&' in the
    // same place we match 'and'), then we could report errors and keep going in the parser.
    switch (errorToken.kind) {
    case ExpressionParserConstants.LEGACY_AND:
        reporter.report(location, LEGACY_AND_ERROR);
        return;
    case ExpressionParserConstants.LEGACY_OR:
        reporter.report(location, LEGACY_OR_ERROR);
        return;
    case ExpressionParserConstants.LEGACY_NOT:
        reporter.report(location, LEGACY_NOT_ERROR);
        return;
    case ExpressionParserConstants.DOUBLE_QUOTE:
        reporter.report(location, LEGACY_DOUBLE_QUOTED_STRING);
        return;
    }
    // otherwise log a generic unexpected token error message
    ImmutableSet.Builder<String> expectedTokenImages = ImmutableSet.builder();
    for (int[] expected : e.expectedTokenSequences) {
        // We only display the first token
        expectedTokenImages.add(getSoyFileParserTokenDisplayName(expected[0]));
    }
    reporter.report(
            // TODO(lukes): we should offset the location by the location of the errorToken however
            // expr source locations are already iffy, so doing random math on them is unlikely to help
            // anything.  Revisit when we stop extracting expressions from SoyNode command texts with
            // regular expressions.
            location, SoyErrorKind.of(expectation + "{0}"),
            formatParseExceptionDetails(errorToken.image, expectedTokenImages.build().asList()));
}

From source file:org.sosy_lab.cpachecker.core.algorithm.bmc.BMCHelper.java

public static Iterable<BooleanFormula> assertAtWithIncrementingDefaultIndex(Iterable<AbstractState> pStates,
        final BooleanFormula pUninstantiatedFormula, final FormulaManagerView pFMGR, int firstDefault) {
    ImmutableSet.Builder<BooleanFormula> formulas = ImmutableSet.builder();
    int defaultIndex = firstDefault;
    for (AbstractState state : pStates) {
        formulas.add(assertAt(state, pUninstantiatedFormula, pFMGR, defaultIndex));
        ++defaultIndex;//from  w  w w .ja  va  2s.  co  m
    }
    return formulas.build();
}

From source file:com.google.devtools.build.buildjar.javac.plugins.dependency.ImplicitDependencyExtractor.java

/** Collect the set of jars on the compilation bootclasspath. */
public static Set<String> getPlatformJars(JavaFileManager fileManager) {

    if (fileManager instanceof JavacFileManager) {
        JavacFileManager jfm = (JavacFileManager) fileManager;
        ImmutableSet.Builder<String> result = ImmutableSet.builder();
        for (Path path : jfm.getLocationAsPaths(StandardLocation.PLATFORM_CLASS_PATH)) {
            result.add(path.toString());
        }/* www .j ava 2  s  . c  o  m*/
        return result.build();
    }

    // TODO(cushon): Assuming JavacFileManager is brittle, but in practice it is the only
    // implementation that matters.
    throw new IllegalStateException("Unsupported file manager type: " + fileManager.getClass().getName());
}