|
17 | 17 | package org.metafacture.metafix; |
18 | 18 |
|
19 | 19 | import org.metafacture.metafix.api.FixPredicate; |
| 20 | +import org.metafacture.metafix.conditional.*; // checkstyle-disable-line AvoidStarImport |
20 | 21 |
|
21 | 22 | import java.util.List; |
22 | 23 | import java.util.Map; |
23 | 24 |
|
| 25 | +@Deprecated(since = "7.1.0", forRemoval = true) // checkstyle-disable-line ClassDataAbstractionCoupling|ClassFanOutComplexity |
24 | 26 | public enum FixConditional implements FixPredicate { |
25 | 27 |
|
26 | 28 | all_contain { |
27 | 29 | @Override |
28 | 30 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
29 | | - return testConditional(record, params, ALL, CONTAINS); |
| 31 | + return new AllContain().test(metafix, record, params, options); |
30 | 32 | } |
31 | 33 | }, |
32 | 34 | any_contain { |
33 | 35 | @Override |
34 | 36 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
35 | | - return testConditional(record, params, ANY, CONTAINS); |
| 37 | + return new AnyContain().test(metafix, record, params, options); |
36 | 38 | } |
37 | 39 | }, |
38 | 40 | none_contain { |
39 | 41 | @Override |
40 | 42 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
41 | | - return !any_contain.test(metafix, record, params, options); |
| 43 | + return new NoneContain().test(metafix, record, params, options); |
42 | 44 | } |
43 | 45 | }, |
44 | 46 | str_contain { |
45 | 47 | @Override |
46 | 48 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
47 | | - return testConditional(params, CONTAINS); |
| 49 | + return new StrContain().test(metafix, record, params, options); |
48 | 50 | } |
49 | 51 | }, |
50 | 52 |
|
51 | 53 | all_equal { |
52 | 54 | @Override |
53 | 55 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
54 | | - return testConditional(record, params, ALL, EQUALS); |
| 56 | + return new AllEqual().test(metafix, record, params, options); |
55 | 57 | } |
56 | 58 | }, |
57 | 59 | any_equal { |
58 | 60 | @Override |
59 | 61 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
60 | | - return testConditional(record, params, ANY, EQUALS); |
| 62 | + return new AnyEqual().test(metafix, record, params, options); |
61 | 63 | } |
62 | 64 | }, |
63 | 65 | none_equal { |
64 | 66 | @Override |
65 | 67 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
66 | | - return !any_equal.test(metafix, record, params, options); |
| 68 | + return new NoneEqual().test(metafix, record, params, options); |
67 | 69 | } |
68 | 70 | }, |
69 | 71 | str_equal { |
70 | 72 | @Override |
71 | 73 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
72 | | - return testConditional(params, EQUALS); |
| 74 | + return new StrEqual().test(metafix, record, params, options); |
73 | 75 | } |
74 | 76 | }, |
75 | 77 |
|
76 | 78 | exists { |
77 | 79 | @Override |
78 | 80 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
79 | | - return record.containsPath(params.get(0)); |
| 81 | + return new Exists().test(metafix, record, params, options); |
80 | 82 | } |
81 | 83 | }, |
82 | 84 |
|
83 | 85 | in { |
84 | 86 | @Override |
85 | 87 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
86 | | - final Value value1 = record.get(params.get(0)); |
87 | | - final Value value2 = record.get(params.get(1)); |
88 | | - |
89 | | - return value1 != null && value2 != null && value1.<Boolean>extractType((m, c) -> m |
90 | | - .ifArray(a1 -> value2.matchType() |
91 | | - .ifArray(a2 -> c.accept(a1.equals(a2))) |
92 | | - .orElse(v -> c.accept(false)) |
93 | | - ) |
94 | | - .ifHash(h1 -> value2.matchType() |
95 | | - .ifHash(h2 -> c.accept(h1.equals(h2))) |
96 | | - .orElse(v -> c.accept(false)) |
97 | | - ) |
98 | | - .ifString(s1 -> value2.matchType() |
99 | | - .ifArray(a2 -> c.accept(a2.stream().anyMatch(value1::equals))) |
100 | | - .ifHash(h2 -> c.accept(h2.containsField(s1))) |
101 | | - .ifString(s2 -> c.accept(s1.equals(s2))) |
102 | | - ) |
103 | | - ); |
| 88 | + return new In().test(metafix, record, params, options); |
104 | 89 | } |
105 | 90 | }, |
106 | 91 | is_contained_in { |
107 | 92 | @Override |
108 | 93 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
109 | | - return in.test(metafix, record, params, options); |
| 94 | + return new IsContainedIn().test(metafix, record, params, options); |
110 | 95 | } |
111 | 96 | }, |
112 | 97 |
|
113 | 98 | is_array { |
114 | 99 | @Override |
115 | 100 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
116 | | - return testConditional(record, params, Value::isArray); |
| 101 | + return new IsArray().test(metafix, record, params, options); |
117 | 102 | } |
118 | 103 | }, |
119 | 104 | is_empty { |
120 | 105 | @Override |
121 | 106 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
122 | | - return testConditional(record, params, IS_EMPTY); |
| 107 | + return new IsEmpty().test(metafix, record, params, options); |
123 | 108 | } |
124 | 109 | }, |
125 | 110 | is_false { |
126 | 111 | @Override |
127 | 112 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
128 | | - return testStringConditional(record, params, IS_FALSE); // TODO: strict=false |
| 113 | + return new IsFalse().test(metafix, record, params, options); |
129 | 114 | } |
130 | 115 | }, |
131 | 116 | is_hash { |
132 | 117 | @Override |
133 | 118 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
134 | | - return is_object.test(metafix, record, params, options); |
| 119 | + return new IsHash().test(metafix, record, params, options); |
135 | 120 | } |
136 | 121 | }, |
137 | 122 | is_number { |
138 | 123 | @Override |
139 | 124 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
140 | | - return testStringConditional(record, params, IS_NUMBER); |
| 125 | + return new IsNumber().test(metafix, record, params, options); |
141 | 126 | } |
142 | 127 | }, |
143 | 128 | is_object { |
144 | 129 | @Override |
145 | 130 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
146 | | - return testConditional(record, params, Value::isHash); |
| 131 | + return new IsObject().test(metafix, record, params, options); |
147 | 132 | } |
148 | 133 | }, |
149 | 134 | is_string { |
150 | 135 | @Override |
151 | 136 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
152 | | - return testConditional(record, params, Value::isString) && !is_number.test(metafix, record, params, options); |
| 137 | + return new IsString().test(metafix, record, params, options); |
153 | 138 | } |
154 | 139 | }, |
155 | 140 | is_true { |
156 | 141 | @Override |
157 | 142 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
158 | | - return testStringConditional(record, params, IS_TRUE); // TODO: strict=false |
| 143 | + return new IsTrue().test(metafix, record, params, options); |
159 | 144 | } |
160 | 145 | }, |
161 | 146 |
|
162 | 147 | all_match { |
163 | 148 | @Override |
164 | 149 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
165 | | - return testConditional(record, params, ALL, MATCHES); |
| 150 | + return new AllMatch().test(metafix, record, params, options); |
166 | 151 | } |
167 | 152 | }, |
168 | 153 | any_match { |
169 | 154 | @Override |
170 | 155 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
171 | | - return testConditional(record, params, ANY, MATCHES); |
| 156 | + return new AnyMatch().test(metafix, record, params, options); |
172 | 157 | } |
173 | 158 | }, |
174 | 159 | none_match { |
175 | 160 | @Override |
176 | 161 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
177 | | - return !any_match.test(metafix, record, params, options); |
| 162 | + return new NoneMatch().test(metafix, record, params, options); |
178 | 163 | } |
179 | 164 | }, |
180 | 165 | str_match { |
181 | 166 | @Override |
182 | 167 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
183 | | - return testConditional(params, MATCHES); |
| 168 | + return new StrMatch().test(metafix, record, params, options); |
184 | 169 | } |
185 | 170 | }, |
186 | 171 |
|
187 | 172 | greater_than { |
188 | 173 | @Override |
189 | 174 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
190 | | - return testConditional(record, params, ALL, GREATER_THAN); |
| 175 | + return new GreaterThan().test(metafix, record, params, options); |
191 | 176 | } |
192 | 177 | }, |
193 | 178 | less_than { |
194 | 179 | @Override |
195 | 180 | public boolean test(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) { |
196 | | - return testConditional(record, params, ALL, LESS_THAN); |
| 181 | + return new LessThan().test(metafix, record, params, options); |
197 | 182 | } |
198 | 183 | } |
199 | 184 |
|
|
0 commit comments