| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Conditional |
|
| 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.composite; | |
| 18 | ||
| 19 | import org.apache.commons.functor.BinaryFunction; | |
| 20 | import org.apache.commons.functor.BinaryPredicate; | |
| 21 | import org.apache.commons.functor.BinaryProcedure; | |
| 22 | import org.apache.commons.functor.Function; | |
| 23 | import org.apache.commons.functor.Predicate; | |
| 24 | import org.apache.commons.functor.Procedure; | |
| 25 | import org.apache.commons.functor.UnaryFunction; | |
| 26 | import org.apache.commons.functor.UnaryPredicate; | |
| 27 | import org.apache.commons.functor.UnaryProcedure; | |
| 28 | ||
| 29 | /** | |
| 30 | * Utility methods for creating conditional functors. | |
| 31 | * @version $Revision: 1166380 $ $Date: 2011-09-07 22:18:14 +0200 (Wed, 07 Sep 2011) $ | |
| 32 | * @author Rodney Waldhoff | |
| 33 | */ | |
| 34 | public final class Conditional { | |
| 35 | ||
| 36 | // constructor - for beanish apis | |
| 37 | // ------------------------------------------------------------------------ | |
| 38 | ||
| 39 | /** | |
| 40 | * <p>{@code Conditional} instances should NOT be constructed in | |
| 41 | * standard programming. Instead, the methods of the class should be invoked | |
| 42 | * statically.</p> | |
| 43 | * | |
| 44 | * <p>This constructor is public to permit tools that require a JavaBean | |
| 45 | * instance to operate.</p> | |
| 46 | */ | |
| 47 | 2 | public Conditional() { } |
| 48 | ||
| 49 | // ------------------------------------------------------------------------ | |
| 50 | ||
| 51 | /** | |
| 52 | * Create a guarded Procedure. | |
| 53 | * @param q if | |
| 54 | * @param r then | |
| 55 | * @return Procedure | |
| 56 | */ | |
| 57 | public static Procedure procedure(Predicate q, Procedure r) { | |
| 58 | 0 | return new ConditionalProcedure(q, r); |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * Create a conditional Procedure. | |
| 63 | * @param q if | |
| 64 | * @param r then | |
| 65 | * @param s else | |
| 66 | * @return Procedure | |
| 67 | */ | |
| 68 | public static Procedure procedure(Predicate q, Procedure r, Procedure s) { | |
| 69 | 0 | return new ConditionalProcedure(q, r, s); |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * Create a conditional Function. | |
| 74 | * @param q if | |
| 75 | * @param r then | |
| 76 | * @param s else | |
| 77 | * @return Function<T> | |
| 78 | */ | |
| 79 | public static <T> Function<T> function(Predicate q, Function<? extends T> r, Function<? extends T> s) { | |
| 80 | 0 | return new ConditionalFunction<T>(q, r, s); |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * Create a conditional Predicate. | |
| 85 | * @param q if | |
| 86 | * @param r then | |
| 87 | * @param s else | |
| 88 | * @return Predicate | |
| 89 | */ | |
| 90 | public static Predicate predicate(Predicate q, Predicate r, Predicate s) { | |
| 91 | 0 | return new ConditionalPredicate(q, r, s); |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * Create a guarded UnaryProcedure. | |
| 96 | * @param q if | |
| 97 | * @param r then | |
| 98 | * @return UnaryProcedure<A> | |
| 99 | */ | |
| 100 | public static <A> UnaryProcedure<A> procedure(UnaryPredicate<? super A> q, UnaryProcedure<? super A> r) { | |
| 101 | 0 | return new ConditionalUnaryProcedure<A>(q, r); |
| 102 | } | |
| 103 | ||
| 104 | /** | |
| 105 | * Create a conditional UnaryProcedure. | |
| 106 | * @param q if | |
| 107 | * @param r then | |
| 108 | * @param s else | |
| 109 | * @return UnaryProcedure<A> | |
| 110 | */ | |
| 111 | public static <A> UnaryProcedure<A> procedure(UnaryPredicate<? super A> q, UnaryProcedure<? super A> r, | |
| 112 | UnaryProcedure<? super A> s) { | |
| 113 | 2 | return new ConditionalUnaryProcedure<A>(q, r, s); |
| 114 | } | |
| 115 | ||
| 116 | /** | |
| 117 | * Create a conditional UnaryFunction. | |
| 118 | * @param q if | |
| 119 | * @param r then | |
| 120 | * @param s else | |
| 121 | * @return UnaryFunction<A, T> | |
| 122 | */ | |
| 123 | public static <A, T> UnaryFunction<A, T> function(UnaryPredicate<? super A> q, | |
| 124 | UnaryFunction<? super A, ? extends T> r, UnaryFunction<? super A, ? extends T> s) { | |
| 125 | 2 | return new ConditionalUnaryFunction<A, T>(q, r, s); |
| 126 | } | |
| 127 | ||
| 128 | /** | |
| 129 | * Create a conditional UnaryPredicate. | |
| 130 | * @param q if | |
| 131 | * @param r then | |
| 132 | * @param s else | |
| 133 | * @return UnaryPredicate<A> | |
| 134 | */ | |
| 135 | public static <A> UnaryPredicate<A> predicate(UnaryPredicate<? super A> q, UnaryPredicate<? super A> r, | |
| 136 | UnaryPredicate<? super A> s) { | |
| 137 | 2 | return new ConditionalUnaryPredicate<A>(q, r, s); |
| 138 | } | |
| 139 | ||
| 140 | /** | |
| 141 | * Create a guarded BinaryProcedure. | |
| 142 | * @param q if | |
| 143 | * @param r then | |
| 144 | * @return BinaryProcedure<L, R> | |
| 145 | */ | |
| 146 | public static <L, R> BinaryProcedure<L, R> procedure(BinaryPredicate<? super L, ? super R> q, | |
| 147 | BinaryProcedure<? super L, ? super R> r) { | |
| 148 | 0 | return new ConditionalBinaryProcedure<L, R>(q, r); |
| 149 | } | |
| 150 | ||
| 151 | /** | |
| 152 | * Create a conditional BinaryProcedure. | |
| 153 | * @param q if | |
| 154 | * @param r then | |
| 155 | * @param s else | |
| 156 | * @return BinaryProcedure<L, R> | |
| 157 | */ | |
| 158 | public static <L, R> BinaryProcedure<L, R> procedure(BinaryPredicate<? super L, ? super R> q, | |
| 159 | BinaryProcedure<? super L, ? super R> r, BinaryProcedure<? super L, ? super R> s) { | |
| 160 | 2 | return new ConditionalBinaryProcedure<L, R>(q, r, s); |
| 161 | } | |
| 162 | ||
| 163 | /** | |
| 164 | * Create a conditional BinaryFunction. | |
| 165 | * @param q if | |
| 166 | * @param r then | |
| 167 | * @param s else | |
| 168 | * @return BinaryFunction<L, R, T> | |
| 169 | */ | |
| 170 | public static <L, R, T> BinaryFunction<L, R, T> function(BinaryPredicate<? super L, ? super R> q, | |
| 171 | BinaryFunction<? super L, ? super R, ? extends T> r, BinaryFunction<? super L, ? super R, ? extends T> s) { | |
| 172 | 6 | return new ConditionalBinaryFunction<L, R, T>(q, r, s); |
| 173 | } | |
| 174 | ||
| 175 | /** | |
| 176 | * Create a conditional BinaryPredicate. | |
| 177 | * @param q if | |
| 178 | * @param r then | |
| 179 | * @param s else | |
| 180 | * @return BinaryPredicate<L, R> | |
| 181 | */ | |
| 182 | public static <L, R> BinaryPredicate<L, R> predicate(BinaryPredicate<? super L, ? super R> q, | |
| 183 | BinaryPredicate<? super L, ? super R> r, BinaryPredicate<? super L, ? super R> s) { | |
| 184 | 2 | return new ConditionalBinaryPredicate<L, R>(q, r, s); |
| 185 | } | |
| 186 | ||
| 187 | } |