Add PredicateDecorator to provide consistent access to predicates

based on code from Brian Lloyd-Newberry


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131756 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2004-05-31 16:43:17 +00:00
parent 82db8c7195
commit 145b19acc4
12 changed files with 93 additions and 69 deletions

View File

@ -24,11 +24,11 @@ import org.apache.commons.collections.Predicate;
* Predicate implementation that returns true if all the predicates return true. * Predicate implementation that returns true if all the predicates return true.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.6 $ $Date: 2004/05/31 16:43:17 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class AllPredicate implements Predicate, Serializable { public final class AllPredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = -3094696765038308799L; static final long serialVersionUID = -3094696765038308799L;

View File

@ -23,11 +23,11 @@ import org.apache.commons.collections.Predicate;
* Predicate implementation that returns true if both the predicates return true. * Predicate implementation that returns true if both the predicates return true.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.6 $ $Date: 2004/05/31 16:43:17 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class AndPredicate implements Predicate, Serializable { public final class AndPredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = 4189014213763186912L; static final long serialVersionUID = 4189014213763186912L;
@ -76,23 +76,13 @@ public final class AndPredicate implements Predicate, Serializable {
} }
/** /**
* Gets the first predicate. * Gets the two predicates being decorated as an array.
* *
* @return the predicate * @return the predicates
* @since Commons Collections 3.1 * @since Commons Collections 3.1
*/ */
public Predicate getPredicate1() { public Predicate[] getPredicates() {
return iPredicate1; return new Predicate[] {iPredicate1, iPredicate2};
}
/**
* Gets the second predicate.
*
* @return the predicate
* @since Commons Collections 3.1
*/
public Predicate getPredicate2() {
return iPredicate2;
} }
} }

View File

@ -24,11 +24,11 @@ import org.apache.commons.collections.Predicate;
* Predicate implementation that returns true if any of the predicates return true. * Predicate implementation that returns true if any of the predicates return true.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.6 $ $Date: 2004/05/31 16:43:17 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class AnyPredicate implements Predicate, Serializable { public final class AnyPredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = 7429999530934647542L; static final long serialVersionUID = 7429999530934647542L;

View File

@ -24,11 +24,11 @@ import org.apache.commons.collections.Predicate;
* Predicate implementation that returns true if none of the predicates return true. * Predicate implementation that returns true if none of the predicates return true.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.6 $ $Date: 2004/05/31 16:43:17 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class NonePredicate implements Predicate, Serializable { public final class NonePredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = 2007613066565892961L; static final long serialVersionUID = 2007613066565892961L;

View File

@ -23,11 +23,11 @@ import org.apache.commons.collections.Predicate;
* Predicate implementation that returns the opposite of the decorated predicate. * Predicate implementation that returns the opposite of the decorated predicate.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.6 $ $Date: 2004/05/31 16:43:17 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class NotPredicate implements Predicate, Serializable { public final class NotPredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = -2654603322338049674L; static final long serialVersionUID = -2654603322338049674L;
@ -71,13 +71,13 @@ public final class NotPredicate implements Predicate, Serializable {
} }
/** /**
* Gets the predicate. * Gets the predicate being decorated.
* *
* @return the predicate * @return the predicate as the only element in an array
* @since Commons Collections 3.1 * @since Commons Collections 3.1
*/ */
public Predicate getPredicate() { public Predicate[] getPredicates() {
return iPredicate; return new Predicate[] {iPredicate};
} }
} }

View File

@ -24,11 +24,11 @@ import org.apache.commons.collections.Predicate;
* Predicate implementation that throws an exception if the input is null. * Predicate implementation that throws an exception if the input is null.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.7 $ $Date: 2004/05/31 16:43:17 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class NullIsExceptionPredicate implements Predicate, Serializable { public final class NullIsExceptionPredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = 3243449850504576071L; static final long serialVersionUID = 3243449850504576071L;
@ -77,13 +77,13 @@ public final class NullIsExceptionPredicate implements Predicate, Serializable {
} }
/** /**
* Gets the predicate. * Gets the predicate being decorated.
* *
* @return the predicate * @return the predicate as the only element in an array
* @since Commons Collections 3.1 * @since Commons Collections 3.1
*/ */
public Predicate getPredicate() { public Predicate[] getPredicates() {
return iPredicate; return new Predicate[] {iPredicate};
} }
} }

View File

