List of usage examples for com.google.common.collect ImmutableSortedSet builder
@Deprecated public static <E> ImmutableSortedSet.Builder<E> builder()
From source file:org.kmworks.util.cp.CodepointSetUtil.java
/** * Internalize an AbstractCodepointSet from an external textual representation. * The external textual representation should comply th the following garmmar: * <pre>//from w w w . j a va2 s. co m * start = ws line+ EOF * line = codepoint ( '-' codepoint)? ws * codepoint = decNumber | hexNumber * decNumber = decDigit+ * decDigit = [0-9] * hexNumber = '0x' hexDigit+ * hexDigit = [a-fA-F0-9] * ws = ( wschar+ | comment )* * comment = '#' (!nl _)* nl * wschar = [ \t\r\n] * nl = '\r'? '\n' * </pre> * @param r a Reader for reading text input * @param radix * @return * @throws IOException */ public static CodepointSet fromText(Reader r, int radix) throws IOException { final ImmutableSortedSet.Builder<Integer> builder = new ImmutableSortedSet.Builder<>( CodepointSet.INTEGER_COMPARATOR); final BufferedReader br = new BufferedReader(r); String line; while ((line = br.readLine()) != null) { line = line.trim(); if (line.length() > 0 && !line.startsWith("#")) { // skip empty & comment lines if (line.contains("-")) { // line contains a codepoint range final String[] range = line.split("\\s*-\\s*"); final int lo = Integer.parseInt(range[0], radix); final int hi = Integer.parseInt(stripTrailingComment(range[1]), radix); for (int i = lo; i <= hi; i++) { builder.add(i); } } else { // line contains a single codepoint builder.add(Integer.parseInt(stripTrailingComment(line), radix)); } } } return CodepointBitSet.of(builder.build()); }
From source file:simpleserver.Group.java
public static ImmutableSet<Integer> parseGroups(String idString, String delimiter) { String[] segments = idString.split(delimiter); ImmutableSortedSet.Builder<Integer> groups = ImmutableSortedSet.naturalOrder(); for (String segment : segments) { if (segment.matches("^\\s*$")) { continue; }/* w ww. jav a 2 s.com*/ try { groups.add(Integer.valueOf(segment)); continue; } catch (NumberFormatException e) { } String[] range = segment.split("-"); if (range.length != 2) { System.out.println("Unable to parse group: " + segment); continue; } int low; int high; try { low = Integer.valueOf(range[0]); high = Integer.valueOf(range[1]); } catch (NumberFormatException e) { System.out.println("Unable to parse group: " + segment); continue; } if (low > high) { System.out.println("Unable to parse group: " + segment); continue; } for (int k = low; k <= high; ++k) { groups.add(k); } } return groups.build(); }
From source file:com.facebook.buck.io.DirectoryTraversers.java
/** * Aggregates a set of all paths to files in the specified directories. All file paths will be * relative to the project root.//from ww w . ja v a 2 s . c o m * @param pathToDirectory path to directory to traverse. The directory may not contain symlinks to * other directories. * @return a set of all files in paths, sorted alphabetically */ public ImmutableSortedSet<Path> findFiles(final String pathToDirectory, DirectoryTraverser traverser) throws IOException { final ImmutableSortedSet.Builder<Path> allFiles = ImmutableSortedSet.naturalOrder(); traverser.traverse(new DirectoryTraversal(Paths.get(pathToDirectory)) { @Override public void visit(Path file, String relativePath) { allFiles.add(Paths.get(pathToDirectory, relativePath)); } }); return allFiles.build(); }
From source file:org.voltcore.utils.COWNavigableSet.java
public COWNavigableSet(Collection<E> c) { Preconditions.checkNotNull(c);/*www . j a v a2 s .c o m*/ ImmutableSortedSet.Builder<E> builder = ImmutableSortedSet.naturalOrder(); for (E e : c) { builder.add(e); } m_set = new AtomicReference<ImmutableSortedSet<E>>(builder.build()); }
From source file:com.facebook.buck.apple.TargetSources.java
/** * Creates a {@link TargetSources} given a list of {@link AppleSource}s. *///from www . ja v a 2 s . c o m public static TargetSources ofAppleSources(SourcePathResolver resolver, Collection<AppleSource> appleSources) { ImmutableList.Builder<GroupedSource> srcsBuilder = ImmutableList.builder(); ImmutableSortedMap.Builder<SourcePath, String> perFileFlagsBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedSet.Builder<SourcePath> srcPathsBuilder = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet.Builder<SourcePath> headerPathsBuilder = ImmutableSortedSet.naturalOrder(); RuleUtils.extractSourcePaths(resolver, srcsBuilder, perFileFlagsBuilder, srcPathsBuilder, headerPathsBuilder, appleSources); return new TargetSources(srcsBuilder.build(), perFileFlagsBuilder.build(), srcPathsBuilder.build(), headerPathsBuilder.build()); }
From source file:com.facebook.buck.util.DirectoryTraversers.java
/** * Aggregates a set of all paths to files in the specified directories. All file paths will be * relative to the project root./* w w w .j a v a 2s . co m*/ * @param pathToDirectory path to directory to traverse. The directory may not contain symlinks to * other directories. * @param traverser * @return a set of all files in paths, sorted alphabetically */ public ImmutableSortedSet<Path> findFiles(final String pathToDirectory, DirectoryTraverser traverser) throws IOException { final ImmutableSortedSet.Builder<Path> allFiles = ImmutableSortedSet.naturalOrder(); traverser.traverse(new DirectoryTraversal(new File(pathToDirectory)) { @Override public void visit(File file, String relativePath) { allFiles.add(Paths.get(pathToDirectory, relativePath)); } }); return allFiles.build(); }
From source file:org.gradle.model.internal.type.ModelTypes.java
/** * Returns the sorted, unique display names of the given types. *///from w w w .ja v a2 s. c om public static Iterable<String> getDisplayNames(Iterable<? extends ModelType<?>> types) { ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder(); for (ModelType<?> type : types) { builder.add(type.getDisplayName()); } return builder.build(); }
From source file:com.facebook.buck.rules.coercer.SortedSetTypeCoercer.java
@Override public ImmutableSortedSet<T> coerce(BuildRuleResolver buildRuleResolver, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, Object object) throws CoerceFailedException { ImmutableSortedSet.Builder<T> builder = ImmutableSortedSet.naturalOrder(); fill(buildRuleResolver, filesystem, pathRelativeToProjectRoot, builder, object); return builder.build(); }
From source file:com.facebook.buck.jvm.java.ZipArchiveDependencySupplier.java
@Override public ImmutableSortedSet<SourcePath> getArchiveMembers(SourcePathResolver resolver) { ImmutableSortedSet.Builder<SourcePath> builder = ImmutableSortedSet.naturalOrder(); for (SourcePath zipSourcePath : zipFiles) { final Path zipRelativePath = resolver.getRelativePath(zipSourcePath); try {/*from w w w. j ava 2 s .c o m*/ for (Path member : filesystem.getZipMembers(zipRelativePath)) { builder.add(new ArchiveMemberSourcePath(zipSourcePath, member)); } } catch (IOException e) { throw new HumanReadableException(e, "Failed to read archive: " + zipRelativePath); } } return builder.build(); }
From source file:org.mattcarrier.erector.dao.mapper.TagDomainMapper.java
@Override public TagDomain map(int index, ResultSet rs, StatementContext ctxt) throws SQLException { final ResultSetMetaData md = rs.getMetaData(); final ImmutableSortedSet.Builder<String> domain = ImmutableSortedSet.naturalOrder(); for (int i = 1; i <= md.getColumnCount(); i++) { final String column = md.getColumnName(i); if ("id".equalsIgnoreCase(column) || ("doNotDelete".equalsIgnoreCase(column))) { continue; }/* www . ja va 2s. c om*/ domain.add(column); } return new TagDomain(domain.build().asList()); }