| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| IsNotNull |
|
| 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>false</code> iff its argument | |
| 29 | * is <code>null</code>. | |
| 30 | * | |
| 31 | * @param <T> the argument type. | |
| 32 | * @version $Revision: 1160401 $ $Date: 2011-08-22 21:47:27 +0200 (Mon, 22 Aug 2011) $ | |
| 33 | * @author Rodney Waldhoff | |
| 34 | */ | |
| 35 | public final class IsNotNull<T> implements UnaryPredicate<T>, Serializable { | |
| 36 | ||
| 37 | // static attributes | |
| 38 | // ------------------------------------------------------------------------ | |
| 39 | /** | |
| 40 | * Basic IsNotNull instance. | |
| 41 | */ | |
| 42 | 2 | public static final IsNotNull<Object> INSTANCE = IsNotNull.<Object>instance(); |
| 43 | ||
| 44 | /** | |
| 45 | * Left-handed BinaryPredicate. | |
| 46 | */ | |
| 47 | 2 | public static final BinaryPredicate<Object, Object> LEFT = IsNotNull.<Object>left(); |
| 48 | ||
| 49 | /** | |
| 50 | * Right-handed BinaryPredicate. | |
| 51 | */ | |
| 52 | 2 | public static final BinaryPredicate<Object, Object> RIGHT = IsNotNull.<Object>right(); |
| 53 | ||
| 54 | /** | |
| 55 | * serialVersionUID declaration. | |
| 56 | */ | |
| 57 | private static final long serialVersionUID = -6856387958371590330L; | |
| 58 | ||
| 59 | // constructor | |
| 60 | // ------------------------------------------------------------------------ | |
| 61 | /** | |
| 62 | * Create a new IsNotNull. | |
| 63 | */ | |
| 64 | 26 | public IsNotNull() { |
| 65 | 26 | } |
| 66 | ||
| 67 | // predicate interface | |
| 68 | // ------------------------------------------------------------------------ | |
| 69 | /** | |
| 70 | * {@inheritDoc} | |
| 71 | */ | |
| 72 | public boolean test(Object obj) { | |
| 73 | 6 | return (null != obj); |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * {@inheritDoc} | |
| 78 | */ | |
| 79 | public boolean equals(Object that) { | |
| 80 | 24 | return that instanceof IsNotNull<?>; |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * {@inheritDoc} | |
| 85 | */ | |
| 86 | public int hashCode() { | |
| 87 | 24 | return "IsNotNull".hashCode(); |
| 88 | } | |
| 89 | ||
| 90 | /** | |
| 91 | * {@inheritDoc} | |
| 92 | */ | |
| 93 | public String toString() { | |
| 94 | 16 | return "IsNotNull"; |
| 95 | } | |
| 96 | ||
| 97 | // static methods | |
| 98 | // ------------------------------------------------------------------------ | |
| 99 | /** | |
| 100 | * Get an IsNotNull instance. | |
| 101 | * @param <T> the predicate argument type. | |
| 102 | * @return IsNotNull | |
| 103 | */ | |
| 104 | public static <T> IsNotNull<T> instance() { | |
| 105 | 8 | return new IsNotNull<T>(); |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * Get a BinaryPredicate that matches if the left argument is not null. | |
| 110 | * @param <A> the left {@code BinaryPredicate} argument type. | |
| 111 | * @return BinaryPredicate<A, Object> | |
| 112 | */ | |
| 113 | public static <A> BinaryPredicate<A, Object> left() { | |
| 114 | 2 | return IgnoreRightPredicate.adapt(new IsNotNull<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<Object, A> | |
| 121 | */ | |
| 122 | public static <A> BinaryPredicate<Object, A> right() { | |
| 123 | 2 | return IgnoreLeftPredicate.adapt(new IsNotNull<A>()); |
| 124 | } | |
| 125 | ||
| 126 | } |