|
3 | 3 | import com.spun.util.Tuple; |
4 | 4 | import com.spun.util.Tuple3; |
5 | 5 | import org.lambda.functions.Function1; |
6 | | -import org.lambda.functions.Function2; |
7 | 6 | import org.lambda.functions.Function3; |
8 | 7 | import org.lambda.query.Queryable; |
9 | 8 |
|
10 | 9 | public class ParseInputWith3Parameters<IN1, IN2, IN3> |
11 | 10 | { |
12 | | - private final String expected; |
13 | | - private final Function1<String, Tuple3<IN1, IN2, IN3>> transformer; |
14 | | - private final ParseInput.ParseInputOptions options; |
15 | | - |
16 | | - public ParseInputWith3Parameters(String expected, Function1<String, Tuple3<IN1, IN2, IN3>> transformer, |
17 | | - ParseInput.ParseInputOptions options) |
18 | | - { |
19 | | - this.expected = expected; |
20 | | - this.transformer = transformer; |
21 | | - this.options = options; |
22 | | - } |
23 | | - |
24 | | - public static <IN1, IN2, IN3> ParseInputWith3Parameters<IN1, IN2, IN3> create(String expected, |
25 | | - Function1<String, IN1> t1, Function1<String, IN2> t2, Function1<String, IN3> t3, |
26 | | - ParseInput.ParseInputOptions options) |
27 | | - { |
28 | | - Function1<String, Tuple3<IN1, IN2, IN3>> f = s -> { |
29 | | - Queryable<String> temp = Queryable.as(s.split(",")).select(String::trim); |
30 | | - IN1 v1 = t1.call(temp.get(0)); |
31 | | - IN2 v2 = t2.call(temp.get(1)); |
32 | | - IN3 v3 = t3.call(temp.get(2)); |
33 | | - return new Tuple3<>(v1, v2, v3); |
34 | | - }; |
35 | | - return new ParseInputWith3Parameters<>(expected, f, options); |
36 | | - } |
37 | | - |
38 | | - private ParseInput<Tuple3<IN1, IN2, IN3>> getParseInput() |
39 | | - { |
40 | | - return new ParseInput<>(expected, s -> new Tuple<>(s, transformer.call(s)), options); |
41 | | - } |
42 | | - |
43 | | -// public <OUT> ParseInputWith1Parameters<OUT> transformTo(Function3<Tuple3<IN1, IN2, IN3>, OUT> transform) |
44 | | -// { |
45 | | -// Function1<String, OUT> f1 = (t) -> { |
46 | | -// Tuple3<IN1, IN2, IN3> transformed = transformer.call(t); |
47 | | -// return transform.call(transformed); |
48 | | -// }; |
49 | | -// return new ParseInputWith1Parameters<>(expected, f1, options); |
50 | | -// } |
51 | | - |
52 | | - public void verifyAll(Function1<Tuple3<IN1, IN2, IN3>, Object> transform) |
53 | | - { |
54 | | - getParseInput().verifyAll(transform); |
55 | | - } |
| 11 | + private final String expected; |
| 12 | + private final Function1<String, Tuple3<IN1, IN2, IN3>> transformer; |
| 13 | + private final ParseInput.ParseInputOptions options; |
| 14 | + public ParseInputWith3Parameters(String expected, Function1<String, Tuple3<IN1, IN2, IN3>> transformer, |
| 15 | + ParseInput.ParseInputOptions options) |
| 16 | + { |
| 17 | + this.expected = expected; |
| 18 | + this.transformer = transformer; |
| 19 | + this.options = options; |
| 20 | + } |
| 21 | + public static <IN1, IN2, IN3> ParseInputWith3Parameters<IN1, IN2, IN3> create(String expected, |
| 22 | + Function1<String, IN1> t1, Function1<String, IN2> t2, Function1<String, IN3> t3, |
| 23 | + ParseInput.ParseInputOptions options) |
| 24 | + { |
| 25 | + Function1<String, Tuple3<IN1, IN2, IN3>> f = s -> { |
| 26 | + Queryable<String> temp = Queryable.as(s.split(",")).select(String::trim); |
| 27 | + IN1 v1 = t1.call(temp.get(0)); |
| 28 | + IN2 v2 = t2.call(temp.get(1)); |
| 29 | + IN3 v3 = t3.call(temp.get(2)); |
| 30 | + return new Tuple3<>(v1, v2, v3); |
| 31 | + }; |
| 32 | + return new ParseInputWith3Parameters<>(expected, f, options); |
| 33 | + } |
| 34 | + private ParseInput<Tuple3<IN1, IN2, IN3>> getParseInput() |
| 35 | + { |
| 36 | + return new ParseInput<>(expected, s -> new Tuple<>(s, transformer.call(s)), options); |
| 37 | + } |
| 38 | + // public <OUT> ParseInputWith1Parameters<OUT> transformTo(Function3<Tuple3<IN1, IN2, IN3>, OUT> transform) |
| 39 | + // { |
| 40 | + // Function1<String, OUT> f1 = (t) -> { |
| 41 | + // Tuple3<IN1, IN2, IN3> transformed = transformer.call(t); |
| 42 | + // return transform.call(transformed); |
| 43 | + // }; |
| 44 | + // return new ParseInputWith1Parameters<>(expected, f1, options); |
| 45 | + // } |
| 46 | + public void verifyAll(Function1<Tuple3<IN1, IN2, IN3>, Object> transform) |
| 47 | + { |
| 48 | + getParseInput().verifyAll(transform); |
| 49 | + } |
| 50 | + public void verifyAll(Function3<IN1, IN2, IN3, Object> transform) |
| 51 | + { |
| 52 | + getParseInput().verifyAll((t) -> transform.call(t.getFirst(), t.getSecond(), t.getThird())); |
| 53 | + } |
56 | 54 | } |
0 commit comments