@@ -17,9 +17,12 @@ public interface Step<I, O> {
17
17
Condition <O > apply (I value , Description mismatch );
18
18
}
19
19
20
- public boolean matching (Matcher <T > match ) { return matching (match , "" ); }
20
+ private Condition () { }
21
+
21
22
public abstract boolean matching (Matcher <T > match , String message );
22
23
public abstract <U > Condition <U > and (Step <? super T , U > mapping );
24
+
25
+ public final boolean matching (Matcher <T > match ) { return matching (match , "" ); }
23
26
public final <U > Condition <U > then (Step <? super T , U > mapping ) { return and (mapping ); }
24
27
25
28
@ SuppressWarnings ("unchecked" )
@@ -28,25 +31,35 @@ public static <T> Condition<T> notMatched() {
28
31
}
29
32
30
33
public static <T > Condition <T > matched (final T theValue , final Description mismatch ) {
31
- return new Condition <T >() {
32
- @ Override
33
- public boolean matching (Matcher <T > matcher , String message ) {
34
- if (matcher .matches (theValue )) {
35
- return true ;
36
- }
37
- mismatch .appendText (message );
38
- matcher .describeMismatch (theValue , mismatch );
39
- return false ;
40
- }
34
+ return new Matched <T >(theValue , mismatch );
35
+ }
36
+
37
+ private static final class Matched <T > extends Condition <T > {
38
+ private final T theValue ;
39
+ private final Description mismatch ;
41
40
42
- @ Override
43
- public <U > Condition <U > and (Step <? super T , U > next ) {
44
- return next .apply (theValue , mismatch );
41
+ private Matched (T theValue , Description mismatch ) {
42
+ this .theValue = theValue ;
43
+ this .mismatch = mismatch ;
44
+ }
45
+
46
+ @ Override
47
+ public boolean matching (Matcher <T > matcher , String message ) {
48
+ if (matcher .matches (theValue )) {
49
+ return true ;
45
50
}
46
- };
51
+ mismatch .appendText (message );
52
+ matcher .describeMismatch (theValue , mismatch );
53
+ return false ;
54
+ }
55
+
56
+ @ Override
57
+ public <U > Condition <U > and (Step <? super T , U > next ) {
58
+ return next .apply (theValue , mismatch );
59
+ }
47
60
}
48
61
49
- private static class NotMatched <T > extends Condition <T > {
62
+ private static final class NotMatched <T > extends Condition <T > {
50
63
@ Override public boolean matching (Matcher <T > match , String message ) { return false ; }
51
64
52
65
@ Override public <U > Condition <U > and (Step <? super T , U > mapping ) {
0 commit comments