Fix findbugs warning wrt exposure of internal representation: introduce a common base class for quantification predicates and clone the internal predicate array.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1436241 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9d6a3eb828
commit
5954027e47
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You 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 java.io.Serializable;
|
||||||
|
|
||||||
|
import org.apache.commons.collections.Predicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for quantification predicates, e.g. All, Any, None.
|
||||||
|
*
|
||||||
|
* @since 4.0
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public abstract class AbstractQuantifierPredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
|
||||||
|
|
||||||
|
/** Serial version UID */
|
||||||
|
private static final long serialVersionUID = -3094696765038308799L;
|
||||||
|
|
||||||
|
/** The array of predicates to call */
|
||||||
|
protected final Predicate<? super T>[] iPredicates;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that performs no validation.
|
||||||
|
* Use <code>getInstance</code> if you want that.
|
||||||
|
*
|
||||||
|
* @param predicates the predicates to check, not cloned, not null
|
||||||
|
*/
|
||||||
|
public AbstractQuantifierPredicate(final Predicate<? super T> ... predicates) {
|
||||||
|
iPredicates = predicates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the predicates.
|
||||||
|
*
|
||||||
|
* @return a copy of the predicates
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
public Predicate<? super T>[] getPredicates() {
|
||||||
|
return FunctorUtils.copy(iPredicates);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -36,14 +36,11 @@ import org.apache.commons.collections.Predicate;
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public final class AllPredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
|
public final class AllPredicate<T> extends AbstractQuantifierPredicate<T> implements Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = -3094696765038308799L;
|
private static final long serialVersionUID = -3094696765038308799L;
|
||||||
|
|
||||||
/** The array of predicates to call */
|
|
||||||
private final Predicate<? super T>[] iPredicates;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory to create the predicate.
|
* Factory to create the predicate.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -98,8 +95,7 @@ public final class AllPredicate<T> implements Predicate<T>, PredicateDecorator<T
|
||||||
* @param predicates the predicates to check, not cloned, not null
|
* @param predicates the predicates to check, not cloned, not null
|
||||||
*/
|
*/
|
||||||
public AllPredicate(final Predicate<? super T> ... predicates) {
|
public AllPredicate(final Predicate<? super T> ... predicates) {
|
||||||
super();
|
super(predicates);
|
||||||
iPredicates = predicates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,14 +113,4 @@ public final class AllPredicate<T> implements Predicate<T>, PredicateDecorator<T
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the predicates, do not modify the array.
|
|
||||||
*
|
|
||||||
* @return the predicates
|
|
||||||
* @since 3.1
|
|
||||||
*/
|
|
||||||
public Predicate<? super T>[] getPredicates() {
|
|
||||||
return iPredicates;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,14 +32,11 @@ import org.apache.commons.collections.Predicate;
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public final class AnyPredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
|
public final class AnyPredicate<T> extends AbstractQuantifierPredicate<T> implements Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = 7429999530934647542L;
|
private static final long serialVersionUID = 7429999530934647542L;
|
||||||
|
|
||||||
/** The array of predicates to call */
|
|
||||||
private final Predicate<? super T>[] iPredicates;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory to create the predicate.
|
* Factory to create the predicate.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -95,8 +92,7 @@ public final class AnyPredicate<T> implements Predicate<T>, PredicateDecorator<T
|
||||||
* @param predicates the predicates to check, not cloned, not null
|
* @param predicates the predicates to check, not cloned, not null
|
||||||
*/
|
*/
|
||||||
public AnyPredicate(final Predicate<? super T>[] predicates) {
|
public AnyPredicate(final Predicate<? super T>[] predicates) {
|
||||||
super();
|
super(predicates);
|
||||||
iPredicates = predicates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,14 +110,4 @@ public final class AnyPredicate<T> implements Predicate<T>, PredicateDecorator<T
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the predicates, do not modify the array.
|
|
||||||
*
|
|
||||||
* @return the predicates
|
|
||||||
* @since 3.1
|
|
||||||
*/
|
|
||||||
public Predicate<? super T>[] getPredicates() {
|
|
||||||
return iPredicates;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,14 +32,11 @@ import org.apache.commons.collections.Predicate;
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public final class NonePredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
|
public final class NonePredicate<T> extends AbstractQuantifierPredicate<T> implements Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = 2007613066565892961L;
|
private static final long serialVersionUID = 2007613066565892961L;
|
||||||
|
|
||||||
/** The array of predicates to call */
|
|
||||||
private final Predicate<? super T>[] iPredicates;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory to create the predicate.
|
* Factory to create the predicate.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -85,8 +82,7 @@ public final class NonePredicate<T> implements Predicate<T>, PredicateDecorator<
|
||||||
* @param predicates the predicates to check, not cloned, not null
|
* @param predicates the predicates to check, not cloned, not null
|
||||||
*/
|
*/
|
||||||
public NonePredicate(final Predicate<? super T>[] predicates) {
|
public NonePredicate(final Predicate<? super T>[] predicates) {
|
||||||
super();
|
super(predicates);
|
||||||
iPredicates = predicates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,14 +100,4 @@ public final class NonePredicate<T> implements Predicate<T>, PredicateDecorator<
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the predicates, do not modify the array.
|
|
||||||
*
|
|
||||||
* @return the predicates
|
|
||||||
* @since 3.1
|
|
||||||
*/
|
|
||||||
public Predicate<? super T>[] getPredicates() {
|
|
||||||
return iPredicates;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,14 +32,11 @@ import org.apache.commons.collections.Predicate;
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public final class OnePredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
|
public final class OnePredicate<T> extends AbstractQuantifierPredicate<T> implements Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = -8125389089924745785L;
|
private static final long serialVersionUID = -8125389089924745785L;
|
||||||
|
|
||||||
/** The array of predicates to call */
|
|
||||||
private final Predicate<? super T>[] iPredicates;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory to create the predicate.
|
* Factory to create the predicate.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -85,8 +82,7 @@ public final class OnePredicate<T> implements Predicate<T>, PredicateDecorator<T
|
||||||
* @param predicates the predicates to check, not cloned, not null
|
* @param predicates the predicates to check, not cloned, not null
|
||||||
*/
|
*/
|
||||||
public OnePredicate(final Predicate<? super T>[] predicates) {
|
public OnePredicate(final Predicate<? super T>[] predicates) {
|
||||||
super();
|
super(predicates);
|
||||||
iPredicates = predicates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,14 +105,4 @@ public final class OnePredicate<T> implements Predicate<T>, PredicateDecorator<T
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the predicates, do not modify the array.
|
|
||||||
*
|
|
||||||
* @return the predicates
|
|
||||||
* @since 3.1
|
|
||||||
*/
|
|
||||||
public Predicate<? super T>[] getPredicates() {
|
|
||||||
return iPredicates;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue