Java Code Examples for java.util.regex.Pattern#splitAsStream()

The following examples show how to use java.util.regex.Pattern#splitAsStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PatternStreamTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 2
Source File: PatternStreamTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 3
Source File: PatternStreamTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 4
Source File: PatternStreamTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 5
Source File: PatternStreamTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 6
Source File: PatternStreamTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Patterns")
public void testPatternSplitAsStream(String description, String input, Pattern pattern) {
    // Derive expected result from pattern.split
    List<String> expected = Arrays.asList(pattern.split(input));

    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 7
Source File: PatternStreamTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testLateBinding() {
    Pattern pattern = Pattern.compile(",");

    StringBuilder sb = new StringBuilder("a,b,c,d,e");
    Stream<String> stream = pattern.splitAsStream(sb);
    sb.setLength(3);
    assertEquals(Arrays.asList("a", "b"), stream.collect(Collectors.toList()));

    stream = pattern.splitAsStream(sb);
    sb.append(",f,g");
    assertEquals(Arrays.asList("a", "b", "f", "g"), stream.collect(Collectors.toList()));
}
 
Example 8
Source File: PatternStreamTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 9
Source File: PatternStreamTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 10
Source File: PatternStreamTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 11
Source File: PatternStreamTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 12
Source File: PatternStreamTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 13
Source File: PatternStreamTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 14
Source File: PatternStreamTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Stream<String>")
public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
    Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
    withData(TestData.Factory.ofSupplier(description, ss))
            .stream(LambdaTestHelpers.identity())
            .expectedResult(expected)
            .exercise();
}
 
Example 15
Source File: StreamEx.java    From streamex with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a stream from the given input sequence around matches of the
 * given pattern.
 *
 * <p>
 * The stream returned by this method contains each substring of the input
 * sequence that is terminated by another subsequence that matches this
 * pattern or is terminated by the end of the input sequence. The substrings
 * in the stream are in the order in which they occur in the input. Trailing
 * empty strings will be discarded and not encountered in the stream.
 *
 * <p>
 * If the given pattern does not match any subsequence of the input then the
 * resulting stream has just one element, namely the input sequence in
 * string form.
 *
 * <p>
 * When there is a positive-width match at the beginning of the input
 * sequence then an empty leading substring is included at the beginning of
 * the stream. A zero-width match at the beginning however never produces
 * such empty leading substring.
 *
 * <p>
 * If the input sequence is mutable, it must remain constant from the stream
 * creation until the execution of the terminal stream operation. Otherwise,
 * the result of the terminal stream operation is undefined.
 *
 * @param str The character sequence to be split
 * @param pattern The pattern to use for splitting
 *
 * @return The stream of strings computed by splitting the input around
 *         matches of this pattern
 * @see Pattern#splitAsStream(CharSequence)
 */
public static StreamEx<String> split(CharSequence str, Pattern pattern) {
    if (str.length() == 0)
        return of("");
    return new StreamEx<>(pattern.splitAsStream(str), StreamContext.SEQUENTIAL);
}