valueFn) {
40 | return keys.stream()
41 | .map(k -> entryOf(k, valueFn.apply(k)))
42 | .collect(entriesToMap());
43 | }
44 |
45 | /**
46 | * Create a map of the list of keys and list of values. Values are associated by the index
47 | * in the list.
48 | *
49 | * Will throw exception if sizes differ or either one is {@code null}.
50 | *
51 | * @param keys the keys of the map
52 | * @param values the values of the map
53 | * @param type of keys
54 | * @param type of values
55 | * @return the map containing the entries
56 | */
57 | public static Map mapOfLists(List keys, List values) {
58 | if (keys.size() != values.size()) {
59 | throw new IllegalArgumentException(String.format("Keys and values sizes differ: %d != %d", keys.size(), values.size()));
60 | }
61 | return IntStream.range(0, keys.size())
62 | .mapToObj(i -> entryOf(keys.get(i), values.get(i)))
63 | .collect(entriesToMap());
64 | }
65 |
66 | /**
67 | * Combine multiple maps to a single one. Will throw exception on duplicate keys.
68 | * If duplicate values are expected, use {@link #combine(BinaryOperator, Map[])}
69 | *
70 | * @param maps the maps to combine
71 | * @param the key type
72 | * @param the value type
73 | * @return the resulting combined map
74 | */
75 | public static Map combine(Map... maps) {
76 | return Arrays.stream(maps)
77 | .flatMap(m -> m.entrySet().stream())
78 | .collect(entriesToMap());
79 | }
80 |
81 | /**
82 | * Combine multiple maps to a single one. Uses {@code mergeFn} to cope with duplicate keys.
83 | *
84 | * @param maps the maps to combine
85 | * @param mergeFn the function to combine values on duplicate keys
86 | * @param the key type
87 | * @param the value type
88 | * @return the resulting combined map
89 | */
90 | public static Map combine(BinaryOperator mergeFn, Map... maps) {
91 | return Arrays.stream(maps)
92 | .flatMap(m -> m.entrySet().stream())
93 | .collect(entriesToMap(mergeFn));
94 | }
95 |
96 | /**
97 | * Combine multiple maps to a single one. Uses the first encountered value as the value
98 | * on duplicate keys.
99 | *
100 | * @param maps the maps to combine
101 | * @param the key type
102 | * @param the value type
103 | * @return the resulting combined map
104 | */
105 | public static Map combineAndSkip(Map... maps) {
106 | return combine((V v1, V v2) -> v1, maps);
107 | }
108 |
109 | /**
110 | * Create a map with the given values
111 | * @param k1 key
112 | * @param v1 value
113 | * @param type of key
114 | * @param type of value
115 | * @return the map
116 | */
117 | public static Map mapOf(K k1, V v1) {
118 | return mapOfEntries(entryOf(k1, v1));
119 | }
120 |
121 | /**
122 | * Create a map with the given values
123 | * @param k1 key
124 | * @param v1 value
125 | * @param k2 key
126 | * @param v2 value
127 | * @param type of key
128 | * @param type of value
129 | * @return the map
130 | */
131 | public static Map mapOf(K k1, V v1, K k2, V v2) {
132 | return combine(
133 | mapOf(k1, v1),
134 | mapOf(k2, v2)
135 | );
136 | }
137 |
138 | /**
139 | *
140 | * @param k1 key
141 | * @param v1 value
142 | * @param k2 key
143 | * @param v2 value
144 | * @param k3 key
145 | * @param v3 value
146 | * @param key type
147 | * @param value type
148 | * @return a map with the values
149 | */
150 | public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3) {
151 | return combine(
152 | mapOf(k1, v1),
153 | mapOf(k2, v2),
154 | mapOf(k3, v3)
155 | );
156 | }
157 |
158 | /**
159 | *
160 | * @param k1 key
161 | * @param v1 value
162 | * @param k2 key
163 | * @param v2 value
164 | * @param k3 key
165 | * @param v3 value
166 | * @param k4 key
167 | * @param v4 value
168 | * @param key type
169 | * @param value type
170 | * @return a map with the values
171 | */
172 | public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
173 | return combine(
174 | mapOf(k1, v1),
175 | mapOf(k2, v2),
176 | mapOf(k3, v3),
177 | mapOf(k4, v4)
178 | );
179 | }
180 |
181 | /**
182 | *
183 | * @param k1 key
184 | * @param v1 value
185 | * @param k2 key
186 | * @param v2 value
187 | * @param k3 key
188 | * @param v3 value
189 | * @param k4 key
190 | * @param v4 value
191 | * @param k5 key
192 | * @param v5 value
193 | * @param key type
194 | * @param value type
195 | * @return a map with the values
196 | */
197 | public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
198 | return combine(
199 | mapOf(k1, v1),
200 | mapOf(k2, v2),
201 | mapOf(k3, v3),
202 | mapOf(k4, v4),
203 | mapOf(k5, v5)
204 | );
205 | }
206 |
207 | /**
208 | *
209 | * @param k1 key
210 | * @param v1 value
211 | * @param k2 key
212 | * @param v2 value
213 | * @param k3 key
214 | * @param v3 value
215 | * @param k4 key
216 | * @param v4 value
217 | * @param k5 key
218 | * @param v5 value
219 | * @param k6 key
220 | * @param v6 value
221 | * @param key type
222 | * @param value type
223 | * @return a map with the values
224 | */
225 | public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) {
226 | return combine(
227 | mapOf(k1, v1),
228 | mapOf(k2, v2),
229 | mapOf(k3, v3),
230 | mapOf(k4, v4),
231 | mapOf(k5, v5),
232 | mapOf(k6, v6)
233 | );
234 | }
235 |
236 | /**
237 | *
238 | * @param k1 key
239 | * @param v1 value
240 | * @param k2 key
241 | * @param v2 value
242 | * @param k3 key
243 | * @param v3 value
244 | * @param k4 key
245 | * @param v4 value
246 | * @param k5 key
247 | * @param v5 value
248 | * @param k6 key
249 | * @param v6 value
250 | * @param k7 key
251 | * @param v7 value
252 | * @param key type
253 | * @param value type
254 | * @return a map with the values
255 | */
256 | public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) {
257 | return combine(
258 | mapOf(k1, v1),
259 | mapOf(k2, v2),
260 | mapOf(k3, v3),
261 | mapOf(k4, v4),
262 | mapOf(k5, v5),
263 | mapOf(k6, v6),
264 | mapOf(k7, v7)
265 | );
266 | }
267 |
268 | /**
269 | *
270 | * @param k1 key
271 | * @param v1 value
272 | * @param k2 key
273 | * @param v2 value
274 | * @param k3 key
275 | * @param v3 value
276 | * @param k4 key
277 | * @param v4 value
278 | * @param k5 key
279 | * @param v5 value
280 | * @param k6 key
281 | * @param v6 value
282 | * @param k7 key
283 | * @param v7 value
284 | * @param k8 key
285 | * @param v8 value
286 | * @param key type
287 | * @param value type
288 | * @return a map with the values
289 | */
290 | public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8) {
291 | return combine(
292 | mapOf(k1, v1),
293 | mapOf(k2, v2),
294 | mapOf(k3, v3),
295 | mapOf(k4, v4),
296 | mapOf(k5, v5),
297 | mapOf(k6, v6),
298 | mapOf(k7, v7),
299 | mapOf(k8, v8)
300 | );
301 | }
302 |
303 | /**
304 | *
305 | * @param k1 key
306 | * @param v1 value
307 | * @param k2 key
308 | * @param v2 value
309 | * @param k3 key
310 | * @param v3 value
311 | * @param k4 key
312 | * @param v4 value
313 | * @param k5 key
314 | * @param v5 value
315 | * @param k6 key
316 | * @param v6 value
317 | * @param k7 key
318 | * @param v7 value
319 | * @param k8 key
320 | * @param v8 value
321 | * @param k9 key
322 | * @param v9 value
323 | * @param key type
324 | * @param value type
325 | * @return a map with the values
326 | */
327 | public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9) {
328 | return combine(
329 | mapOf(k1, v1),
330 | mapOf(k2, v2),
331 | mapOf(k3, v3),
332 | mapOf(k4, v4),
333 | mapOf(k5, v5),
334 | mapOf(k6, v6),
335 | mapOf(k7, v7),
336 | mapOf(k8, v8),
337 | mapOf(k9, v9)
338 | );
339 | }
340 |
341 | /**
342 | *
343 | * @param k1 key
344 | * @param v1 value
345 | * @param k2 key
346 | * @param v2 value
347 | * @param k3 key
348 | * @param v3 value
349 | * @param k4 key
350 | * @param v4 value
351 | * @param k5 key
352 | * @param v5 value
353 | * @param k6 key
354 | * @param v6 value
355 | * @param k7 key
356 | * @param v7 value
357 | * @param k8 key
358 | * @param v8 value
359 | * @param k9 key
360 | * @param v9 value
361 | * @param k10 key
362 | * @param v10 value
363 | * @param key type
364 | * @param value type
365 | * @return a map with the values
366 | */
367 | public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10) {
368 | return combine(
369 | mapOf(k1, v1),
370 | mapOf(k2, v2),
371 | mapOf(k3, v3),
372 | mapOf(k4, v4),
373 | mapOf(k5, v5),
374 | mapOf(k6, v6),
375 | mapOf(k7, v7),
376 | mapOf(k8, v8),
377 | mapOf(k9, v9),
378 | mapOf(k10, v10)
379 | );
380 | }
381 | }
382 |
--------------------------------------------------------------------------------
/src/main/java/com/nitorcreations/collections/NSets.java:
--------------------------------------------------------------------------------
1 | package com.nitorcreations.collections;
2 |
3 | import com.nitorcreations.streams.NStreams;
4 |
5 | import java.util.HashSet;
6 | import java.util.Iterator;
7 | import java.util.Set;
8 |
9 | import static java.util.Arrays.asList;
10 | import static java.util.stream.Collectors.toSet;
11 |
12 | public final class NSets {
13 |
14 | private NSets() { /** prevent instantiation */}
15 |
16 | /**
17 | * Create a new {@link HashSet} with the given values
18 | *
19 | * @param values the values to add to the set.
20 | * @param the type of the element
21 | * @return the set containing the values
22 | */
23 | @SafeVarargs
24 | public static Set asSet(V... values) {
25 | return new HashSet<>(asList(values));
26 | }
27 |
28 | /**
29 | * Create a new set with the values of the given iterable
30 | *
31 | * @param values the values to add to the set.
32 | * @param the type of the element
33 | * @return the set containing the values
34 | */
35 | public static Set asSet(Iterable values) {
36 | return NStreams.asStream(values).collect(toSet());
37 | }
38 |
39 | /**
40 | * Create a new set with the values of the given iterator
41 | *
42 | * @param iterator the values to add to the set.
43 | * @param the type of the element
44 | * @return the set containing the values
45 | */
46 | public static Set asSet(Iterator iterator) {
47 | return asSet(() -> iterator);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/nitorcreations/predicates/NCollectionPredicates.java:
--------------------------------------------------------------------------------
1 | package com.nitorcreations.predicates;
2 |
3 | import java.util.Arrays;
4 | import java.util.function.Predicate;
5 |
6 | import static com.nitorcreations.predicates.NPredicates.*;
7 | import static com.nitorcreations.streams.NStreams.asStream;
8 | import static java.util.Arrays.asList;
9 |
10 | public final class NCollectionPredicates {
11 | private NCollectionPredicates() { /** prevent instantiation */}
12 |
13 |
14 | /**
15 | * Checks that the iterable is non-null and not empty
16 | * @param type of an element
17 | * @param type of the iterable
18 | * @return predicate
19 | */
20 | public static > Predicate notEmpty() {
21 | return NPredicates.notNull().and(s -> s.iterator().hasNext());
22 | }
23 |
24 | /**
25 | * Checks that the iterable is non-null and empty
26 | * @param type of an element
27 | * @param type of the iterable
28 | * @return predicate
29 | */
30 | public static > Predicate empty() {
31 | return NPredicates.notNull().and(s -> !s.iterator().hasNext());
32 | }
33 |
34 | /**
35 | * Checks that the iterable is non-null and contains target element (comparison by {@code #equals})
36 | * @param type of an element
37 | * @param type of the iterable
38 | * @return predicate
39 | */
40 | public static > Predicate contains(T element) {
41 | return NPredicates.notNull().and(it -> asStream(it).anyMatch(equalTo(element)));
42 | }
43 |
44 | /**
45 | * Checks that the iterable is non-null and contains all of the target elements (comparison by {@code #equals})
46 | * @param type of an element
47 | * @param type of the iterable
48 | * @return predicate
49 | */
50 | @SafeVarargs
51 | public static > Predicate containsAll(T... elements) {
52 | return containsAll(asList(elements));
53 | }
54 |
55 | /**
56 | * Checks that the iterable is non-null and contains all of the target elements (comparison by {@code #equals})
57 | * @param elements
58 | * @param type of an element
59 | * @param type of the iterable
60 | * @return predicate
61 | */
62 | public static > Predicate containsAll(Iterable elements) {
63 | final Predicate allmatch = asStream(elements)
64 | .map(NCollectionPredicates::contains)
65 | .reduce(notEmpty(), (p1, p2) -> p1.and(p2));
66 | return NPredicates.notNull().and(allmatch);
67 | }
68 |
69 | /**
70 | * Checks that the iterable is non-null and contains any of the target elements (comparison by {@code #equals})
71 | * @param type of an element
72 | * @param type of the iterable
73 | * @return predicate
74 | */
75 | @SafeVarargs
76 | public static > Predicate containsAny(T... elements) {
77 | return containsAny(asList(elements));
78 | }
79 |
80 | /**
81 | * Checks that the iterable is non-null and contains any of the target elements (comparison by {@code #equals})
82 | * @param elements
83 | * @param type of an element
84 | * @param type of the iterable
85 | * @return predicate
86 | */
87 | public static > Predicate containsAny(Iterable elements) {
88 | final Predicate anyMatches = asStream(elements)
89 | .map(NCollectionPredicates::contains)
90 | .reduce(never(), (p1, p2) -> p1.or(p2));
91 | return NPredicates.notNull().and(anyMatches);
92 | }
93 |
94 | /**
95 | * Checks that the iterable is non-null and does not contain the target element (comparison by {@code #equals})
96 | * @param element the element
97 | * @param type of an element
98 | * @param type of the iterable
99 | * @return predicate
100 | */
101 | public static > Predicate doesNotContain(T element) {
102 | return doesNotContainAnyOf(element);
103 | }
104 |
105 | /**
106 | * Checks that the iterable is non-null and contains none of target elements
107 | * @param elements elements
108 | * @param type of an element
109 | * @param type of the iterable
110 | * @return predicate
111 | */
112 | @SafeVarargs
113 | public static > Predicate doesNotContainAnyOf(T... elements) {
114 | return doesNotContainAnyOf(Arrays.asList(elements));
115 | }
116 |
117 | /**
118 | * Checks that the iterable is non-null and contains none of target elements
119 | * @param elements elements
120 | * @param type of an element
121 | * @param type of the iterable
122 | * @return predicate
123 | */
124 | public static > Predicate doesNotContainAnyOf(Iterable elements) {
125 | return NPredicates.notNull().and(not(containsAny(elements)));
126 | }
127 |
128 | /**
129 | * Checks that iterable is non-null and does not contain all of the target elements. Will return {@code true} if some of the elements are present
130 | *
131 | * @param elements elements to find
132 | * @param type of an element
133 | * @param type of the iterable
134 | * @return predicate
135 | */
136 | @SafeVarargs
137 | public static > Predicate doesNotContainAllOf(T... elements) {
138 | return doesNotContainAllOf(asList(elements));
139 | }
140 |
141 | /**
142 | * Checks that iterable is non-null and does not contain all of the target elements. Will return {@code true} if some of the elements are present
143 | *
144 | * @param elements
145 | * @param type of an element
146 | * @param type of the iterable
147 | * @return predicate
148 | */
149 | public static > Predicate doesNotContainAllOf(Iterable elements) {
150 | return NPredicates.notNull().and(not(containsAll(elements)));
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/src/main/java/com/nitorcreations/predicates/NComparablePredicates.java:
--------------------------------------------------------------------------------
1 | package com.nitorcreations.predicates;
2 |
3 | import java.util.function.Predicate;
4 |
5 | public final class NComparablePredicates {
6 |
7 | private NComparablePredicates() { /** prevent instantiation */}
8 |
9 | /**
10 | * Matches when target is less than {@code other}
11 | * @param other the number to compare to
12 | * @param type of comparables
13 | * @return predicate
14 | */
15 | public static Predicate> lt(T other) {
16 | return lessThan(other);
17 | }
18 |
19 | /**
20 | * Matches when target is less than or equal to {@code other}
21 | * @param other the number to compare to
22 | * @param type of comparables
23 | * @return predicate
24 | */
25 | public static Predicate> lte(T other) {
26 | return lessThanOrEqualTo(other);
27 | }
28 |
29 | /**
30 | * Matches when target is less than {@code other}
31 | * @param other the number to compare to
32 | * @param type of comparables
33 | * @return predicate
34 | */
35 | public static Predicate> lessThan(T other) {
36 | return a -> a.compareTo(other) < 0;
37 | }
38 |
39 | /**
40 | * Matches when target is less than or equal to {@code other}
41 | * @param other the number to compare to
42 | * @param type of comparables
43 | * @return predicate
44 | */
45 | public static Predicate> lessThanOrEqualTo(T other) {
46 | return a -> a.compareTo(other) <= 0;
47 | }
48 |
49 | /**
50 | * Matches when target is greater than {@code other}
51 | * @param other the number to compare to
52 | * @param type of comparables
53 | * @return predicate
54 | */
55 | public static Predicate> gt(T other) {
56 | return greaterThan(other);
57 | }
58 |
59 | /**
60 | * Matches when target is greater than or equal to {@code other}
61 | * @param other the number to compare to
62 | * @param type of comparables
63 | * @return predicate
64 | */
65 | public static Predicate> gte(T other) {
66 | return greaterThanOrEqualTo(other);
67 | }
68 |
69 | /**
70 | * Matches when target is greater than {@code other}
71 | * @param other the number to compare to
72 | * @param type of comparables
73 | * @return predicate
74 | */
75 | public static Predicate> greaterThan(T other) {
76 | return a -> a.compareTo(other) > 0;
77 | }
78 |
79 | /**
80 | * Matches when target is greater than or equal to {@code other}
81 | * @param other the number to compare to
82 | * @param type of comparables
83 | * @return predicate
84 | */
85 | public static Predicate> greaterThanOrEqualTo(T other) {
86 | return a -> a.compareTo(other) >= 0;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/com/nitorcreations/predicates/NOptionalPredicates.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015- Nitor Creations Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package com.nitorcreations.predicates;
19 |
20 | import java.util.Optional;
21 | import java.util.function.Predicate;
22 |
23 | import static com.nitorcreations.predicates.NPredicates.equalTo;
24 | import static com.nitorcreations.predicates.NPredicates.not;
25 |
26 | public final class NOptionalPredicates {
27 | private NOptionalPredicates() { /** prevent instantiation */}
28 |
29 | /**
30 | * Predicate that checks if optional is empty
31 | * @param type of containing optional
32 | * @return the predicate
33 | */
34 | public static Predicate> empty() {
35 | return not(present());
36 | }
37 |
38 | /**
39 | * Predicate that checks if optional is present
40 | * @param type of containing optional
41 | * @return the predicate
42 | */
43 | public static Predicate> present() {
44 | return x -> x.isPresent();
45 | }
46 |
47 |
48 | /**
49 | * Predicate that checks if value in optional matches target.
50 | * Returns {@code false} if value not present.
51 | * @param predicate the predicate to apply to the optional's contents
52 | * @param type of containing optional
53 | * @return the predicate
54 | */
55 | public static Predicate> havingValue(Predicate predicate) {
56 | return NOptionalPredicates.present().and(o -> predicate.test(o.get()));
57 | }
58 |
59 | /**
60 | * Shorthand for {@code havingValue(equalTo(value))}
61 | * @param value the value to compare the contents to
62 | * @param type of containing optional
63 | * @return the predicate
64 | */
65 | public static Predicate> havingValue(T value) {
66 | return havingValue(equalTo(value));
67 | }
68 |
69 | /**
70 | * Shorthand for {@code havingValue(not(predicate))}
71 | * @param predicate the predicate to apply to the optional's contents
72 | * @param type of containing optional
73 | * @return the predicate
74 | */
75 | public static Predicate> notHavingValue(Predicate predicate) {
76 | return havingValue(not(predicate));
77 | }
78 |
79 | /**
80 | * Shorthand for {@code havingValue(not(equalTo(value)))}
81 | * @param value the value to compare the contents to
82 | * @param type of containing optional
83 | * @return the predicate
84 | */
85 | public static Predicate> notHavingValue(T value) {
86 | return notHavingValue(equalTo(value));
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/com/nitorcreations/predicates/NPredicates.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015- Nitor Creations Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package com.nitorcreations.predicates;
19 |
20 | import java.util.Objects;
21 | import java.util.function.Function;
22 | import java.util.function.Predicate;
23 | import java.util.stream.Stream;
24 |
25 | public final class NPredicates {
26 | private NPredicates() { /** prevent instantiation */}
27 |
28 | /**
29 | * Predicate that checks if {@code value == x}
30 | * @param value the value to compare to
31 | * @param type of value
32 | * @return predicate
33 | */
34 | public static Predicate is(T value) {
35 | return x -> x == value;
36 | }
37 |
38 | /**
39 | * Predicate that checks {@code value.equals(x)}
40 | * @param value the value to compare to
41 | * @param type of value
42 | * @return predicate
43 | */
44 | public static Predicate equalTo(T value) {
45 | return x -> Objects.equals(value, x);
46 | }
47 |
48 | /**
49 | * Predicate that inverts the result of target predicate.
50 | * @param predicate the predicate to invert
51 | * @param type of value
52 | * @return predicate
53 | */
54 | public static Predicate not(Predicate predicate) {
55 | return x -> !predicate.test(x);
56 | }
57 |
58 | /**
59 | * Predicate that checks if {@code !(value == x)}
60 | * @param value the value to compare to
61 | * @param type of value
62 | * @return predicate
63 | */
64 | public static Predicate not(T value) {
65 | return not(is(value));
66 | }
67 |
68 | /**
69 | * Predicate that checks if {@code !value.equalTo(x)}
70 | * @param value the value to compare to
71 | * @param type of value
72 | * @return predicate
73 | */
74 | public static Predicate notEqualTo(T value) {
75 | return not(equalTo(value));
76 | }
77 |
78 | /**
79 | * Predicate that checks if {@code x == null}
80 | * @param type of value
81 | * @return predicate
82 | */
83 | public static Predicate isNull() {
84 | return x -> x == null;
85 | }
86 |
87 | /**
88 | * Predicate that checks if {@code x != null}
89 | * @param type of value
90 | * @return predicate
91 | */
92 | public static Predicate notNull() {
93 | return not(isNull());
94 | }
95 |
96 | /**
97 | * Predicate that checks if {@code test} matches the result of {@code fn}
98 | * @param fn the fn that is applied to the element under test
99 | * @param test the predicate applied to the result of {@code fn}
100 | * @param source type
101 | * @param target type
102 | * @return predicate
103 | */
104 | public static Predicate having(Function fn, Predicate test) {
105 | Objects.requireNonNull(fn, "fn must be supplied");
106 | Objects.requireNonNull(test, "test must be supplied");
107 | return x -> test.test(fn.apply(x));
108 | }
109 |
110 | /**
111 | * Predicate that checks if {@code value} is equal to the result of {@code fn}
112 | * @param fn the fn that is applied to the element under test
113 | * @param value the value to compare to
114 | * @param