You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2012/07/26 21:46:33 UTC
svn commit: r1366174 - in /commons/proper/collections/trunk/src:
changes/changes.xml
main/java/org/apache/commons/collections/functors/EqualPredicate.java
Author: tn
Date: Thu Jul 26 19:46:32 2012
New Revision: 1366174
URL: http://svn.apache.org/viewvc?rev=1366174&view=rev
Log:
[COLLECTIONS-239] Use of generic Equator in EqualPredicate.
Modified:
commons/proper/collections/trunk/src/changes/changes.xml
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/EqualPredicate.java
Modified: commons/proper/collections/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1366174&r1=1366173&r2=1366174&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Thu Jul 26 19:46:32 2012
@@ -22,8 +22,11 @@
<body>
<release version="4.0" date="TBA" description="Next release">
+ <action issue="COLLECTION-239" type="add" due-to="Stephen Kestle">
+ Added support for using custom "Equator" objects in "EqualPredicate".
+ </action>
<action issue="COLLECTIONS-425" type="fix" due-to="Adrian Nistor">
- Improved performance of ListOrderedMap#remove(Object) method.
+ Improved performance of "ListOrderedMap#remove(Object)" method.
</action>
</release>
</body>
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/EqualPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/EqualPredicate.java?rev=1366174&r1=1366173&r2=1366174&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/EqualPredicate.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/EqualPredicate.java Thu Jul 26 19:46:32 2012
@@ -35,11 +35,15 @@ public final class EqualPredicate<T> imp
private static final long serialVersionUID = 5633766978029907089L;
/** The value to compare to */
- private final Object iValue;
+ private final T iValue;
+
+ /** The equator to use for comparison */
+ private final Equator<T> equator;
/**
- * Factory to create the identity predicate.
+ * Factory to create the predicate.
*
+ * @param <T> the type that the predicate queries
* @param object the object to compare to
* @return the predicate
* @throws IllegalArgumentException if the predicate is null
@@ -52,14 +56,44 @@ public final class EqualPredicate<T> imp
}
/**
+ * Factory to create the identity predicate.
+ *
+ * @param <T> the type that the predicate queries
+ * @param object the object to compare to
+ * @param equator the equator to use for comparison
+ * @return the predicate
+ * @throws IllegalArgumentException if the predicate is null
+ * @since 4.0
+ */
+ public static <T> Predicate<T> equalPredicate(T object, Equator<T> equator) {
+ if (object == null) {
+ return nullPredicate();
+ }
+ return new EqualPredicate<T>(object, equator);
+ }
+
+ /**
+ * Constructor that performs no validation.
+ * Use <code>getInstance</code> if you want that.
+ *
+ * @param object the object to compare to
+ */
+ public EqualPredicate(T object) {
+ this(object, new DefaultEquator<T>());
+ }
+
+ /**
* Constructor that performs no validation.
* Use <code>getInstance</code> if you want that.
*
* @param object the object to compare to
+ * @param equator the equator to use for comparison
+ * @since 4.0
*/
- public EqualPredicate(Object object) {
+ public EqualPredicate(T object, Equator<T> equator) {
super();
iValue = object;
+ this.equator = equator;
}
/**
@@ -68,8 +102,8 @@ public final class EqualPredicate<T> imp
* @param object the input object
* @return true if input object equals stored value
*/
- public boolean evaluate(Object object) {
- return (iValue.equals(object));
+ public boolean evaluate(T object) {
+ return equator.equate(iValue, object);
}
/**