|
12 | 12 | public class ParseInput<OUT> |
13 | 13 | { |
14 | 14 | private final String expected; |
15 | | - private final boolean multiline; |
| 15 | + private final ParseInputOptions options; |
16 | 16 | private final Function1<String, Tuple<String, OUT>> transformer; |
17 | | - ParseInput(String expected, Function1<String, Tuple<String, OUT>> transformer, boolean multiline) |
| 17 | + ParseInput(String expected, Function1<String, Tuple<String, OUT>> transformer, ParseInputOptions options) |
18 | 18 | { |
19 | 19 | this.expected = expected; |
20 | 20 | this.transformer = transformer; |
21 | | - this.multiline = multiline; |
| 21 | + this.options = options; |
22 | 22 | } |
23 | 23 | public static ParseInput<String> from(String expected) |
24 | 24 | { |
25 | | - return new ParseInput<String>(expected, s -> new Tuple<>(s, s), false); |
| 25 | + return new ParseInput<String>(expected, s -> new Tuple<>(s, s), new ParseInputOptions()); |
26 | 26 | } |
27 | 27 | public ParseInput<OUT> multiline() |
28 | 28 | { |
29 | | - return new ParseInput<>(expected, transformer, true); |
| 29 | + return new ParseInput<>(expected, transformer, new ParseInputOptions(true)); |
30 | 30 | } |
31 | 31 | public Queryable<Tuple<String, OUT>> parse() |
32 | 32 | { |
33 | | - Function1<String, Boolean> f = multiline ? s -> s.contains("->") : s -> true; |
| 33 | + Function1<String, Boolean> f = options.multiline ? s -> s.contains("->") : s -> true; |
34 | 34 | return Queryable.as(expected.split("\n")) // |
35 | 35 | .where(f) // |
36 | 36 | .select(l -> l.split("->")[0].trim()) // |
@@ -66,21 +66,33 @@ public static <OUT> Function1<String, OUT> getTransformerForClass(Class<OUT> tar |
66 | 66 | // ************* 1 parameter |
67 | 67 | public <T1> ParseInputWith1Parameters<T1> withTypes(Class<T1> type1) |
68 | 68 | { |
69 | | - return ParseInputWith1Parameters.create(expected, type1, multiline); |
| 69 | + return ParseInputWith1Parameters.create(expected, type1, options); |
70 | 70 | } |
71 | 71 | public <T1> ParseInputWith1Parameters<T1> transformTo(Function1<String, T1> transformer) |
72 | 72 | { |
73 | | - return new ParseInputWith1Parameters<>(expected, transformer, multiline); |
| 73 | + return new ParseInputWith1Parameters<>(expected, transformer, options); |
74 | 74 | } |
75 | 75 | // ************* 2 parameters |
76 | 76 | public <T1, T2> ParseInputWith2Parameters<T1, T2> withTypes(Class<T1> type1, Class<T2> type2) |
77 | 77 | { |
78 | 78 | return ParseInputWith2Parameters.create(expected, getTransformerForClass(type1), getTransformerForClass(type2), |
79 | | - multiline); |
| 79 | + options); |
80 | 80 | } |
81 | 81 | public <T1, T2> ParseInputWith2Parameters<T1, T2> transformTo(Function1<String, T1> transformer1, |
82 | 82 | Function1<String, T2> transformer2) |
83 | 83 | { |
84 | | - return ParseInputWith2Parameters.create(expected, transformer1, transformer2, multiline); |
| 84 | + return ParseInputWith2Parameters.create(expected, transformer1, transformer2, options); |
| 85 | + } |
| 86 | + public static class ParseInputOptions |
| 87 | + { |
| 88 | + public final boolean multiline; |
| 89 | + public ParseInputOptions() |
| 90 | + { |
| 91 | + this(false); |
| 92 | + } |
| 93 | + public ParseInputOptions(boolean multiline) |
| 94 | + { |
| 95 | + this.multiline = multiline; |
| 96 | + } |
85 | 97 | } |
86 | 98 | } |
0 commit comments