Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IsNull |
|
| 1.0;1 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | package org.apache.commons.functor.core; | |
18 | ||
19 | import java.io.Serializable; | |
20 | ||
21 | import org.apache.commons.functor.BinaryPredicate; | |
22 | import org.apache.commons.functor.UnaryPredicate; | |
23 | import org.apache.commons.functor.adapter.IgnoreLeftPredicate; | |
24 | import org.apache.commons.functor.adapter.IgnoreRightPredicate; | |
25 | ||
26 | /** | |
27 | * {@link #test Tests} | |
28 | * <code>true</code> iff its argument | |
29 | * is <code>null</code>. | |
30 | * | |
31 | * @param <A> the argument type. | |
32 | * @version $Revision: 1160407 $ $Date: 2011-08-22 22:03:21 +0200 (Mon, 22 Aug 2011) $ | |
33 | * @author Rodney Waldhoff | |
34 | */ | |
35 | public final class IsNull<A> implements UnaryPredicate<A>, Serializable { | |
36 | ||
37 | // static attributes | |
38 | // ------------------------------------------------------------------------ | |
39 | /** | |
40 | * Basic IsNull instance. | |
41 | */ | |
42 | 2 | public static final IsNull<Object> INSTANCE = IsNull.<Object>instance(); |
43 | ||
44 | /** | |
45 | * Left-handed BinaryPredicate. | |
46 | */ | |
47 | 2 | public static final BinaryPredicate<Object, Object> LEFT = IsNull.<Object>left(); |
48 | ||
49 | /** | |
50 | * Right-handed BinaryPredicate. | |
51 | */ | |
52 | 2 | public static final BinaryPredicate<Object, Object> RIGHT = IsNull.<Object>right(); |
53 | ||
54 | /** | |
55 | * serialVersionUID declaration. | |
56 | */ | |
57 | private static final long serialVersionUID = 6001380107746171952L; | |
58 | ||
59 | // constructor | |
60 | // ------------------------------------------------------------------------ | |
61 | /** | |
62 | * Create a new IsNull. | |
63 | */ | |
64 | 44 | public IsNull() { |
65 | 44 | } |
66 | ||
67 | // predicate interface | |
68 | // ------------------------------------------------------------------------ | |
69 | /** | |
70 | * {@inheritDoc} | |
71 | */ | |
72 | public boolean test(A obj) { | |
73 | 110 | return (null == obj); |
74 | } | |
75 | ||
76 | /** | |
77 | * {@inheritDoc} | |
78 | */ | |
79 | public boolean equals(Object that) { | |
80 | 24 | return that instanceof IsNull<?>; |
81 | } | |
82 | ||
83 | /** | |
84 | * {@inheritDoc} | |
85 | */ | |
86 | public int hashCode() { | |
87 | 24 | return "IsNull".hashCode(); |
88 | } | |
89 | ||
90 | /** | |
91 | * {@inheritDoc} | |
92 | */ | |
93 | public String toString() { | |
94 | 16 | return "IsNull"; |
95 | } | |
96 | ||
97 | // static methods | |
98 | // ------------------------------------------------------------------------ | |
99 | /** | |
100 | * Get an IsNull instance. | |
101 | * @param <T> the predicate argument type. | |
102 | * @return IsNull | |
103 | */ | |
104 | public static <T> IsNull<T> instance() { | |
105 | 14 | return new IsNull<T>(); |
106 | } | |
107 | ||
108 | /** | |
109 | * Get a BinaryPredicate that matches if the left argument is null. | |
110 | * @param <A> the left {@code BinaryPredicate} argument type. | |
111 | * @return BinaryPredicate | |
112 | */ | |
113 | public static <A> BinaryPredicate<A, Object> left() { | |
114 | 10 | return IgnoreRightPredicate.adapt(new IsNull<A>()); |
115 | } | |
116 | ||
117 | /** | |
118 | * Get a BinaryPredicate that matches if the right argument is null. | |
119 | * @param <A> the right {@code BinaryPredicate} argument type. | |
120 | * @return BinaryPredicate | |
121 | */ | |
122 | public static <A> BinaryPredicate<Object, A> right() { | |
123 | 6 | return IgnoreLeftPredicate.adapt(new IsNull<A>()); |
124 | } | |
125 | ||
126 | } |