List of usage examples for com.google.common.collect ImmutableSet builder
public static <E> Builder<E> builder()
From source file:com.facebook.buck.dalvik.firstorder.FirstOrderHelper.java
private FirstOrderHelper(Iterable<Type> scenarioTypes, ImmutableSet.Builder<String> resultBuilder) { this.scenarioTypes = Preconditions.checkNotNull(scenarioTypes); this.resultBuilder = Preconditions.checkNotNull(resultBuilder); this.knownTypes = Maps.newHashMap(); }
From source file:com.github.richardballard.arbeeutils.stream.MoreCollectors.java
/** * Based on code from <a href="https://dzone.com/articles/java-8-collectors-guava">here</a> *///from w w w .j a v a 2 s. c o m public static @NotNull <T> Collector<T, ?, ImmutableSet<T>> toImmutableSet() { final Supplier<ImmutableSet.Builder<T>> supplier = ImmutableSet.Builder::new; final BiConsumer<ImmutableSet.Builder<T>, T> accumulator = ImmutableSet.Builder::add; final BinaryOperator<ImmutableSet.Builder<T>> combiner = (l, r) -> l.addAll(r.build()); final Function<ImmutableSet.Builder<T>, ImmutableSet<T>> finisher = ImmutableSet.Builder::build; return Collector.of(supplier, accumulator, combiner, finisher); }
From source file:org.fenixedu.academic.domain.accounting.EventTypes.java
public EventTypes(JsonElement json) { ImmutableSet.Builder<EventType> builder = ImmutableSet.builder(); for (JsonElement el : json.getAsJsonArray()) { builder.add(EventType.valueOf(el.getAsString())); }/* w ww .j a v a 2s.c o m*/ this.types = builder.build(); }
From source file:es.udc.pfc.gamelib.chess.pieces.ChessRook.java
@Override public final ImmutableSet<Position> getStandardMoves(final ChessBoard board) { final ImmutableSet.Builder<Position> moves = ImmutableSet.builder(); moves.addAll(getMovesTo(board, Direction.N)); moves.addAll(getMovesTo(board, Direction.S)); moves.addAll(getMovesTo(board, Direction.E)); moves.addAll(getMovesTo(board, Direction.W)); return moves.build(); }
From source file:com.spotify.heroic.metadata.FindSeriesIds.java
public static Collector<FindSeriesIds, FindSeriesIds> reduce(final OptionalLimit limit) { return results -> { final List<RequestError> errors = new ArrayList<>(); final ImmutableSet.Builder<String> ids = ImmutableSet.builder(); boolean limited = false; for (final FindSeriesIds result : results) { errors.addAll(result.errors); ids.addAll(result.ids);/*w w w. ja v a 2s .c om*/ limited |= result.limited; } final Set<String> s = ids.build(); return new FindSeriesIds(errors, limit.limitSet(s), limited || limit.isGreater(s.size())); }; }
From source file:com.plvision.switchover.fwd.PathFinder.java
/** * Searching of primary and backup paths between two devices. * //from w w w.ja v a2s .co m * @param service - topology service * @param src - source device Id * @param dst - destination device Id * * @return set of paths */ public static Set<Path> result(TopologyService service, DeviceId src, DeviceId dst) { ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); Set<Path> paths1 = service.getPaths(service.currentTopology(), src, dst); Set<DisjointPath> paths2 = service.getDisjointPaths(service.currentTopology(), src, dst); paths1.forEach(path -> { builder.add(path); }); paths2.forEach(path -> { builder.add(path.backup()); }); return builder.build(); }
From source file:com.spotify.apollo.module.AbstractApolloModule.java
protected AbstractApolloModule() { lifecycleManagedBuilder = ImmutableSet.builder(); }
From source file:com.facebook.buck.cli.PathArguments.java
/** * Filter files under the project root, and convert to canonical relative path style. * For example, the project root is /project, * 1. file path /project/./src/com/facebook/./test/../Test.java will be converted to * src/com/facebook/Test.java//from w w w . j a v a 2 s . com * 2. file path /otherproject/src/com/facebook/Test.java will be ignored. */ static ReferencedFiles getCanonicalFilesUnderProjectRoot(Path projectRoot, Iterable<String> nonCanonicalFilePaths) throws IOException { // toRealPath() is used throughout to resolve symlinks or else the Path.startsWith() check will // not be reliable. ImmutableSet.Builder<Path> projectFiles = ImmutableSet.builder(); ImmutableSet.Builder<Path> nonProjectFiles = ImmutableSet.builder(); Path normalizedRoot = projectRoot.toRealPath(); for (String filePath : nonCanonicalFilePaths) { Path canonicalFullPath = Paths.get(filePath); if (!canonicalFullPath.isAbsolute()) { canonicalFullPath = projectRoot.resolve(canonicalFullPath); } if (!canonicalFullPath.toFile().exists()) { nonProjectFiles.add(canonicalFullPath); continue; } canonicalFullPath = canonicalFullPath.toRealPath(); // Ignore files that aren't under project root. if (canonicalFullPath.startsWith(normalizedRoot)) { Path relativePath = canonicalFullPath.subpath(normalizedRoot.getNameCount(), canonicalFullPath.getNameCount()); projectFiles.add(relativePath); } else { nonProjectFiles.add(canonicalFullPath); } } return new ReferencedFiles(projectFiles.build(), nonProjectFiles.build()); }
From source file:es.udc.pfc.gamelib.chess.pieces.ChessQueen.java
@Override public final ImmutableSet<Position> getStandardMoves(final ChessBoard board) { final ImmutableSet.Builder<Position> moves = ImmutableSet.builder(); moves.addAll(getMovesTo(board, Direction.N)); moves.addAll(getMovesTo(board, Direction.S)); moves.addAll(getMovesTo(board, Direction.E)); moves.addAll(getMovesTo(board, Direction.W)); moves.addAll(getMovesTo(board, Direction.NE)); moves.addAll(getMovesTo(board, Direction.NW)); moves.addAll(getMovesTo(board, Direction.SE)); moves.addAll(getMovesTo(board, Direction.SW)); return moves.build(); }
From source file:org.fenixedu.academic.domain.degreeStructure.CycleTypes.java
public CycleTypes(JsonElement json) { ImmutableSet.Builder<CycleType> builder = ImmutableSet.builder(); for (JsonElement el : json.getAsJsonArray()) { builder.add(CycleType.valueOf(el.getAsString())); }/*from w w w . j a va 2 s .c o m*/ this.types = builder.build(); }