| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| UnaryConditions |
|
| 0.0;0 | ||||
| UnaryConditions$1 |
|
| 0.0;0 |
| 1 | /* | |
| 2 | Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. | |
| 3 | Licensed under the Academic Free License version 3.0 | |
| 4 | */ | |
| 5 | ||
| 6 | package jaggregate.internal; | |
| 7 | ||
| 8 | import jaggregate.UnaryCondition; | |
| 9 | import static jaggregate.internal.ArgumentChecks.*; | |
| 10 | ||
| 11 | /** | |
| 12 | * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a> | |
| 13 | * @version $Id: UnaryConditions.java,v 1.2 2008/10/03 19:01:23 pholser Exp $ | |
| 14 | */ | |
| 15 | public class UnaryConditions { | |
| 16 | /** | |
| 17 | * Discourages instantiation. | |
| 18 | * | |
| 19 | * @throws UnsupportedOperationException always | |
| 20 | */ | |
| 21 | 1 | protected UnaryConditions() { |
| 22 | 1 | throw new UnsupportedOperationException(); |
| 23 | } | |
| 24 | ||
| 25 | /** | |
| 26 | * Answers a predicate that represents the logical <dfn>inverse</dfn> of the given | |
| 27 | * predicate; wherever the given predicate's {@link UnaryCondition#matches(Object) | |
| 28 | * matches} method would answer {@code true}, the inverse answers {@code false}; | |
| 29 | * and vice versa. | |
| 30 | * | |
| 31 | * @param <T> constraint on the types accepted by the condition | |
| 32 | * @param condition the condition to invert | |
| 33 | * @return the inverse of {@code condition} | |
| 34 | * @throws NullPointerException if {@code condition} is {@code null} | |
| 35 | */ | |
| 36 | public static <T> UnaryCondition<T> not( final UnaryCondition<T> condition ) { | |
| 37 | 8 | ensureNotNull( condition, DISCRIMINATOR ); |
| 38 | ||
| 39 | 6 | return new UnaryCondition<T>() { |
| 40 | 6 | public boolean matches( T target ) { |
| 41 | 10 | return !condition.matches( target ); |
| 42 | } | |
| 43 | }; | |
| 44 | } | |
| 45 | } |