List of usage examples for com.google.common.collect ImmutableSet builder
public static <E> Builder<E> builder()
From source file:com.lambdautils.util.stream.MoreCollectors.java
static <T> Collector<T, ImmutableSet.Builder<T>, ImmutableSet<T>> toImmutableSet() { return Collector.of(ImmutableSet.Builder::new, ImmutableSet.Builder::add, (l, r) -> l.addAll(r.build()), ImmutableSet.Builder<T>::build); }
From source file:co.cask.cdap.common.lang.FilterClassLoader.java
public static FilterClassLoader create(ProgramType programType, ClassLoader parentClassLoader) { Set<String> visibleResources = ProgramResources.getVisibleResources(programType); ImmutableSet.Builder<String> visiblePackages = ImmutableSet.builder(); for (String resource : visibleResources) { if (resource.endsWith(".class")) { int idx = resource.lastIndexOf('/'); // Ignore empty package if (idx > 0) { visiblePackages.add(resource.substring(0, idx)); }//from www.ja v a 2 s. co m } } return new FilterClassLoader(Predicates.in(visibleResources), Predicates.in(visiblePackages.build()), parentClassLoader); }
From source file:org.apache.james.util.streams.ImmutableCollectors.java
public static <T> Collector<T, ImmutableSet.Builder<T>, ImmutableSet<T>> toImmutableSet() { return Collector.of(ImmutableSet::builder, ImmutableSet.Builder::add, (left, right) -> { left.addAll(right.build());//from ww w . j a va2 s. co m return left; }, ImmutableSet.Builder::build); }
From source file:org.prebake.fs.FilePerms.java
/** * @param permBits POSIX style permission bits where bits 6-8 are RWX * respectively for the owner, bits 3-5 are RWX respectively for all users * in the group, and bits 0-2 are RWX respectively for all other users. * @return the file permissions corresponding to permBits. *///from www. j a va 2s .c o m public static @Nonnull Set<PosixFilePermission> permSet(int permBits, boolean isDirectory) { if (isDirectory) { // Set the executable bit for any of the UGO blocks that have the read // or write bits set. int fromRead = (permBits >>> 2) & 0111; int fromWrite = (permBits >>> 1) & 0111; permBits |= fromRead | fromWrite; } permBits &= 0777; ImmutableSet.Builder<PosixFilePermission> posixs = ImmutableSet.builder(); for (int k = 0; permBits != 0; ++k, permBits >>>= 1) { if ((permBits & 1) != 0) { posixs.add(POSIX_PERMS[k]); } } return posixs.build(); }
From source file:com.stackframe.sarariman.DirectorySynchronizerImpl.java
private Set<Integer> getEmployeeIDs(DataSource dataSource) throws SQLException { Connection connection = dataSource.getConnection(); try {//from ww w .j a va2 s . c om PreparedStatement ps = connection.prepareStatement("SELECT id FROM employee"); try { ResultSet rs = ps.executeQuery(); ImmutableSet.Builder<Integer> setBuilder = ImmutableSet.builder(); while (rs.next()) { setBuilder.add(rs.getInt("id")); } return setBuilder.build(); } finally { ps.close(); } } finally { connection.close(); } }
From source file:com.facebook.presto.sql.planner.SubExpressionExtractor.java
public static Set<Expression> extract(Expression expression) { final ImmutableSet.Builder<Expression> builder = ImmutableSet.builder(); extract(builder, expression);//from w w w . j a v a 2 s.c o m return builder.build(); }
From source file:org.b1.pack.standard.writer.CompressedFormatDetector.java
private static ImmutableSet<String> loadExtensions() { try {//from www. j av a2s. co m ImmutableSet.Builder<String> builder = ImmutableSet.builder(); Enumeration<URL> resources = getResources("org/b1/pack/standard/writer/compressedFormats.txt"); while (resources.hasMoreElements()) { readResource(resources.nextElement(), builder); } return builder.build(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.cyclop.common.Gullectors.java
public static <T> Collector<T, ?, ImmutableSet<T>> toImmutableSet() { Supplier<ImmutableSet.Builder<T>> supplier = ImmutableSet.Builder::new; BiConsumer<ImmutableSet.Builder<T>, T> accumulator = (b, v) -> b.add(v); BinaryOperator<ImmutableSet.Builder<T>> combiner = (l, r) -> l.addAll(r.build()); Function<ImmutableSet.Builder<T>, ImmutableSet<T>> finisher = ImmutableSet.Builder::build; return Collector.of(supplier, accumulator, combiner, finisher); }
From source file:com.spotify.heroic.common.Groups.java
public static Groups combine(final Groups first, final Groups... other) { final ImmutableSet.Builder<String> all = ImmutableSet.<String>builder().addAll(first.groups); Arrays.stream(other).forEach(all::addAll); return new Groups(all.build()); }
From source file:com.facebook.buck.cxx.AbstractCxxIncludePaths.java
/** * Merge all the given {@link CxxIncludePaths}. * * Combinines their path lists, deduping them (keeping the earlier of the repeated instance). *///from ww w . j a v a 2 s .co m public static CxxIncludePaths concat(Iterator<CxxIncludePaths> itemIter) { ImmutableSet.Builder<CxxHeaders> ipathBuilder = ImmutableSet.<CxxHeaders>builder(); ImmutableSet.Builder<FrameworkPath> fpathBuilder = ImmutableSet.<FrameworkPath>builder(); while (itemIter.hasNext()) { CxxIncludePaths item = itemIter.next(); ipathBuilder.addAll(item.getIPaths()); fpathBuilder.addAll(item.getFPaths()); } return CxxIncludePaths.of(ipathBuilder.build(), fpathBuilder.build()); }