aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks/src/jmh/java/benchmarks/flow/scrabble/optimizations/StringFlowable.java
blob: 3d36a0d8e7d88547fb625ad9f220ebb4a68ce3f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package benchmarks.flow.scrabble.optimizations;

import io.reactivex.Flowable;
import io.reactivex.FlowableTransformer;
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.plugins.RxJavaPlugins;

import java.util.regex.Pattern;

public final class StringFlowable {
    /** Utility class. */
    private StringFlowable() {
        throw new IllegalStateException("No instances!");
    }

    /**
     * Signals each character of the given string CharSequence as Integers.
     * @param string the source of characters
     * @return the new Flowable instance
     */
    public static Flowable<Integer> characters(CharSequence string) {
        ObjectHelper.requireNonNull(string, "string is null");
        return RxJavaPlugins.onAssembly(new FlowableCharSequence(string));
    }

    /**
     * Splits the input sequence of strings based on a pattern even across subsequent
     * elements if needed.
     * @param pattern the Rexexp pattern to split along
     * @return the new FlowableTransformer instance
     *
     * @since 0.13.0
     */
    public static FlowableTransformer<String, String> split(Pattern pattern) {
        return split(pattern, Flowable.bufferSize());
    }

    /**
     * Splits the input sequence of strings based on a pattern even across subsequent
     * elements if needed.
     * @param pattern the Rexexp pattern to split along
     * @param bufferSize the number of items to prefetch from the upstream
     * @return the new FlowableTransformer instance
     *
     * @since 0.13.0
     */
    public static FlowableTransformer<String, String> split(Pattern pattern, int bufferSize) {
        ObjectHelper.requireNonNull(pattern, "pattern is null");
        ObjectHelper.verifyPositive(bufferSize, "bufferSize");
        return new FlowableSplit(null, pattern, bufferSize);
    }

    /**
     * Splits the input sequence of strings based on a pattern even across subsequent
     * elements if needed.
     * @param pattern the Rexexp pattern to split along
     * @return the new FlowableTransformer instance
     *
     * @since 0.13.0
     */
    public static FlowableTransformer<String, String> split(String pattern) {
        return split(pattern, Flowable.bufferSize());
    }

    /**
     * Splits the input sequence of strings based on a pattern even across subsequent
     * elements if needed.
     * @param pattern the Rexexp pattern to split along
     * @param bufferSize the number of items to prefetch from the upstream
     * @return the new FlowableTransformer instance
     *
     * @since 0.13.0
     */
    public static FlowableTransformer<String, String> split(String pattern, int bufferSize) {
        return split(Pattern.compile(pattern), bufferSize);
    }

}