private void assertResultAndMessages(BuildResult result, TaskOutcome outcome, String... messages) { String expectedToStartWith = StringPrinter.buildStringFromLines(messages).trim(); int numNewlines = CharMatcher.is('\n').countIn(expectedToStartWith); List<String> actualLines = Splitter.on('\n').splitToList(LineEnding.toUnix(result.getOutput())); String actualStart = String.join("\n", actualLines.subList(0, numNewlines + 1)); Assertions.assertThat(actualStart).isEqualTo(expectedToStartWith); Assertions.assertThat(result.tasks(outcome).size() + result.tasks(TaskOutcome.UP_TO_DATE).size()) .isEqualTo(result.getTasks().size()); } }
/** * Returns a splitter that behaves equivalently to {@code this} splitter, but * automatically removes leading and trailing {@linkplain * CharMatcher#WHITESPACE whitespace} from each returned substring; equivalent * to {@code trimResults(CharMatcher.WHITESPACE)}. For example, {@code * Splitter.on(',').trimResults().split(" a, b ,c ")} returns an iterable * containing {@code ["a", "b", "c"]}. * * @return a splitter with the desired configuration */ @CheckReturnValue public Splitter trimResults() { return trimResults(CharMatcher.WHITESPACE); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, * and splits entries into keys and values using the specified separator. * * @since 14.0 */ @CheckReturnValue @Beta public MapSplitter withKeyValueSeparator(char separator) { return withKeyValueSeparator(on(separator)); }
Iterable<String> components = Splitter.on('/').omitEmptyStrings().split(pathname); List<String> path = new ArrayList<String>();
public Map<String, String> split(CharSequence sequence) { Map<String, String> map = new LinkedHashMap<String, String>(); for (String entry : outerSplitter.split(sequence)) { Iterator<String> entryFields = entrySplitter.splittingIterator(entry);
private void addFile(String arg) { // at the very least, we'll print this about a file: // 0.txt // @@ -1,2 +1,2 @@, // -1\\r\\n, // -2\\r\\n, // ... (more lines that didn't fit) List<String> lines = NEWLINE_SPLITTER.splitToList(arg); if (!lines.isEmpty()) { addIntendedLine(NORMAL_INDENT, lines.get(0)); } for (int i = 1; i < Math.min(MIN_LINES_PER_FILE, lines.size()); ++i) { addIntendedLine(DIFF_INDENT, lines.get(i)); } // then we'll print the rest that can fit ListIterator<String> iter = lines.listIterator(Math.min(MIN_LINES_PER_FILE, lines.size())); while (iter.hasNext() && numLines < MAX_CHECK_MESSAGE_LINES) { addIntendedLine(DIFF_INDENT, iter.next()); } if (numLines >= MAX_CHECK_MESSAGE_LINES) { // we're out of space if (iter.hasNext()) { int linesLeft = lines.size() - iter.nextIndex(); addIntendedLine(NORMAL_INDENT, "... (" + linesLeft + " more lines that didn't fit)"); } } }
/** * Returns a splitter that uses the given single-character separator. For * example, {@code Splitter.on(',').split("foo,,bar")} returns an iterable * containing {@code ["foo", "", "bar"]}. * * @param separator the character to recognize as a separator * @return a splitter, with default settings, that recognizes that separator */ @CheckReturnValue public static Splitter on(char separator) { return on(CharMatcher.is(separator)); }
/** * Returns a splitter that behaves equivalently to {@code this} splitter, but * automatically omits empty strings from the results. For example, {@code * Splitter.on(',').omitEmptyStrings().split(",a,,,b,c,,")} returns an * iterable containing only {@code ["a", "b", "c"]}. * * <p>If either {@code trimResults} option is also specified when creating a * splitter, that splitter always trims results first before checking for * emptiness. So, for example, {@code * Splitter.on(':').omitEmptyStrings().trimResults().split(": : : ")} returns * an empty iterable. * * <p>Note that it is ordinarily not possible for {@link #split(CharSequence)} * to return an empty iterable, but when using this option, it can (if the * input sequence consists of nothing but separators). * * @return a splitter with the desired configuration */ @CheckReturnValue public Splitter omitEmptyStrings() { return new Splitter(strategy, true, trimmer, limit); }
/** * Splits {@code sequence} into string components and returns them as * an immutable list. If you want an {@link Iterable} which may be lazily * evaluated, use {@link #split(CharSequence)}. * * @param sequence the sequence of characters to split * @return an immutable list of the segments split from the parameter * @since 15.0 */ @CheckReturnValue @Beta public List<String> splitToList(CharSequence sequence) { checkNotNull(sequence); Iterator<String> iterator = splittingIterator(sequence); List<String> result = new ArrayList<String>(); while (iterator.hasNext()) { result.add(iterator.next()); } return Collections.unmodifiableList(result); }
/** * Creates a CacheBuilderSpec from a string. * * @param cacheBuilderSpecification the string form */ public static CacheBuilderSpec parse(String cacheBuilderSpecification) { CacheBuilderSpec spec = new CacheBuilderSpec(cacheBuilderSpecification); if (!cacheBuilderSpecification.isEmpty()) { for (String keyValuePair : KEYS_SPLITTER.split(cacheBuilderSpecification)) { List<String> keyAndValue = ImmutableList.copyOf(KEY_VALUE_SPLITTER.split(keyValuePair)); checkArgument(!keyAndValue.isEmpty(), "blank key-value pair"); checkArgument(keyAndValue.size() <= 2, "key-value pair %s with more than one equals sign", keyValuePair); // Find the ValueParser for the current key. String key = keyAndValue.get(0); ValueParser valueParser = VALUE_PARSERS.get(key); checkArgument(valueParser != null, "unknown key %s", key); String value = keyAndValue.size() == 1 ? null : keyAndValue.get(1); valueParser.parse(spec, key, value); } } return spec; }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, * and splits entries into keys and values using the specified separator. * * @since 10.0 */ @CheckReturnValue @Beta public MapSplitter withKeyValueSeparator(String separator) { return withKeyValueSeparator(on(separator)); }
private void addFile(String arg) { // at the very least, we'll print this about a file: // 0.txt // @@ -1,2 +1,2 @@, // -1\\r\\n, // -2\\r\\n, // ... (more lines that didn't fit) List<String> lines = NEWLINE_SPLITTER.splitToList(arg); if (!lines.isEmpty()) { addIntendedLine(NORMAL_INDENT, lines.get(0)); } for (int i = 1; i < Math.min(MIN_LINES_PER_FILE, lines.size()); ++i) { addIntendedLine(DIFF_INDENT, lines.get(i)); } // then we'll print the rest that can fit ListIterator<String> iter = lines.listIterator(Math.min(MIN_LINES_PER_FILE, lines.size())); while (iter.hasNext() && numLines < MAX_CHECK_MESSAGE_LINES) { addIntendedLine(DIFF_INDENT, iter.next()); } if (numLines >= MAX_CHECK_MESSAGE_LINES) { // we're out of space if (iter.hasNext()) { int linesLeft = lines.size() - iter.nextIndex(); addIntendedLine(NORMAL_INDENT, "... (" + linesLeft + " more lines that didn't fit)"); } } }
/** * Returns a splitter that considers any subsequence matching a given * pattern (regular expression) to be a separator. For example, {@code * Splitter.onPattern("\r?\n").split(entireFile)} splits a string into lines * whether it uses DOS-style or UNIX-style line terminators. This is * equivalent to {@code Splitter.on(Pattern.compile(pattern))}. * * @param separatorPattern the pattern that determines whether a subsequence * is a separator. This pattern may not match the empty string. * @return a splitter, with default settings, that uses this pattern * @throws java.util.regex.PatternSyntaxException if {@code separatorPattern} * is a malformed expression * @throws IllegalArgumentException if {@code separatorPattern} matches the * empty string */ @CheckReturnValue @GwtIncompatible("java.util.regex") public static Splitter onPattern(String separatorPattern) { return on(Pattern.compile(separatorPattern)); }
/** * Returns a splitter that behaves equivalently to {@code this} splitter, but * removes all leading or trailing characters matching the given {@code * CharMatcher} from each returned substring. For example, {@code * Splitter.on(',').trimResults(CharMatcher.is('_')).split("_a ,_b_ ,c__")} * returns an iterable containing {@code ["a ", "b_ ", "c"]}. * * @param trimmer a {@link CharMatcher} that determines whether a character * should be removed from the beginning/end of a subsequence * @return a splitter with the desired configuration */ // TODO(kevinb): throw if a trimmer was already specified! @CheckReturnValue public Splitter trimResults(CharMatcher trimmer) { checkNotNull(trimmer); return new Splitter(strategy, omitEmptyStrings, trimmer, limit); }
.getValue(Attributes.Name.CLASS_PATH.toString()); if (classpathAttribute != null) { for (String path : CLASS_PATH_ATTRIBUTE_SEPARATOR.split(classpathAttribute)) { URL url; try {
/** * Returns a splitter that behaves equivalently to {@code this} splitter but * stops splitting after it reaches the limit. * The limit defines the maximum number of items returned by the iterator, or * the maximum size of the list returned by {@link #splitToList}. * * <p>For example, * {@code Splitter.on(',').limit(3).split("a,b,c,d")} returns an iterable * containing {@code ["a", "b", "c,d"]}. When omitting empty strings, the * omitted strings do no count. Hence, * {@code Splitter.on(',').limit(3).omitEmptyStrings().split("a,,,b,,,c,d")} * returns an iterable containing {@code ["a", "b", "c,d"}. * When trim is requested, all entries, including the last are trimmed. Hence * {@code Splitter.on(',').limit(3).trimResults().split(" a , b , c , d ")} * results in {@code ["a", "b", "c , d"]}. * * @param limit the maximum number of items returned * @return a splitter with the desired configuration * @since 9.0 */ @CheckReturnValue public Splitter limit(int limit) { checkArgument(limit > 0, "must be greater than zero: %s", limit); return new Splitter(strategy, omitEmptyStrings, trimmer, limit); }
/** * Returns a splitter that considers any single character matched by the * given {@code CharMatcher} to be a separator. For example, {@code * Splitter.on(CharMatcher.anyOf(";,")).split("foo,;bar,quux")} returns an * iterable containing {@code ["foo", "", "bar", "quux"]}. * * @param separatorMatcher a {@link CharMatcher} that determines whether a * character is a separator * @return a splitter, with default settings, that uses this matcher */ @CheckReturnValue public static Splitter on(final CharMatcher separatorMatcher) { checkNotNull(separatorMatcher); return new Splitter( new Strategy() { @Override public SplittingIterator iterator(Splitter splitter, final CharSequence toSplit) { return new SplittingIterator(splitter, toSplit) { @Override int separatorStart(int start) { return separatorMatcher.indexIn(toSplit, start); } @Override int separatorEnd(int separatorPosition) { return separatorPosition + 1; } }; } }); }
checkArgument(length > 0, "The length may not be less than 1"); return new Splitter( new Strategy() { @Override
separatorPattern); return new Splitter( new Strategy() { @Override