List of usage examples for com.google.common.collect ImmutableSortedSet builder
@Deprecated public static <E> ImmutableSortedSet.Builder<E> builder()
From source file:com.facebook.buck.jvm.java.AbstractJavacOptions.java
public ImmutableSortedSet<SourcePath> getInputs(SourcePathRuleFinder ruleFinder) { ImmutableSortedSet.Builder<SourcePath> builder = ImmutableSortedSet.<SourcePath>naturalOrder() .addAll(getAnnotationProcessingParams().getInputs()); Optional<SourcePath> javacJarPath = getJavacJarPath(); if (javacJarPath.isPresent()) { SourcePath sourcePath = javacJarPath.get(); // Add the original rule regardless of what happens next. builder.add(sourcePath);//from w w w.jav a 2 s .c o m Optional<BuildRule> possibleRule = ruleFinder.getRule(sourcePath); if (possibleRule.isPresent()) { BuildRule rule = possibleRule.get(); // And now include any transitive deps that contribute to the classpath. if (rule instanceof JavaLibrary) { builder.addAll(((JavaLibrary) rule).getDepsForTransitiveClasspathEntries().stream() .map(SourcePaths.getToBuildTargetSourcePath()::apply) .collect(MoreCollectors.toImmutableList())); } else { builder.add(sourcePath); } } } return builder.build(); }
From source file:com.b2international.snowowl.datastore.CodeSystemEntry.java
/** * Returns all code system short name dependencies and itself. */// w ww .ja va 2 s .c o m @JsonIgnore public SortedSet<String> getDependenciesAndSelf() { ImmutableSortedSet.Builder<String> affectedCodeSystems = ImmutableSortedSet.naturalOrder(); affectedCodeSystems.addAll( CoreTerminologyBroker.getInstance().getAffectedCodeSystemsForTeminology(terminologyComponentId)); affectedCodeSystems.add(shortName); return affectedCodeSystems.build(); }
From source file:com.facebook.buck.java.JavaSymbolFinder.java
/** * Find all Java source files that define a given fully-qualified symbol (like "com.example.a.A"). * To do this, open up all the Java files that could define it (see {@link #getCandidatePaths}) * and parse them with our Eclipse-based {@link JavaFileParser}. *///from ww w . j a v a 2 s . c om private ImmutableSortedSet<Path> getDefiningPaths(String symbol, Collection<Path> srcRoots) { ImmutableSortedSet.Builder<Path> definingPaths = ImmutableSortedSet.naturalOrder(); // TODO(simons): This should use the same javac env as was used for compiling the code. JavaFileParser parser = JavaFileParser.createJavaFileParser(javacOptions); for (Path candidatePath : getCandidatePaths(symbol, srcRoots)) { String content = projectFilesystem .readFileIfItExists(projectFilesystem.getPathForRelativeExistingPath(candidatePath)).get(); Set<String> symbols = parser.getExportedSymbolsFromString(content); if (symbols.contains(symbol)) { definingPaths.add(candidatePath); } } return definingPaths.build(); }
From source file:edu.mit.streamjit.impl.compiler2.Actor.java
/** * Returns the logical indices pushed to the given output during the given * iterations./* w w w . j ava 2 s . c o m*/ * @param output the output index * @param iterations the iteration numbers * @return the logical indices pushed to the given input during the given * iterations */ public ImmutableSortedSet<Integer> pushes(int output, Set<Integer> iterations) { if (iterations.isEmpty()) return ImmutableSortedSet.of(); if (iterations instanceof ContiguousSet) return pushes(output, (ContiguousSet<Integer>) iterations); ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder(); for (int i : iterations) builder.addAll(pushes(output, i)); return builder.build(); }
From source file:org.pircbotx.Channel.java
/** * Get all the user's nicks in this channel * * @return An <i>Unmodifiable</i> Set of user's nicks as String in this * channel/*from ww w . j a va 2s.com*/ */ public ImmutableSortedSet<String> getUsersNicks() { ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder(); for (User curUser : getDao().getUsers(this)) builder.add(curUser.getNick()); return builder.build(); }
From source file:com.google.devtools.build.lib.rules.config.ConfigFeatureFlagOptions.java
/** * Trims the set of known flag-value pairs to the given set. * * <p>Each target which participates in manual trimming will call this method (via * ConfigFeatureFlagTaggedTrimmingTransitionFactory) with its set of requested flags. This set * typically comes straight from the user via the transitive_configs attribute. For feature * flags themselves, this will be a singleton set containing the feature flag's own label. * * <p>At the top level, or when there is also a transition which calls replaceFlagValues (e.g., * ConfigFeatureFlagValuesTransition, created by ConfigFeatureFlagTransitionFactory and used by * android_binary among others), the configuration will start off untrimmed (knownDefaultFlags is * null). In this case:/*from w ww. jav a2s. com*/ * * <ul> * <li>Any map entries from flagValues whose keys are in requiredFlags will be retained in * flagValues; all other entries of flagValues will be discarded.</li> * <li>All other elements of requiredFlags will be put into knownDefaultFlags.</li> * <li>unknownFlags will always be set to the empty set; its old value will be discarded.</li> * </ul> * * <p>At any place other than the top level and the aforementioned replaceFlagValues transitions, * the source configuration is already trimmed (knownDefaultFlags is not null). In this case: * * <ul> * <li>Any map entries from flagValues which have keys that are in requiredFlags will be * retained in flagValues; all other entries of flagValues will be discarded.</li> * <li>Any elements of knownDefaultFlags which are also in requiredFlags will be retained in * knownDefaultFlags; all other elements of knownDefaultFlags will be discarded.</li> * <li>unknownFlags will be set to contain all other elements of requiredFlags; its old value * will be discarded.</li> * </ul> * * <p>If requiredFlags is empty, then flagValues, knownDefaultFlags, and unknownFlags will all be * set to empty values. * * <p>After this method is called, regardless of circumstances: * * <ul> * <li>knownDefaultValues will be non-null, and thus isTrimmed will return true, indicating that * the configuration is trimmed.</li> * <li>If unknownFlags is set non-empty, this indicates that the target this configuration is * for has been reached via a path which mistakenly trimmed out one or more of the flags it * needs, and thus there isn't enough information to evaluate it.</li> * </ul> */ public void trimFlagValues(Set<Label> requiredFlags) { ImmutableSortedMap.Builder<Label, String> flagValuesBuilder = ImmutableSortedMap.naturalOrder(); ImmutableSortedSet.Builder<Label> knownDefaultFlagsBuilder = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet.Builder<Label> unknownFlagsBuilder = ImmutableSortedSet.naturalOrder(); for (Label label : requiredFlags) { if (this.flagValues.containsKey(label)) { flagValuesBuilder.put(label, flagValues.get(label)); } else if (!this.isTrimmed() || this.knownDefaultFlags.contains(label)) { knownDefaultFlagsBuilder.add(label); } else { unknownFlagsBuilder.add(label); } } this.flagValues = flagValuesBuilder.build(); this.knownDefaultFlags = knownDefaultFlagsBuilder.build(); this.unknownFlags = unknownFlagsBuilder.build(); }
From source file:org.cyclop.service.cassandra.intern.QueryServiceImpl.java
@Override public ImmutableSortedSet<CqlColumnName> findColumnNames(Optional<CqlTable> table) { StringBuilder buf = new StringBuilder("select column_name from system.schema_columns"); if (table.isPresent()) { buf.append(" where columnfamily_name='"); buf.append(table.get().partLc);/*from ww w . j a va 2 s . c o m*/ buf.append("'"); } buf.append(" limit "); buf.append(config.cassandra.columnsLimit); buf.append(" allow filtering"); Optional<ResultSet> result = executeSilent(buf.toString()); if (!result.isPresent()) { LOG.warn("Cannot readIdentifier column names"); return ImmutableSortedSet.of(); } ImmutableSortedSet.Builder<CqlColumnName> cqlColumnNames = ImmutableSortedSet.naturalOrder(); for (Row row : result.get()) { String name = StringUtils.trimToNull(row.getString("column_name")); if (name == null) { continue; } cqlColumnNames.add(new CqlColumnName(CqlDataType.create(DataType.text()), name)); } loadPartitionKeyNames(table, cqlColumnNames); return cqlColumnNames.build(); }
From source file:com.facebook.buck.jvm.java.JavaSymbolFinder.java
/** * Find all Java source files that define a given fully-qualified symbol (like "com.example.a.A"). * To do this, open up all the Java files that could define it (see {@link #getCandidatePaths}) * and parse them with our Eclipse-based {@link JavaFileParser}. *///from www .ja va2s . c o m private ImmutableSortedSet<Path> getDefiningPaths(String symbol, Collection<Path> srcRoots) { ImmutableSortedSet.Builder<Path> definingPaths = ImmutableSortedSet.naturalOrder(); // TODO(shs96c): This should use the same javac env as was used for compiling the code. JavaFileParser parser = JavaFileParser.createJavaFileParser(javacOptions); for (Path candidatePath : getCandidatePaths(symbol, srcRoots)) { Optional<String> content = projectFilesystem .readFileIfItExists(projectFilesystem.getPathForRelativeExistingPath(candidatePath)); if (content.isPresent() && parser.getExportedSymbolsFromString(content.get()).contains(symbol)) { definingPaths.add(candidatePath); } } return definingPaths.build(); }
From source file:com.publictransitanalytics.scoregenerator.workflow.Calculation.java
private static NavigableSet<LocalDateTime> getTaskTimes(final LocalDateTime startTime, final LocalDateTime endTime, final Duration samplingInterval) { final ImmutableSortedSet.Builder<LocalDateTime> builder = ImmutableSortedSet.naturalOrder(); if (endTime == null) { builder.add(startTime);//www . ja va2s . c o m } else { LocalDateTime time = startTime; while (time.isBefore(endTime)) { builder.add(time); time = time.plus(samplingInterval); } } return builder.build(); }
From source file:com.google.googlejavaformat.java.ImportOrderer.java
/** * Scans a sequence of import lines. The parsing uses this approximate grammar: * * <pre>{@code// w w w .ja va 2s . c o m * <imports> -> (<end-of-line> | <import>)* * <import> -> "import" <whitespace> ("static" <whitespace>)? * <identifier> ("." <identifier>)* ("." "*")? <whitespace>? ";" * <whitespace>? <end-of-line>? (<line-comment> <end-of-line>)* * }</pre> * * @param i the index to start parsing at. * @return the result of parsing the imports. * @throws FormatterException if imports could not parsed according to the grammar. */ private ImportsAndIndex scanImports(int i) throws FormatterException { int afterLastImport = i; ImmutableSortedSet.Builder<Import> imports = ImmutableSortedSet.orderedBy(importComparator); // JavaInput.buildToks appends a zero-width EOF token after all tokens. It won't match any // of our tests here and protects us from running off the end of the toks list. Since it is // zero-width it doesn't matter if we include it in our string concatenation at the end. while (i < toks.size() && tokenAt(i).equals("import")) { i++; if (isSpaceToken(i)) { i++; } boolean isStatic = tokenAt(i).equals("static"); if (isStatic) { i++; if (isSpaceToken(i)) { i++; } } if (!isIdentifierToken(i)) { throw new FormatterException("Unexpected token after import: " + tokenAt(i)); } StringAndIndex imported = scanImported(i); String importedName = imported.string; i = imported.index; if (isSpaceToken(i)) { i++; } if (!tokenAt(i).equals(";")) { throw new FormatterException("Expected ; after import"); } while (tokenAt(i).equals(";")) { // Extra semicolons are not allowed by the JLS but are accepted by javac. i++; } StringBuilder trailing = new StringBuilder(); if (isSpaceToken(i)) { trailing.append(tokenAt(i)); i++; } if (isNewlineToken(i)) { trailing.append(tokenAt(i)); i++; } // Gather (if any) all single line comments and accompanied line terminators following this // import while (isSlashSlashCommentToken(i)) { trailing.append(tokenAt(i)); i++; if (isNewlineToken(i)) { trailing.append(tokenAt(i)); i++; } } imports.add(new Import(importedName, trailing.toString(), isStatic)); // Remember the position just after the import we just saw, before skipping blank lines. // If the next thing after the blank lines is not another import then we don't want to // include those blank lines in the text to be replaced. afterLastImport = i; while (isNewlineToken(i) || isSpaceToken(i)) { i++; } } return new ImportsAndIndex(imports.build(), afterLastImport); }