Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 59136200CC5 for ; Tue, 11 Jul 2017 19:54:59 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 57A2E166A67; Tue, 11 Jul 2017 17:54:59 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 078881669D6 for ; Tue, 11 Jul 2017 19:54:56 +0200 (CEST) Received: (qmail 3812 invoked by uid 500); 11 Jul 2017 17:54:50 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 2017 invoked by uid 99); 11 Jul 2017 17:54:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Jul 2017 17:54:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 56CADE96B1; Tue, 11 Jul 2017 17:54:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chtompki@apache.org To: commits@commons.apache.org Date: Tue, 11 Jul 2017 17:55:12 -0000 Message-Id: In-Reply-To: <73d6ee8e3b69428ca7266b5410a6494f@git.apache.org> References: <73d6ee8e3b69428ca7266b5410a6494f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [27/77] [abbrv] commons-collections git commit: finish generics (minus one class) archived-at: Tue, 11 Jul 2017 17:54:59 -0000 http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/FunctorUtils.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/FunctorUtils.java b/src/java/org/apache/commons/collections/functors/FunctorUtils.java index d52ba01..3585558 100644 --- a/src/java/org/apache/commons/collections/functors/FunctorUtils.java +++ b/src/java/org/apache/commons/collections/functors/FunctorUtils.java @@ -5,9 +5,9 @@ * 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. @@ -24,7 +24,7 @@ import org.apache.commons.collections.Transformer; /** * Internal utilities for functors. - * + * * @since Commons Collections 3.0 * @version $Revision$ $Date$ * @@ -32,38 +32,38 @@ import org.apache.commons.collections.Transformer; * @author Matt Benson */ class FunctorUtils { - + /** * Restricted constructor. */ private FunctorUtils() { super(); } - + /** * Clone the predicates to ensure that the internal reference can't be messed with. * Due to the {@link Predicate#evaluate(T)} method, Predicate is - * able to be coerced to Predicate without casting issues. - * + * able to be coerced to Predicate without casting issues. + * * @param predicates the predicates to copy * @return the cloned predicates */ @SuppressWarnings("unchecked") - static Predicate[] copy(Predicate[] predicates) { + static Predicate[] copy(Predicate[] predicates) { if (predicates == null) { return null; } - return predicates.clone(); + return (Predicate[]) predicates.clone(); } - + /** * A very simple method that coerces Predicate to Predicate. * Due to the {@link Predicate#evaluate(T)} method, Predicate is - * able to be coerced to Predicate without casting issues. + * able to be coerced to Predicate without casting issues. *

This method exists * simply as centralised documentation and atomic unchecked warning * suppression. - * + * * @param the type of object the returned predicate should "accept" * @param predicate the predicate to coerce. * @return the coerced predicate. @@ -72,10 +72,10 @@ class FunctorUtils { static Predicate coerce(Predicate predicate){ return (Predicate) predicate; } - + /** * Validate the predicates to ensure that all is well. - * + * * @param predicates the predicates to validate */ static void validate(Predicate[] predicates) { @@ -88,22 +88,22 @@ class FunctorUtils { } } } - + /** * Validate the predicates to ensure that all is well. - * + * * @param predicates the predicates to validate * @return predicate array */ @SuppressWarnings("unchecked") - static Predicate[] validate(Collection> predicates) { + static Predicate[] validate(Collection> predicates) { if (predicates == null) { throw new IllegalArgumentException("The predicate collection must not be null"); } // convert to array like this to guarantee iterator() ordering - Predicate[] preds = new Predicate[predicates.size()]; + Predicate[] preds = new Predicate[predicates.size()]; int i = 0; - for (Predicate predicate : predicates) { + for (Predicate predicate : predicates) { preds[i] = predicate; if (preds[i] == null) { throw new IllegalArgumentException("The predicate collection must not contain a null predicate, index " + i + " was null"); @@ -112,26 +112,27 @@ class FunctorUtils { } return preds; } - + /** * Clone the closures to ensure that the internal reference can't be messed with. - * + * * @param closures the closures to copy * @return the cloned closures */ - static Closure[] copy(Closure[] closures) { + @SuppressWarnings("unchecked") + static Closure[] copy(Closure[] closures) { if (closures == null) { return null; } - return (Closure[]) closures.clone(); + return (Closure[]) closures.clone(); } - + /** * Validate the closures to ensure that all is well. - * + * * @param closures the closures to validate */ - static void validate(Closure[] closures) { + static void validate(Closure[] closures) { if (closures == null) { throw new IllegalArgumentException("The closure array must not be null"); } @@ -143,24 +144,40 @@ class FunctorUtils { } /** + * A very simple method that coerces Closure to Closure. + *

This method exists + * simply as centralised documentation and atomic unchecked warning + * suppression. + * + * @param the type of object the returned closure should "accept" + * @param closure the closure to coerce. + * @return the coerced closure. + */ + @SuppressWarnings("unchecked") + static Closure coerce(Closure closure){ + return (Closure) closure; + } + + /** * Copy method - * + * * @param transformers the transformers to copy * @return a clone of the transformers */ - static Transformer[] copy(Transformer[] transformers) { + @SuppressWarnings("unchecked") + static Transformer[] copy(Transformer[] transformers) { if (transformers == null) { return null; } - return (Transformer[]) transformers.clone(); + return (Transformer[]) transformers.clone(); } - + /** * Validate method - * + * * @param transformers the transformers to validate */ - static void validate(Transformer[] transformers) { + static void validate(Transformer[] transformers) { if (transformers == null) { throw new IllegalArgumentException("The transformer array must not be null"); } @@ -172,4 +189,19 @@ class FunctorUtils { } } + /** + * A very simple method that coerces Transformer to Transformer. + *

This method exists + * simply as centralised documentation and atomic unchecked warning + * suppression. + * + * @param the type of object the returned transformer should "accept" + * @param transformer the transformer to coerce. + * @return the coerced transformer. + */ + @SuppressWarnings("unchecked") + static Transformer coerce(Transformer transformer) { + return (Transformer) transformer; + } + } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/IdentityPredicate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/IdentityPredicate.java b/src/java/org/apache/commons/collections/functors/IdentityPredicate.java index 5175a15..5768259 100644 --- a/src/java/org/apache/commons/collections/functors/IdentityPredicate.java +++ b/src/java/org/apache/commons/collections/functors/IdentityPredicate.java @@ -5,9 +5,9 @@ * 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. @@ -23,42 +23,41 @@ import org.apache.commons.collections.Predicate; /** * Predicate implementation that returns true if the input is the same object * as the one stored in this predicate. - * + * * @since Commons Collections 3.0 * @version $Revision$ $Date$ * * @author Stephen Colebourne */ -public final class IdentityPredicate implements Predicate, Serializable { +public final class IdentityPredicate implements Predicate, Serializable { /** Serial version UID */ private static final long serialVersionUID = -89901658494523293L; - /** The value to compare to */ - private final Object iValue; - + private final T iValue; + /** * Factory to create the identity predicate. - * + * * @param object the object to compare to * @return the predicate * @throws IllegalArgumentException if the predicate is null */ - public static Predicate getInstance(Object object) { + public static Predicate getInstance(T object) { if (object == null) { - return NullPredicate.INSTANCE; + return NullPredicate.nullPredicate(); } - return new IdentityPredicate(object); + return new IdentityPredicate(object); } /** * Constructor that performs no validation. * Use getInstance if you want that. - * + * * @param object the object to compare to */ - public IdentityPredicate(Object object) { + public IdentityPredicate(T object) { super(); iValue = object; } @@ -66,21 +65,21 @@ public final class IdentityPredicate implements Predicate, Serializable { /** * Evaluates the predicate returning true if the input object is identical to * the stored object. - * + * * @param object the input object * @return true if input is the same object as the stored value */ - public boolean evaluate(Object object) { + public boolean evaluate(T object) { return (iValue == object); } /** * Gets the value. - * + * * @return the value * @since Commons Collections 3.1 */ - public Object getValue() { + public T getValue() { return iValue; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/IfClosure.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/IfClosure.java b/src/java/org/apache/commons/collections/functors/IfClosure.java index 0f49a39..151874a 100644 --- a/src/java/org/apache/commons/collections/functors/IfClosure.java +++ b/src/java/org/apache/commons/collections/functors/IfClosure.java @@ -31,17 +31,17 @@ import org.apache.commons.collections.Predicate; * @author Stephen Colebourne * @author Matt Benson */ -public class IfClosure implements Closure, Serializable { +public class IfClosure implements Closure, Serializable { /** Serial version UID */ private static final long serialVersionUID = 3518477308466486130L; /** The test */ - private final Predicate iPredicate; + private final Predicate iPredicate; /** The closure to use if true */ - private final Closure iTrueClosure; + private final Closure iTrueClosure; /** The closure to use if false */ - private final Closure iFalseClosure; + private final Closure iFalseClosure; /** * Factory method that performs validation. @@ -55,8 +55,8 @@ public class IfClosure implements Closure, Serializable { * @throws IllegalArgumentException if either argument is null * @since Commons Collections 3.2 */ - public static Closure getInstance(Predicate predicate, Closure trueClosure) { - return getInstance(predicate, trueClosure, NOPClosure.INSTANCE); + public static Closure getInstance(Predicate predicate, Closure trueClosure) { + return IfClosure.getInstance(predicate, trueClosure, NOPClosure.getInstance()); } /** @@ -68,14 +68,14 @@ public class IfClosure implements Closure, Serializable { * @return the if closure * @throws IllegalArgumentException if any argument is null */ - public static Closure getInstance(Predicate predicate, Closure trueClosure, Closure falseClosure) { + public static Closure getInstance(Predicate predicate, Closure trueClosure, Closure falseClosure) { if (predicate == null) { throw new IllegalArgumentException("Predicate must not be null"); } if (trueClosure == null || falseClosure == null) { throw new IllegalArgumentException("Closures must not be null"); } - return new IfClosure(predicate, trueClosure, falseClosure); + return new IfClosure(predicate, trueClosure, falseClosure); } /** @@ -89,7 +89,7 @@ public class IfClosure implements Closure, Serializable { * @param trueClosure closure used if true, not null * @since Commons Collections 3.2 */ - public IfClosure(Predicate predicate, Closure trueClosure) { + public IfClosure(Predicate predicate, Closure trueClosure) { this(predicate, trueClosure, NOPClosure.INSTANCE); } @@ -101,7 +101,7 @@ public class IfClosure implements Closure, Serializable { * @param trueClosure closure used if true, not null * @param falseClosure closure used if false, not null */ - public IfClosure(Predicate predicate, Closure trueClosure, Closure falseClosure) { + public IfClosure(Predicate predicate, Closure trueClosure, Closure falseClosure) { super(); iPredicate = predicate; iTrueClosure = trueClosure; @@ -113,8 +113,8 @@ public class IfClosure implements Closure, Serializable { * * @param input the input object */ - public void execute(Object input) { - if (iPredicate.evaluate(input) == true) { + public void execute(E input) { + if (iPredicate.evaluate(input)) { iTrueClosure.execute(input); } else { iFalseClosure.execute(input); @@ -127,7 +127,7 @@ public class IfClosure implements Closure, Serializable { * @return the predicate * @since Commons Collections 3.1 */ - public Predicate getPredicate() { + public Predicate getPredicate() { return iPredicate; } @@ -137,7 +137,7 @@ public class IfClosure implements Closure, Serializable { * @return the closure * @since Commons Collections 3.1 */ - public Closure getTrueClosure() { + public Closure getTrueClosure() { return iTrueClosure; } @@ -147,7 +147,7 @@ public class IfClosure implements Closure, Serializable { * @return the closure * @since Commons Collections 3.1 */ - public Closure getFalseClosure() { + public Closure getFalseClosure() { return iFalseClosure; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java b/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java index d97971e..58fbe86 100644 --- a/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java +++ b/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java @@ -5,9 +5,9 @@ * 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. @@ -23,28 +23,28 @@ import org.apache.commons.collections.Predicate; /** * Predicate implementation that returns true if the input is an instanceof * the type stored in this predicate. - * + * * @since Commons Collections 3.0 * @version $Revision$ $Date$ * * @author Stephen Colebourne */ -public final class InstanceofPredicate implements Predicate, Serializable { +public final class InstanceofPredicate implements Predicate, Serializable { /** Serial version UID */ private static final long serialVersionUID = -6682656911025165584L; /** The type to compare to */ - private final Class iType; - + private final Class iType; + /** * Factory to create the identity predicate. - * + * * @param type the type to check for, may not be null * @return the predicate * @throws IllegalArgumentException if the class is null */ - public static Predicate getInstance(Class type) { + public static Predicate getInstance(Class type) { if (type == null) { throw new IllegalArgumentException("The type to check instanceof must not be null"); } @@ -54,17 +54,17 @@ public final class InstanceofPredicate implements Predicate, Serializable { /** * Constructor that performs no validation. * Use getInstance if you want that. - * + * * @param type the type to check for */ - public InstanceofPredicate(Class type) { + public InstanceofPredicate(Class type) { super(); iType = type; } /** * Evaluates the predicate returning true if the input object is of the correct type. - * + * * @param object the input object * @return true if input is of stored type */ @@ -74,11 +74,11 @@ public final class InstanceofPredicate implements Predicate, Serializable { /** * Gets the type to compare to. - * + * * @return the type * @since Commons Collections 3.1 */ - public Class getType() { + public Class getType() { return iType; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/InstantiateFactory.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/InstantiateFactory.java b/src/java/org/apache/commons/collections/functors/InstantiateFactory.java index f6e11df..a09c580 100644 --- a/src/java/org/apache/commons/collections/functors/InstantiateFactory.java +++ b/src/java/org/apache/commons/collections/functors/InstantiateFactory.java @@ -39,7 +39,7 @@ public class InstantiateFactory implements Factory, Serializable { /** The class to create */ private final Class iClassToInstantiate; /** The constructor parameter types */ - private final Class[] iParamTypes; + private final Class[] iParamTypes; /** The constructor arguments */ private final Object[] iArgs; /** The constructor */ @@ -53,7 +53,7 @@ public class InstantiateFactory implements Factory, Serializable { * @param args the constructor arguments * @return a new instantiate factory */ - public static Factory getInstance(Class classToInstantiate, Class[] paramTypes, Object[] args) { + public static Factory getInstance(Class classToInstantiate, Class[] paramTypes, Object[] args) { if (classToInstantiate == null) { throw new IllegalArgumentException("Class to instantiate must not be null"); } @@ -93,7 +93,7 @@ public class InstantiateFactory implements Factory, Serializable { * @param paramTypes the constructor parameter types, not cloned * @param args the constructor arguments, not cloned */ - public InstantiateFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) { + public InstantiateFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) { super(); iClassToInstantiate = classToInstantiate; iParamTypes = paramTypes; @@ -126,7 +126,6 @@ public class InstantiateFactory implements Factory, Serializable { try { return iConstructor.newInstance(iArgs); - } catch (InstantiationException ex) { throw new FunctorException("InstantiateFactory: InstantiationException", ex); } catch (IllegalAccessException ex) { http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java b/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java index 61af4a8..ab1d098 100644 --- a/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java +++ b/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java @@ -5,9 +5,9 @@ * 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. @@ -25,33 +25,42 @@ import org.apache.commons.collections.Transformer; /** * Transformer implementation that creates a new object instance by reflection. - * + * * @since Commons Collections 3.0 * @version $Revision$ $Date$ * * @author Stephen Colebourne */ -public class InstantiateTransformer implements Transformer, Serializable { +public class InstantiateTransformer implements Transformer, T>, Serializable { /** The serial version */ private static final long serialVersionUID = 3786388740793356347L; - + /** Singleton instance that uses the no arg constructor */ - public static final Transformer NO_ARG_INSTANCE = new InstantiateTransformer(); + public static final Transformer, ?> NO_ARG_INSTANCE = new InstantiateTransformer(); /** The constructor parameter types */ - private final Class[] iParamTypes; + private final Class[] iParamTypes; /** The constructor arguments */ private final Object[] iArgs; /** + * Get a typed no-arg instance. + * @param + * @return Transformer, T> + */ + public static Transformer, T> getInstance() { + return new InstantiateTransformer(); + } + + /** * Transformer method that performs validation. - * + * * @param paramTypes the constructor parameter types * @param args the constructor arguments * @return an instantiate transformer */ - public static Transformer getInstance(Class[] paramTypes, Object[] args) { + public static Transformer, T> getInstance(Class[] paramTypes, Object[] args) { if (((paramTypes == null) && (args != null)) || ((paramTypes != null) && (args == null)) || ((paramTypes != null) && (args != null) && (paramTypes.length != args.length))) { @@ -59,12 +68,11 @@ public class InstantiateTransformer implements Transformer, Serializable { } if (paramTypes == null || paramTypes.length == 0) { - return NO_ARG_INSTANCE; - } else { - paramTypes = (Class[]) paramTypes.clone(); - args = (Object[]) args.clone(); + return new InstantiateTransformer(); } - return new InstantiateTransformer(paramTypes, args); + paramTypes = (Class[]) paramTypes.clone(); + args = (Object[]) args.clone(); + return new InstantiateTransformer(paramTypes, args); } /** @@ -79,11 +87,11 @@ public class InstantiateTransformer implements Transformer, Serializable { /** * Constructor that performs no validation. * Use getInstance if you want that. - * + * * @param paramTypes the constructor parameter types, not cloned * @param args the constructor arguments, not cloned */ - public InstantiateTransformer(Class[] paramTypes, Object[] args) { + public InstantiateTransformer(Class[] paramTypes, Object[] args) { super(); iParamTypes = paramTypes; iArgs = args; @@ -91,20 +99,19 @@ public class InstantiateTransformer implements Transformer, Serializable { /** * Transforms the input Class object to a result by instantiation. - * + * * @param input the input object to transform * @return the transformed result */ - public Object transform(Object input) { + public T transform(Class input) { try { if (input instanceof Class == false) { throw new FunctorException( "InstantiateTransformer: Input object was not an instanceof Class, it was a " + (input == null ? "null object" : input.getClass().getName())); } - Constructor con = ((Class) input).getConstructor(iParamTypes); + Constructor con = input.getConstructor(iParamTypes); return con.newInstance(iArgs); - } catch (NoSuchMethodException ex) { throw new FunctorException("InstantiateTransformer: The constructor must exist and be public "); } catch (InstantiationException ex) { http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/InvokerTransformer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/InvokerTransformer.java b/src/java/org/apache/commons/collections/functors/InvokerTransformer.java index fdb4502..0ab3dbb 100644 --- a/src/java/org/apache/commons/collections/functors/InvokerTransformer.java +++ b/src/java/org/apache/commons/collections/functors/InvokerTransformer.java @@ -31,7 +31,7 @@ import org.apache.commons.collections.Transformer; * * @author Stephen Colebourne */ -public class InvokerTransformer implements Transformer, Serializable { +public class InvokerTransformer implements Transformer, Serializable { /** The serial version */ private static final long serialVersionUID = -8653385846894047688L; @@ -39,7 +39,7 @@ public class InvokerTransformer implements Transformer, Serializable { /** The method name to call */ private final String iMethodName; /** The array of reflection parameter types */ - private final Class[] iParamTypes; + private final Class[] iParamTypes; /** The array of reflection arguments */ private final Object[] iArgs; @@ -50,11 +50,11 @@ public class InvokerTransformer implements Transformer, Serializable { * @return an invoker transformer * @since Commons Collections 3.1 */ - public static Transformer getInstance(String methodName) { + public static Transformer getInstance(String methodName) { if (methodName == null) { throw new IllegalArgumentException("The method to invoke must not be null"); } - return new InvokerTransformer(methodName); + return new InvokerTransformer(methodName); } /** @@ -65,7 +65,7 @@ public class InvokerTransformer implements Transformer, Serializable { * @param args the arguments to pass to the method * @return an invoker transformer */ - public static Transformer getInstance(String methodName, Class[] paramTypes, Object[] args) { + public static Transformer getInstance(String methodName, Class[] paramTypes, Object[] args) { if (methodName == null) { throw new IllegalArgumentException("The method to invoke must not be null"); } @@ -75,11 +75,11 @@ public class InvokerTransformer implements Transformer, Serializable { throw new IllegalArgumentException("The parameter types must match the arguments"); } if (paramTypes == null || paramTypes.length == 0) { - return new InvokerTransformer(methodName); + return new InvokerTransformer(methodName); } else { paramTypes = (Class[]) paramTypes.clone(); args = (Object[]) args.clone(); - return new InvokerTransformer(methodName, paramTypes, args); + return new InvokerTransformer(methodName, paramTypes, args); } } @@ -103,7 +103,7 @@ public class InvokerTransformer implements Transformer, Serializable { * @param paramTypes the constructor parameter types, not cloned * @param args the constructor arguments, not cloned */ - public InvokerTransformer(String methodName, Class[] paramTypes, Object[] args) { + public InvokerTransformer(String methodName, Class[] paramTypes, Object[] args) { super(); iMethodName = methodName; iParamTypes = paramTypes; @@ -116,15 +116,15 @@ public class InvokerTransformer implements Transformer, Serializable { * @param input the input object to transform * @return the transformed result, null if null input */ - public Object transform(Object input) { + @SuppressWarnings("unchecked") + public O transform(Object input) { if (input == null) { return null; } try { - Class cls = input.getClass(); + Class cls = input.getClass(); Method method = cls.getMethod(iMethodName, iParamTypes); - return method.invoke(input, iArgs); - + return (O) method.invoke(input, iArgs); } catch (NoSuchMethodException ex) { throw new FunctorException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.getClass() + "' does not exist"); } catch (IllegalAccessException ex) { http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/MapTransformer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/MapTransformer.java b/src/java/org/apache/commons/collections/functors/MapTransformer.java index 573762b..2bdaa98 100644 --- a/src/java/org/apache/commons/collections/functors/MapTransformer.java +++ b/src/java/org/apache/commons/collections/functors/MapTransformer.java @@ -5,9 +5,9 @@ * 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. @@ -24,63 +24,63 @@ import org.apache.commons.collections.Transformer; /** * Transformer implementation that returns the value held in a specified map * using the input parameter as a key. - * + * * @since Commons Collections 3.0 * @version $Revision$ $Date$ * * @author Stephen Colebourne */ -public final class MapTransformer implements Transformer, Serializable { +public final class MapTransformer implements Transformer, Serializable { /** Serial version UID */ private static final long serialVersionUID = 862391807045468939L; - + /** The map of data to lookup in */ - private final Map iMap; + private final Map iMap; /** * Factory to create the transformer. *

* If the map is null, a transformer that always returns null is returned. - * + * * @param map the map, not cloned * @return the transformer */ - public static Transformer getInstance(Map map) { + public static Transformer getInstance(Map map) { if (map == null) { - return ConstantTransformer.NULL_INSTANCE; + return ConstantTransformer.getNullInstance(); } - return new MapTransformer(map); + return new MapTransformer(map); } /** * Constructor that performs no validation. * Use getInstance if you want that. - * + * * @param map the map to use for lookup, not cloned */ - private MapTransformer(Map map) { + private MapTransformer(Map map) { super(); iMap = map; } /** * Transforms the input to result by looking it up in a Map. - * + * * @param input the input object to transform * @return the transformed result */ - public Object transform(Object input) { + public O transform(I input) { return iMap.get(input); } /** * Gets the map to lookup in. - * + * * @return the map * @since Commons Collections 3.1 */ - public Map getMap() { + public Map getMap() { return iMap; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NOPClosure.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/NOPClosure.java b/src/java/org/apache/commons/collections/functors/NOPClosure.java index 3bfee9e..3fa08c2 100644 --- a/src/java/org/apache/commons/collections/functors/NOPClosure.java +++ b/src/java/org/apache/commons/collections/functors/NOPClosure.java @@ -28,13 +28,13 @@ import org.apache.commons.collections.Closure; * * @author Stephen Colebourne */ -public class NOPClosure implements Closure, Serializable { +public class NOPClosure implements Closure, Serializable { /** Serial version UID */ private static final long serialVersionUID = 3518477308466486130L; /** Singleton predicate instance */ - public static final Closure INSTANCE = new NOPClosure(); + public static final Closure INSTANCE = new NOPClosure(); /** * Factory returning the singleton instance. @@ -42,8 +42,9 @@ public class NOPClosure implements Closure, Serializable { * @return the singleton instance * @since Commons Collections 3.1 */ - public static Closure getInstance() { - return INSTANCE; + @SuppressWarnings("unchecked") + public static Closure getInstance() { + return (Closure) INSTANCE; } /** @@ -58,8 +59,23 @@ public class NOPClosure implements Closure, Serializable { * * @param input the input object */ - public void execute(Object input) { + public void execute(E input) { // do nothing } + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object arg0) { + return arg0.hashCode() == this.hashCode(); + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return System.identityHashCode(INSTANCE); + } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NOPTransformer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/NOPTransformer.java b/src/java/org/apache/commons/collections/functors/NOPTransformer.java index 6c018c8..a21e44a 100644 --- a/src/java/org/apache/commons/collections/functors/NOPTransformer.java +++ b/src/java/org/apache/commons/collections/functors/NOPTransformer.java @@ -28,13 +28,13 @@ import org.apache.commons.collections.Transformer; * * @author Stephen Colebourne */ -public class NOPTransformer implements Transformer, Serializable { +public class NOPTransformer implements Transformer, Serializable { /** Serial version UID */ private static final long serialVersionUID = 2133891748318574490L; /** Singleton predicate instance */ - public static final Transformer INSTANCE = new NOPTransformer(); + public static final Transformer INSTANCE = new NOPTransformer(); /** * Factory returning the singleton instance. @@ -42,8 +42,9 @@ public class NOPTransformer implements Transformer, Serializable { * @return the singleton instance * @since Commons Collections 3.1 */ - public static Transformer getInstance() { - return INSTANCE; + @SuppressWarnings("unchecked") + public static Transformer getInstance() { + return (Transformer) INSTANCE; } /** @@ -59,7 +60,7 @@ public class NOPTransformer implements Transformer, Serializable { * @param input the input object to transform * @return the transformed result which is the input */ - public Object transform(Object input) { + public T transform(T input) { return input; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NonePredicate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/NonePredicate.java b/src/java/org/apache/commons/collections/functors/NonePredicate.java index f3cf062..11b07a1 100644 --- a/src/java/org/apache/commons/collections/functors/NonePredicate.java +++ b/src/java/org/apache/commons/collections/functors/NonePredicate.java @@ -5,9 +5,9 @@ * 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. @@ -35,14 +35,14 @@ import org.apache.commons.collections.Predicate; * @author Stephen Colebourne * @author Matt Benson */ -public final class NonePredicate implements Predicate, PredicateDecorator, Serializable { +public final class NonePredicate implements Predicate, PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = 2007613066565892961L; - + /** The array of predicates to call */ - private final Predicate[] iPredicates; - + private final Predicate[] iPredicates; + /** * Factory to create the predicate. *

@@ -53,13 +53,13 @@ public final class NonePredicate implements Predicate, PredicateDecorator, Seria * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ - public static Predicate getInstance(Predicate[] predicates) { + public static Predicate getInstance(Predicate[] predicates) { FunctorUtils.validate(predicates); if (predicates.length == 0) { - return TruePredicate.INSTANCE; + return TruePredicate.truePredicate(); } predicates = FunctorUtils.copy(predicates); - return new NonePredicate(predicates); + return new NonePredicate(predicates); } /** @@ -72,32 +72,32 @@ public final class NonePredicate implements Predicate, PredicateDecorator, Seria * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ - public static Predicate getInstance(Collection predicates) { - Predicate[] preds = FunctorUtils.validate(predicates); + public static Predicate getInstance(Collection> predicates) { + Predicate[] preds = FunctorUtils.validate(predicates); if (preds.length == 0) { - return TruePredicate.INSTANCE; + return TruePredicate.truePredicate(); } - return new NonePredicate(preds); + return new NonePredicate(preds); } /** * Constructor that performs no validation. * Use getInstance if you want that. - * + * * @param predicates the predicates to check, not cloned, not null */ - public NonePredicate(Predicate[] predicates) { + public NonePredicate(Predicate[] predicates) { super(); iPredicates = predicates; } /** * Evaluates the predicate returning false if any stored predicate returns false. - * + * * @param object the input object * @return true if none of decorated predicates return true */ - public boolean evaluate(Object object) { + public boolean evaluate(T object) { for (int i = 0; i < iPredicates.length; i++) { if (iPredicates[i].evaluate(object)) { return false; @@ -108,11 +108,11 @@ public final class NonePredicate implements Predicate, PredicateDecorator, Seria /** * Gets the predicates, do not modify the array. - * + * * @return the predicates * @since Commons Collections 3.1 */ - public Predicate[] getPredicates() { + public Predicate[] getPredicates() { return iPredicates; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NotNullPredicate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/NotNullPredicate.java b/src/java/org/apache/commons/collections/functors/NotNullPredicate.java index c68d0cf..218ad82 100644 --- a/src/java/org/apache/commons/collections/functors/NotNullPredicate.java +++ b/src/java/org/apache/commons/collections/functors/NotNullPredicate.java @@ -28,13 +28,13 @@ import org.apache.commons.collections.Predicate; * * @author Stephen Colebourne */ -public final class NotNullPredicate implements Predicate, Serializable { +public final class NotNullPredicate implements Predicate, Serializable { /** Serial version UID */ private static final long serialVersionUID = 7533784454832764388L; /** Singleton predicate instance */ - public static final Predicate INSTANCE = new NotNullPredicate(); + public static final Predicate INSTANCE = new NotNullPredicate(); /** * Factory returning the singleton instance. @@ -42,8 +42,9 @@ public final class NotNullPredicate implements Predicate, Serializable { * @return the singleton instance * @since Commons Collections 3.1 */ - public static Predicate getInstance() { - return INSTANCE; + @SuppressWarnings("unchecked") + public static Predicate getInstance() { + return (Predicate) INSTANCE; } /** @@ -59,7 +60,7 @@ public final class NotNullPredicate implements Predicate, Serializable { * @param object the object to evaluate * @return true if not null */ - public boolean evaluate(Object object) { + public boolean evaluate(T object) { return (object != null); } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NotPredicate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/NotPredicate.java b/src/java/org/apache/commons/collections/functors/NotPredicate.java index 7096683..5bc171b 100644 --- a/src/java/org/apache/commons/collections/functors/NotPredicate.java +++ b/src/java/org/apache/commons/collections/functors/NotPredicate.java @@ -28,13 +28,13 @@ import org.apache.commons.collections.Predicate; * * @author Stephen Colebourne */ -public final class NotPredicate implements Predicate, PredicateDecorator, Serializable { +public final class NotPredicate implements Predicate, PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -2654603322338049674L; /** The predicate to decorate */ - private final Predicate iPredicate; + private final Predicate iPredicate; /** * Factory to create the not predicate. @@ -43,11 +43,11 @@ public final class NotPredicate implements Predicate, PredicateDecorator, Serial * @return the predicate * @throws IllegalArgumentException if the predicate is null */ - public static Predicate getInstance(Predicate predicate) { + public static Predicate getInstance(Predicate predicate) { if (predicate == null) { throw new IllegalArgumentException("Predicate must not be null"); } - return new NotPredicate(predicate); + return new NotPredicate(predicate); } /** @@ -56,7 +56,7 @@ public final class NotPredicate implements Predicate, PredicateDecorator, Serial * * @param predicate the predicate to call after the null check */ - public NotPredicate(Predicate predicate) { + public NotPredicate(Predicate predicate) { super(); iPredicate = predicate; } @@ -67,7 +67,7 @@ public final class NotPredicate implements Predicate, PredicateDecorator, Serial * @param object the input object * @return true if predicate returns false */ - public boolean evaluate(Object object) { + public boolean evaluate(T object) { return !(iPredicate.evaluate(object)); } @@ -77,7 +77,8 @@ public final class NotPredicate implements Predicate, PredicateDecorator, Serial * @return the predicate as the only element in an array * @since Commons Collections 3.1 */ - public Predicate[] getPredicates() { + @SuppressWarnings("unchecked") + public Predicate[] getPredicates() { return new Predicate[] {iPredicate}; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java b/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java index 8e6728c..d8269fa 100644 --- a/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java +++ b/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java @@ -29,13 +29,13 @@ import org.apache.commons.collections.Predicate; * * @author Stephen Colebourne */ -public final class NullIsExceptionPredicate implements Predicate, PredicateDecorator, Serializable { +public final class NullIsExceptionPredicate implements Predicate, PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = 3243449850504576071L; /** The predicate to decorate */ - private final Predicate iPredicate; + private final Predicate iPredicate; /** * Factory to create the null exception predicate. @@ -44,11 +44,11 @@ public final class NullIsExceptionPredicate implements Predicate, PredicateDecor * @return the predicate * @throws IllegalArgumentException if the predicate is null */ - public static Predicate getInstance(Predicate predicate) { + public static Predicate getInstance(Predicate predicate) { if (predicate == null) { throw new IllegalArgumentException("Predicate must not be null"); } - return new NullIsExceptionPredicate(predicate); + return new NullIsExceptionPredicate(predicate); } /** @@ -57,7 +57,7 @@ public final class NullIsExceptionPredicate implements Predicate, PredicateDecor * * @param predicate the predicate to call after the null check */ - public NullIsExceptionPredicate(Predicate predicate) { + public NullIsExceptionPredicate(Predicate predicate) { super(); iPredicate = predicate; } @@ -70,7 +70,7 @@ public final class NullIsExceptionPredicate implements Predicate, PredicateDecor * @return true if decorated predicate returns true * @throws FunctorException if input is null */ - public boolean evaluate(Object object) { + public boolean evaluate(T object) { if (object == null) { throw new FunctorException("Input Object must not be null"); } @@ -83,8 +83,9 @@ public final class NullIsExceptionPredicate implements Predicate, PredicateDecor * @return the predicate as the only element in an array * @since Commons Collections 3.1 */ - public Predicate[] getPredicates() { - return new Predicate[] {iPredicate}; + @SuppressWarnings("unchecked") + public Predicate[] getPredicates() { + return new Predicate[] { iPredicate }; } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java b/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java index a60a277..217422c 100644 --- a/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java +++ b/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java @@ -5,9 +5,9 @@ * 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. @@ -22,41 +22,41 @@ import org.apache.commons.collections.Predicate; /** * Predicate implementation that returns false if the input is null. - * + * * @since Commons Collections 3.0 * @version $Revision$ $Date$ * * @author Stephen Colebourne */ -public final class NullIsFalsePredicate implements Predicate, PredicateDecorator, Serializable { +public final class NullIsFalsePredicate implements Predicate, PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -2997501534564735525L; - + /** The predicate to decorate */ - private final Predicate iPredicate; - + private final Predicate iPredicate; + /** * Factory to create the null false predicate. - * + * * @param predicate the predicate to decorate, not null * @return the predicate * @throws IllegalArgumentException if the predicate is null */ - public static Predicate getInstance(Predicate predicate) { + public static Predicate getInstance(Predicate predicate) { if (predicate == null) { throw new IllegalArgumentException("Predicate must not be null"); } - return new NullIsFalsePredicate(predicate); + return new NullIsFalsePredicate(predicate); } /** * Constructor that performs no validation. * Use getInstance if you want that. - * + * * @param predicate the predicate to call after the null check */ - public NullIsFalsePredicate(Predicate predicate) { + public NullIsFalsePredicate(Predicate predicate) { super(); iPredicate = predicate; } @@ -64,11 +64,11 @@ public final class NullIsFalsePredicate implements Predicate, PredicateDecorator /** * Evaluates the predicate returning the result of the decorated predicate * once a null check is performed. - * + * * @param object the input object * @return true if decorated predicate returns true, false if input is null */ - public boolean evaluate(Object object) { + public boolean evaluate(T object) { if (object == null) { return false; } @@ -77,12 +77,13 @@ public final class NullIsFalsePredicate implements Predicate, PredicateDecorator /** * Gets the predicate being decorated. - * + * * @return the predicate as the only element in an array * @since Commons Collections 3.1 */ - public Predicate[] getPredicates() { - return new Predicate[] {iPredicate}; + @SuppressWarnings("unchecked") + public Predicate[] getPredicates() { + return new Predicate[] { iPredicate }; } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java b/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java index e75fc23..0ba668f 100644 --- a/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java +++ b/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java @@ -28,13 +28,13 @@ import org.apache.commons.collections.Predicate; * * @author Stephen Colebourne */ -public final class NullIsTruePredicate implements Predicate, PredicateDecorator, Serializable { +public final class NullIsTruePredicate implements Predicate, PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -7625133768987126273L; /** The predicate to decorate */ - private final Predicate iPredicate; + private final Predicate iPredicate; /** * Factory to create the null true predicate. @@ -43,11 +43,11 @@ public final class NullIsTruePredicate implements Predicate, PredicateDecorator, * @return the predicate * @throws IllegalArgumentException if the predicate is null */ - public static Predicate getInstance(Predicate predicate) { + public static Predicate getInstance(Predicate predicate) { if (predicate == null) { throw new IllegalArgumentException("Predicate must not be null"); } - return new NullIsTruePredicate(predicate); + return new NullIsTruePredicate(predicate); } /** @@ -56,7 +56,7 @@ public final class NullIsTruePredicate implements Predicate, PredicateDecorator, * * @param predicate the predicate to call after the null check */ - public NullIsTruePredicate(Predicate predicate) { + public NullIsTruePredicate(Predicate predicate) { super(); iPredicate = predicate; } @@ -68,7 +68,7 @@ public final class NullIsTruePredicate implements Predicate, PredicateDecorator, * @param object the input object * @return true if decorated predicate returns true or input is null */ - public boolean evaluate(Object object) { + public boolean evaluate(T object) { if (object == null) { return true; } @@ -81,8 +81,9 @@ public final class NullIsTruePredicate implements Predicate, PredicateDecorator, * @return the predicate as the only element in an array * @since Commons Collections 3.1 */ - public Predicate[] getPredicates() { - return new Predicate[] {iPredicate}; + @SuppressWarnings("unchecked") + public Predicate[] getPredicates() { + return new Predicate[] { iPredicate }; } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/OnePredicate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/OnePredicate.java b/src/java/org/apache/commons/collections/functors/OnePredicate.java index 425f9b6..5f3252e 100644 --- a/src/java/org/apache/commons/collections/functors/OnePredicate.java +++ b/src/java/org/apache/commons/collections/functors/OnePredicate.java @@ -35,13 +35,13 @@ import org.apache.commons.collections.Predicate; * @author Stephen Colebourne * @author Matt Benson */ -public final class OnePredicate implements Predicate, PredicateDecorator, Serializable { +public final class OnePredicate implements Predicate, PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -8125389089924745785L; /** The array of predicates to call */ - private final Predicate[] iPredicates; + private final Predicate[] iPredicates; /** * Factory to create the predicate. @@ -54,16 +54,17 @@ public final class OnePredicate implements Predicate, PredicateDecorator, Serial * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ - public static Predicate getInstance(Predicate[] predicates) { + @SuppressWarnings("unchecked") + public static Predicate getInstance(Predicate[] predicates) { FunctorUtils.validate(predicates); if (predicates.length == 0) { - return FalsePredicate.INSTANCE; + return FalsePredicate.falsePredicate(); } if (predicates.length == 1) { - return predicates[0]; + return (Predicate) predicates[0]; } predicates = FunctorUtils.copy(predicates); - return new OnePredicate(predicates); + return new OnePredicate(predicates); } /** @@ -74,9 +75,9 @@ public final class OnePredicate implements Predicate, PredicateDecorator, Serial * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ - public static Predicate getInstance(Collection predicates) { - Predicate[] preds = FunctorUtils.validate(predicates); - return new OnePredicate(preds); + public static Predicate getInstance(Collection> predicates) { + Predicate[] preds = FunctorUtils.validate(predicates); + return new OnePredicate(preds); } /** @@ -85,7 +86,7 @@ public final class OnePredicate implements Predicate, PredicateDecorator, Serial * * @param predicates the predicates to check, not cloned, not null */ - public OnePredicate(Predicate[] predicates) { + public OnePredicate(Predicate[] predicates) { super(); iPredicates = predicates; } @@ -97,7 +98,7 @@ public final class OnePredicate implements Predicate, PredicateDecorator, Serial * @param object the input object * @return true if only one decorated predicate returns true */ - public boolean evaluate(Object object) { + public boolean evaluate(T object) { boolean match = false; for (int i = 0; i < iPredicates.length; i++) { if (iPredicates[i].evaluate(object)) { @@ -116,7 +117,7 @@ public final class OnePredicate implements Predicate, PredicateDecorator, Serial * @return the predicates * @since Commons Collections 3.1 */ - public Predicate[] getPredicates() { + public Predicate[] getPredicates() { return iPredicates; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/OrPredicate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/OrPredicate.java b/src/java/org/apache/commons/collections/functors/OrPredicate.java index ea7f0fd..e87edbd 100644 --- a/src/java/org/apache/commons/collections/functors/OrPredicate.java +++ b/src/java/org/apache/commons/collections/functors/OrPredicate.java @@ -5,9 +5,9 @@ * 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. @@ -22,45 +22,45 @@ import org.apache.commons.collections.Predicate; /** * Predicate implementation that returns true if either of the predicates return true. - * + * * @since Commons Collections 3.0 * @version $Revision$ $Date$ * * @author Stephen Colebourne */ -public final class OrPredicate implements Predicate, PredicateDecorator, Serializable { +public final class OrPredicate implements Predicate, PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -8791518325735182855L; - + /** The array of predicates to call */ - private final Predicate iPredicate1; + private final Predicate iPredicate1; /** The array of predicates to call */ - private final Predicate iPredicate2; - + private final Predicate iPredicate2; + /** * Factory to create the predicate. - * + * * @param predicate1 the first predicate to check, not null * @param predicate2 the second predicate to check, not null * @return the and predicate * @throws IllegalArgumentException if either predicate is null */ - public static Predicate getInstance(Predicate predicate1, Predicate predicate2) { + public static Predicate getInstance(Predicate predicate1, Predicate predicate2) { if (predicate1 == null || predicate2 == null) { throw new IllegalArgumentException("Predicate must not be null"); } - return new OrPredicate(predicate1, predicate2); + return new OrPredicate(predicate1, predicate2); } /** * Constructor that performs no validation. * Use getInstance if you want that. - * + * * @param predicate1 the first predicate to check, not null * @param predicate2 the second predicate to check, not null */ - public OrPredicate(Predicate predicate1, Predicate predicate2) { + public OrPredicate(Predicate predicate1, Predicate predicate2) { super(); iPredicate1 = predicate1; iPredicate2 = predicate2; @@ -68,21 +68,22 @@ public final class OrPredicate implements Predicate, PredicateDecorator, Seriali /** * Evaluates the predicate returning true if either predicate returns true. - * + * * @param object the input object * @return true if either decorated predicate returns true */ - public boolean evaluate(Object object) { + public boolean evaluate(T object) { return (iPredicate1.evaluate(object) || iPredicate2.evaluate(object)); } /** * Gets the two predicates being decorated as an array. - * + * * @return the predicates * @since Commons Collections 3.1 */ - public Predicate[] getPredicates() { + @SuppressWarnings("unchecked") + public Predicate[] getPredicates() { return new Predicate[] {iPredicate1, iPredicate2}; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/PredicateTransformer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/PredicateTransformer.java b/src/java/org/apache/commons/collections/functors/PredicateTransformer.java index a0a83d9..ca8c93b 100644 --- a/src/java/org/apache/commons/collections/functors/PredicateTransformer.java +++ b/src/java/org/apache/commons/collections/functors/PredicateTransformer.java @@ -23,20 +23,20 @@ import org.apache.commons.collections.Transformer; /** * Transformer implementation that calls a Predicate using the input object - * and then returns the input. + * and then returns the result. * * @since Commons Collections 3.0 * @version $Revision$ $Date$ * * @author Stephen Colebourne */ -public class PredicateTransformer implements Transformer, Serializable { +public class PredicateTransformer implements Transformer, Serializable { /** Serial version UID */ private static final long serialVersionUID = 5278818408044349346L; /** The closure to wrap */ - private final Predicate iPredicate; + private final Predicate iPredicate; /** * Factory method that performs validation. @@ -45,11 +45,11 @@ public class PredicateTransformer implements Transformer, Serializable { * @return the predicate transformer * @throws IllegalArgumentException if the predicate is null */ - public static Transformer getInstance(Predicate predicate) { + public static Transformer getInstance(Predicate predicate) { if (predicate == null) { throw new IllegalArgumentException("Predicate must not be null"); } - return new PredicateTransformer(predicate); + return new PredicateTransformer(predicate); } /** @@ -58,7 +58,7 @@ public class PredicateTransformer implements Transformer, Serializable { * * @param predicate the predicate to call, not null */ - public PredicateTransformer(Predicate predicate) { + public PredicateTransformer(Predicate predicate) { super(); iPredicate = predicate; } @@ -69,8 +69,8 @@ public class PredicateTransformer implements Transformer, Serializable { * @param input the input object to transform * @return the transformed result */ - public Object transform(Object input) { - return (iPredicate.evaluate(input) ? Boolean.TRUE : Boolean.FALSE); + public Boolean transform(T input) { + return iPredicate.evaluate(input); } /** @@ -79,7 +79,7 @@ public class PredicateTransformer implements Transformer, Serializable { * @return the predicate * @since Commons Collections 3.1 */ - public Predicate getPredicate() { + public Predicate getPredicate() { return iPredicate; } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/PrototypeFactory.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/PrototypeFactory.java b/src/java/org/apache/commons/collections/functors/PrototypeFactory.java index d3b2ed0..c23d584 100644 --- a/src/java/org/apache/commons/collections/functors/PrototypeFactory.java +++ b/src/java/org/apache/commons/collections/functors/PrototypeFactory.java @@ -55,22 +55,22 @@ public class PrototypeFactory { * @throws IllegalArgumentException if the prototype is null * @throws IllegalArgumentException if the prototype cannot be cloned */ - public static Factory getInstance(Object prototype) { + @SuppressWarnings("unchecked") + public static Factory getInstance(T prototype) { if (prototype == null) { - return ConstantFactory.NULL_INSTANCE; + return ConstantFactory.getInstance(null); } try { Method method = prototype.getClass().getMethod("clone", (Class[]) null); - return new PrototypeCloneFactory(prototype, method); + return new PrototypeCloneFactory(prototype, method); } catch (NoSuchMethodException ex) { try { - prototype.getClass().getConstructor(new Class[] { prototype.getClass()}); - return new InstantiateFactory( - prototype.getClass(), - new Class[] { prototype.getClass()}, + prototype.getClass().getConstructor(new Class[] { prototype.getClass() }); + return new InstantiateFactory( + (Class) prototype.getClass(), + new Class[] { prototype.getClass() }, new Object[] { prototype }); - } catch (NoSuchMethodException ex2) { if (prototype instanceof Serializable) { return new PrototypeSerializationFactory((Serializable) prototype); @@ -93,20 +93,20 @@ public class PrototypeFactory { /** * PrototypeCloneFactory creates objects by copying a prototype using the clone method. */ - static class PrototypeCloneFactory implements Factory, Serializable { + static class PrototypeCloneFactory implements Factory, Serializable { /** The serial version */ private static final long serialVersionUID = 5604271422565175555L; /** The object to clone each time */ - private final Object iPrototype; + private final T iPrototype; /** The method used to clone */ private transient Method iCloneMethod; /** * Constructor to store prototype. */ - private PrototypeCloneFactory(Object prototype, Method method) { + private PrototypeCloneFactory(T prototype, Method method) { super(); iPrototype = prototype; iCloneMethod = method; @@ -118,7 +118,6 @@ public class PrototypeFactory { private void findCloneMethod() { try { iCloneMethod = iPrototype.getClass().getMethod("clone", (Class[]) null); - } catch (NoSuchMethodException ex) { throw new IllegalArgumentException("PrototypeCloneFactory: The clone method must exist and be public "); } @@ -129,15 +128,15 @@ public class PrototypeFactory { * * @return the new object */ - public Object create() { + @SuppressWarnings("unchecked") + public T create() { // needed for post-serialization if (iCloneMethod == null) { findCloneMethod(); } try { - return iCloneMethod.invoke(iPrototype, (Object[])null); - + return (T) iCloneMethod.invoke(iPrototype, (Object[]) null); } catch (IllegalAccessException ex) { throw new FunctorException("PrototypeCloneFactory: Clone method must be public", ex); } catch (InvocationTargetException ex) { @@ -151,18 +150,18 @@ public class PrototypeFactory { /** * PrototypeSerializationFactory creates objects by cloning a prototype using serialization. */ - static class PrototypeSerializationFactory implements Factory, Serializable { + static class PrototypeSerializationFactory implements Factory, Serializable { /** The serial version */ private static final long serialVersionUID = -8704966966139178833L; /** The object to clone via serialization each time */ - private final Serializable iPrototype; + private final T iPrototype; /** * Constructor to store prototype */ - private PrototypeSerializationFactory(Serializable prototype) { + private PrototypeSerializationFactory(T prototype) { super(); iPrototype = prototype; } @@ -172,7 +171,8 @@ public class PrototypeFactory { * * @return the new object */ - public Object create() { + @SuppressWarnings("unchecked") + public T create() { ByteArrayOutputStream baos = new ByteArrayOutputStream(512); ByteArrayInputStream bais = null; try { @@ -181,7 +181,7 @@ public class PrototypeFactory { bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); - return in.readObject(); + return (T) in.readObject(); } catch (ClassNotFoundException ex) { throw new FunctorException(ex); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/StringValueTransformer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/StringValueTransformer.java b/src/java/org/apache/commons/collections/functors/StringValueTransformer.java index 8e75c82..3e54967 100644 --- a/src/java/org/apache/commons/collections/functors/StringValueTransformer.java +++ b/src/java/org/apache/commons/collections/functors/StringValueTransformer.java @@ -29,13 +29,13 @@ import org.apache.commons.collections.Transformer; * * @author Stephen Colebourne */ -public final class StringValueTransformer implements Transformer, Serializable { +public final class StringValueTransformer implements Transformer, Serializable { /** Serial version UID */ private static final long serialVersionUID = 7511110693171758606L; /** Singleton predicate instance */ - public static final Transformer INSTANCE = new StringValueTransformer(); + public static final Transformer INSTANCE = new StringValueTransformer(); /** * Factory returning the singleton instance. @@ -43,8 +43,9 @@ public final class StringValueTransformer implements Transformer, Serializable { * @return the singleton instance * @since Commons Collections 3.1 */ - public static Transformer getInstance() { - return INSTANCE; + @SuppressWarnings("unchecked") + public static Transformer getInstance() { + return (Transformer) INSTANCE; } /** @@ -60,7 +61,7 @@ public final class StringValueTransformer implements Transformer, Serializable { * @param input the input object to transform * @return the transformed result */ - public Object transform(Object input) { + public String transform(T input) { return String.valueOf(input); } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/SwitchClosure.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/functors/SwitchClosure.java b/src/java/org/apache/commons/collections/functors/SwitchClosure.java index be64369..1ee7806 100644 --- a/src/java/org/apache/commons/collections/functors/SwitchClosure.java +++ b/src/java/org/apache/commons/collections/functors/SwitchClosure.java @@ -5,9 +5,9 @@ * 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. @@ -17,7 +17,6 @@ package org.apache.commons.collections.functors; import java.io.Serializable; -import java.util.Iterator; import java.util.Map; import org.apache.commons.collections.Closure; @@ -26,27 +25,27 @@ import org.apache.commons.collections.Predicate; /** * Closure implementation calls the closure whose predicate returns true, * like a switch statement. - * + * * @since Commons Collections 3.0 * @version $Revision$ $Date$ * * @author Stephen Colebourne */ -public class SwitchClosure implements Closure, Serializable { +public class SwitchClosure implements Closure, Serializable { /** Serial version UID */ private static final long serialVersionUID = 3518477308466486130L; /** The tests to consider */ - private final Predicate[] iPredicates; + private final Predicate[] iPredicates; /** The matching closures to call */ - private final Closure[] iClosures; + private final Closure[] iClosures; /** The default closure to call if no tests match */ - private final Closure iDefault; + private final Closure iDefault; /** * Factory method that performs validation and copies the parameter arrays. - * + * * @param predicates array of predicates, cloned, no nulls * @param closures matching array of closures, cloned, no nulls * @param defaultClosure the closure to use if no match, null means nop @@ -54,85 +53,82 @@ public class SwitchClosure implements Closure, Serializable { * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if any element in the array is null */ - public static Closure getInstance(Predicate[] predicates, Closure[] closures, Closure defaultClosure) { + @SuppressWarnings("unchecked") + public static Closure getInstance(Predicate[] predicates, Closure[] closures, Closure defaultClosure) { FunctorUtils.validate(predicates); FunctorUtils.validate(closures); if (predicates.length != closures.length) { throw new IllegalArgumentException("The predicate and closure arrays must be the same size"); } if (predicates.length == 0) { - return (defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure); + return (Closure) (defaultClosure == null ? NOPClosure.getInstance(): defaultClosure); } predicates = FunctorUtils.copy(predicates); closures = FunctorUtils.copy(closures); - return new SwitchClosure(predicates, closures, defaultClosure); + return new SwitchClosure(predicates, closures, defaultClosure); } /** - * Create a new Closure that calls one of the closures depending - * on the predicates. + * Create a new Closure that calls one of the closures depending + * on the predicates. *

- * The Map consists of Predicate keys and Closure values. A closure + * The Map consists of Predicate keys and Closure values. A closure * is called if its matching predicate returns true. Each predicate is evaluated * until one returns true. If no predicates evaluate to true, the default - * closure is called. The default closure is set in the map with a - * null key. The ordering is that of the iterator() method on the entryset + * closure is called. The default closure is set in the map with a + * null key. The ordering is that of the iterator() method on the entryset * collection of the map. - * + * * @param predicatesAndClosures a map of predicates to closures * @return the switch closure * @throws IllegalArgumentException if the map is null * @throws IllegalArgumentException if any closure in the map is null * @throws ClassCastException if the map elements are of the wrong type */ - public static Closure getInstance(Map predicatesAndClosures) { - Closure[] closures = null; - Predicate[] preds = null; + @SuppressWarnings("unchecked") + public static Closure getInstance(Map, Closure> predicatesAndClosures) { if (predicatesAndClosures == null) { throw new IllegalArgumentException("The predicate and closure map must not be null"); } - if (predicatesAndClosures.size() == 0) { - return NOPClosure.INSTANCE; - } // convert to array like this to guarantee iterator() ordering - Closure defaultClosure = (Closure) predicatesAndClosures.remove(null); + Closure defaultClosure = predicatesAndClosures.remove(null); int size = predicatesAndClosures.size(); if (size == 0) { - return (defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure); + return (Closure) (defaultClosure == null ? NOPClosure.getInstance() : defaultClosure); } - closures = new Closure[size]; - preds = new Predicate[size]; + Closure[] closures = new Closure[size]; + Predicate[] preds = new Predicate[size]; int i = 0; - for (Iterator it = predicatesAndClosures.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Map.Entry) it.next(); - preds[i] = (Predicate) entry.getKey(); - closures[i] = (Closure) entry.getValue(); + for (Map.Entry, Closure> entry : predicatesAndClosures.entrySet()) { + preds[i] = entry.getKey(); + closures[i] = entry.getValue(); i++; } - return new SwitchClosure(preds, closures, defaultClosure); + return new SwitchClosure(preds, closures, defaultClosure); } - + /** * Constructor that performs no validation. * Use getInstance if you want that. - * + * * @param predicates array of predicates, not cloned, no nulls * @param closures matching array of closures, not cloned, no nulls * @param defaultClosure the closure to use if no match, null means nop */ - public SwitchClosure(Predicate[] predicates, Closure[] closures, Closure defaultClosure) { + @SuppressWarnings("unchecked") + public SwitchClosure(Predicate[] predicates, Closure[] closures, Closure defaultClosure) { super(); iPredicates = predicates; iClosures = closures; - iDefault = (defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure); + iDefault = (Closure) (defaultClosure == null ? NOPClosure.getInstance() : defaultClosure); } /** * Executes the closure whose matching predicate returns true - * + * * @param input the input object */ - public void execute(Object input) { + public void execute(E input) { for (int i = 0; i < iPredicates.length; i++) { if (iPredicates[i].evaluate(input) == true) { iClosures[i].execute(input); @@ -144,32 +140,32 @@ public class SwitchClosure implements Closure, Serializable { /** * Gets the predicates, do not modify the array. - * + * * @return the predicates * @since Commons Collections 3.1 */ - public Predicate[] getPredicates() { + public Predicate[] getPredicates() { return iPredicates; } /** * Gets the closures, do not modify the array. - * + * * @return the closures * @since Commons Collections 3.1 */ - public Closure[] getClosures() { + public Closure[] getClosures() { return iClosures; } /** * Gets the default closure. - * + * * @return the default closure * @since Commons Collections 3.1 */ - public Closure getDefaultClosure() { + public Closure getDefaultClosure() { return iDefault; } - + }