@ -23,11 +23,11 @@ import org.apache.commons.collections.Predicate;
* Predicate implementation that returns false if the input is null. * Predicate implementation that returns false if the input is null.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.6 $ $Date: 2004/05/31 16:43:17 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class NullIsFalsePredicate implements Predicate, Serializable { public final class NullIsFalsePredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = -2997501534564735525L; static final long serialVersionUID = -2997501534564735525L;
@ -75,13 +75,13 @@ public final class NullIsFalsePredicate implements Predicate, Serializable {
} }
/** /**
* Gets the predicate. * Gets the predicate being decorated.
* *
* @return the predicate * @return the predicate as the only element in an array
* @since Commons Collections 3.1 * @since Commons Collections 3.1
*/ */
public Predicate getPredicate() { public Predicate[] getPredicates() {
return iPredicate; return new Predicate[] {iPredicate};
} }
} }

View File

@ -23,11 +23,11 @@ import org.apache.commons.collections.Predicate;
* Predicate implementation that returns true if the input is null. * Predicate implementation that returns true if the input is null.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.6 $ $Date: 2004/05/31 16:43:17 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class NullIsTruePredicate implements Predicate, Serializable { public final class NullIsTruePredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = -7625133768987126273L; static final long serialVersionUID = -7625133768987126273L;
@ -75,13 +75,13 @@ public final class NullIsTruePredicate implements Predicate, Serializable {
} }
/** /**
* Gets the predicate. * Gets the predicate being decorated.
* *
* @return the predicate * @return the predicate as the only element in an array
* @since Commons Collections 3.1 * @since Commons Collections 3.1
*/ */
public Predicate getPredicate() { public Predicate[] getPredicates() {
return iPredicate; return new Predicate[] {iPredicate};
} }
} }

View File

@ -24,11 +24,11 @@ import org.apache.commons.collections.Predicate;
* Predicate implementation that returns true if only one of the predicates return true. * Predicate implementation that returns true if only one of the predicates return true.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.6 $ $Date: 2004/05/31 16:43:17 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class OnePredicate implements Predicate, Serializable { public final class OnePredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = -8125389089924745785L; static final long serialVersionUID = -8125389089924745785L;

View File

@ -23,11 +23,11 @@ import org.apache.commons.collections.Predicate;
* Predicate implementation that returns true if either of the predicates return true. * Predicate implementation that returns true if either of the predicates return true.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.6 $ $Date: 2004/05/31 16:43:17 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class OrPredicate implements Predicate, Serializable { public final class OrPredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = -8791518325735182855L; static final long serialVersionUID = -8791518325735182855L;
@ -76,22 +76,13 @@ public final class OrPredicate implements Predicate, Serializable {
} }
/** /**
* Gets the first predicate. * Gets the two predicates being decorated as an array.
* *
* @return the predicate * @return the predicates
* @since Commons Collections 3.1 * @since Commons Collections 3.1
*/ */
public Predicate getPredicate1() { public Predicate[] getPredicates() {
return iPredicate1; return new Predicate[] {iPredicate1, iPredicate2};
}
/**
* Gets the second predicate.
* @return the predicate
* @since Commons Collections 3.1
*/
public Predicate getPredicate2() {
return iPredicate2;
} }
} }

View File

@ -0,0 +1,42 @@
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.collections.functors;
import org.apache.commons.collections.Predicate;
/**
* Defines a predicate that decorates one or more other predicates.
* <p>
* This interface enables tools to access the decorated predicates.
*
* @since Commons Collections 3.1
* @version $Revision: 1.1 $ $Date: 2004/05/31 16:43:17 $
*
* @author Stephen Colebourne
*/
public interface PredicateDecorator extends Predicate {
/**
* Gets the predicates being decorated as an array.
* <p>
* The array may be the internal data structure of the predicate and thus
* should not be altered.
*
* @return the predicates being decorated
*/
Predicate[] getPredicates();
}

View File

@ -25,11 +25,11 @@ import org.apache.commons.collections.Transformer;
* another <code>Predicate</code>. * another <code>Predicate</code>.
* *
* @since Commons Collections 3.1 * @since Commons Collections 3.1
* @version $Revision: 1.3 $ $Date: 2004/05/16 11:16:01 $ * @version $Revision: 1.4 $ $Date: 2004/05/31 16:43:17 $
* @author Alban Peignier * @author Alban Peignier
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class TransformedPredicate implements Predicate, Serializable { public final class TransformedPredicate implements Predicate, PredicateDecorator, Serializable {
/** Serial version UID */ /** Serial version UID */
static final long serialVersionUID = -5596090919668315834L; static final long serialVersionUID = -5596090919668315834L;
@ -82,12 +82,13 @@ public final class TransformedPredicate implements Predicate, Serializable {
} }
/** /**
* Gets the predicate in use. * Gets the predicate being decorated.
* *
* @return the predicate * @return the predicate as the only element in an array
* @since Commons Collections 3.1
*/ */
public Predicate getPredicate() { public Predicate[] getPredicates() {
return iPredicate; return new Predicate[] {iPredicate};
} }
/** /**