Author: tn
Date: Mon Jan 21 09:49:21 2013
New Revision: 1436241
URL: http://svn.apache.org/viewvc?rev=1436241&view=rev
Log:
Fix findbugs warning wrt exposure of internal representation: introduce a
common base class for quantification predicates and clone the internal
predicate array.
Added:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AbstractQuantifierPredicate.java
(with props)
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AllPredicate.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AnyPredicate.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/NonePredicate.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/OnePredicate.java
Added:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AbstractQuantifierPredicate.java
URL:
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AbstractQuantifierPredicate.java?rev=1436241&view=auto
==============================================================================
---
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AbstractQuantifierPredicate.java
(added)
+++
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AbstractQuantifierPredicate.java
Mon Jan 21 09:49:21 2013
@@ -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);
+ }
+
+}
Propchange:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AbstractQuantifierPredicate.java
------------------------------------------------------------------------------
svn:keywords = Id Revision
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AllPredicate.java
URL:
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AllPredicate.java?rev=1436241&r1=1436240&r2=1436241&view=diff
==============================================================================
---
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AllPredicate.java
(original)
+++
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AllPredicate.java
Mon Jan 21 09:49:21 2013
@@ -36,14 +36,11 @@ import org.apache.commons.collections.Pr
* @since 3.0
* @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 */
private static final long serialVersionUID = -3094696765038308799L;
- /** The array of predicates to call */
- private final Predicate<? super T>[] iPredicates;
-
/**
* Factory to create the predicate.
* <p>
@@ -98,8 +95,7 @@ public final class AllPredicate<T> imple
* @param predicates the predicates to check, not cloned, not null
*/
public AllPredicate(final Predicate<? super T> ... predicates) {
- super();
- iPredicates = predicates;
+ super(predicates);
}
/**
@@ -117,14 +113,4 @@ public final class AllPredicate<T> imple
return true;
}
- /**
- * Gets the predicates, do not modify the array.
- *
- * @return the predicates
- * @since 3.1
- */
- public Predicate<? super T>[] getPredicates() {
- return iPredicates;
- }
-
}
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AnyPredicate.java
URL:
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AnyPredicate.java?rev=1436241&r1=1436240&r2=1436241&view=diff
==============================================================================
---
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AnyPredicate.java
(original)
+++
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/AnyPredicate.java
Mon Jan 21 09:49:21 2013
@@ -32,14 +32,11 @@ import org.apache.commons.collections.Pr
* @since 3.0
* @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 */
private static final long serialVersionUID = 7429999530934647542L;
- /** The array of predicates to call */
- private final Predicate<? super T>[] iPredicates;
-
/**
* Factory to create the predicate.
* <p>
@@ -95,8 +92,7 @@ public final class AnyPredicate<T> imple
* @param predicates the predicates to check, not cloned, not null
*/
public AnyPredicate(final Predicate<? super T>[] predicates) {
- super();
- iPredicates = predicates;
+ super(predicates);
}
/**
@@ -114,14 +110,4 @@ public final class AnyPredicate<T> imple
return false;
}
- /**
- * Gets the predicates, do not modify the array.
- *
- * @return the predicates
- * @since 3.1
- */
- public Predicate<? super T>[] getPredicates() {
- return iPredicates;
- }
-
}
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/NonePredicate.java
URL:
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/NonePredicate.java?rev=1436241&r1=1436240&r2=1436241&view=diff
==============================================================================
---
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/NonePredicate.java
(original)
+++
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/NonePredicate.java
Mon Jan 21 09:49:21 2013
@@ -32,14 +32,11 @@ import org.apache.commons.collections.Pr
* @since 3.0
* @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 */
private static final long serialVersionUID = 2007613066565892961L;
- /** The array of predicates to call */
- private final Predicate<? super T>[] iPredicates;
-
/**
* Factory to create the predicate.
* <p>
@@ -85,8 +82,7 @@ public final class NonePredicate<T> impl
* @param predicates the predicates to check, not cloned, not null
*/
public NonePredicate(final Predicate<? super T>[] predicates) {
- super();
- iPredicates = predicates;
+ super(predicates);
}
/**
@@ -104,14 +100,4 @@ public final class NonePredicate<T> impl
return true;
}
- /**
- * Gets the predicates, do not modify the array.
- *
- * @return the predicates
- * @since 3.1
- */
- public Predicate<? super T>[] getPredicates() {
- return iPredicates;
- }
-
}
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/OnePredicate.java
URL:
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/OnePredicate.java?rev=1436241&r1=1436240&r2=1436241&view=diff
==============================================================================
---
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/OnePredicate.java
(original)
+++
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/OnePredicate.java
Mon Jan 21 09:49:21 2013
@@ -32,14 +32,11 @@ import org.apache.commons.collections.Pr
* @since 3.0
* @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 */
private static final long serialVersionUID = -8125389089924745785L;
- /** The array of predicates to call */
- private final Predicate<? super T>[] iPredicates;
-
/**
* Factory to create the predicate.
* <p>
@@ -85,8 +82,7 @@ public final class OnePredicate<T> imple
* @param predicates the predicates to check, not cloned, not null
*/
public OnePredicate(final Predicate<? super T>[] predicates) {
- super();
- iPredicates = predicates;
+ super(predicates);
}
/**
@@ -109,14 +105,4 @@ public final class OnePredicate<T> imple
return match;
}
- /**
- * Gets the predicates, do not modify the array.
- *
- * @return the predicates
- * @since 3.1
- */
- public Predicate<? super T>[] getPredicates() {
- return iPredicates;
- }
-
}