You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/10/21 13:13:59 UTC
[commons-beanutils] branch master updated: BEANUTILS-527: Remove
Commons Collection4 dependency. (#9)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/master by this push:
new 30f0fa5 BEANUTILS-527: Remove Commons Collection4 dependency. (#9)
30f0fa5 is described below
commit 30f0fa5fe4d61ae301269e3db1ce533db801f891
Author: Melloware <me...@gmail.com>
AuthorDate: Mon Oct 21 09:13:50 2019 -0400
BEANUTILS-527: Remove Commons Collection4 dependency. (#9)
* BEANUTILS-527: Remove Commons Collection4 dependency.
* BEANUTILS-527: Rename NaturalOrderingComparator.
---
pom.xml | 5 --
.../apache/commons/beanutils2/BeanComparator.java | 59 +++++++++++++++++++---
.../apache/commons/beanutils2/package-info.java | 3 +-
3 files changed, 54 insertions(+), 13 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4b581cd..af845d7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -330,11 +330,6 @@
<version>1.2</version>
</dependency>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-collections4</artifactId>
- <version>4.4</version>
- </dependency>
- <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections-testframework</artifactId>
<version>3.2.1</version>
diff --git a/src/main/java/org/apache/commons/beanutils2/BeanComparator.java b/src/main/java/org/apache/commons/beanutils2/BeanComparator.java
index f5da10a..f9a6b0f 100644
--- a/src/main/java/org/apache/commons/beanutils2/BeanComparator.java
+++ b/src/main/java/org/apache/commons/beanutils2/BeanComparator.java
@@ -21,7 +21,6 @@ import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.Comparator;
-import org.apache.commons.collections4.comparators.ComparableComparator;
/**
* <p>
@@ -84,7 +83,7 @@ public class BeanComparator<T> implements Comparator<T>, Serializable {
* If the property passed in is null then the actual objects will be compared
*/
public BeanComparator( final String property ) {
- this( property, ComparableComparator.INSTANCE );
+ this( property, NaturalOrderingComparator.INSTANCE );
}
/**
@@ -108,7 +107,7 @@ public class BeanComparator<T> implements Comparator<T>, Serializable {
if (comparator != null) {
this.comparator = comparator;
} else {
- this.comparator = ComparableComparator.INSTANCE;
+ this.comparator = NaturalOrderingComparator.INSTANCE;
}
}
@@ -217,9 +216,7 @@ public class BeanComparator<T> implements Comparator<T>, Serializable {
*/
@Override
public int hashCode() {
- int result;
- result = comparator.hashCode();
- return result;
+ return comparator.hashCode();
}
/**
@@ -238,4 +235,54 @@ public class BeanComparator<T> implements Comparator<T>, Serializable {
Comparator c = comparator;
return c.compare(val1, val2);
}
+
+ /**
+ * A {@link Comparator Comparator} that compares {@link Comparable Comparable}
+ * objects.
+ * <p>
+ * This Comparator is useful, for example, for enforcing the natural order in
+ * custom implementations of {@link java.util.SortedSet SortedSet} and
+ * {@link java.util.SortedMap SortedMap}.
+ * </p>
+ *
+ * @param <E> the type of objects compared by this comparator
+ * @see java.util.Collections#reverseOrder()
+ */
+ private static class NaturalOrderingComparator<E extends Comparable<? super E>> implements Comparator<E>, Serializable {
+
+ /** Serialization version. */
+ private static final long serialVersionUID=-291439688585137865L;
+
+ /** The singleton instance. */
+ @SuppressWarnings("rawtypes")
+ public static final NaturalOrderingComparator INSTANCE = new NaturalOrderingComparator();
+
+ /**
+ * Private constructor to prevent instantiation. Only use INSTANCE.
+ */
+ private NaturalOrderingComparator() {
+ super();
+ }
+
+ /**
+ * Compare the two {@link Comparable Comparable} arguments.
+ * This method is equivalent to:
+ * <pre>((Comparable)obj1).compareTo(obj2)</pre>
+ */
+ @Override
+ public int compare(final E obj1, final E obj2) {
+ return obj1.compareTo(obj2);
+ }
+
+ @Override
+ public int hashCode() {
+ return "NaturalOrderingComparator".hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object object) {
+ return this == object ||
+ null != object && object.getClass().equals(this.getClass());
+ }
+ }
}
diff --git a/src/main/java/org/apache/commons/beanutils2/package-info.java b/src/main/java/org/apache/commons/beanutils2/package-info.java
index caf0002..38e5bb5 100644
--- a/src/main/java/org/apache/commons/beanutils2/package-info.java
+++ b/src/main/java/org/apache/commons/beanutils2/package-info.java
@@ -1017,8 +1017,7 @@
* <h2>How Do I Set The BeanComparator Order To Be Ascending/Descending?</h2>
* <p>
* BeanComparator relies on an internal Comparator to perform the actual
- * comparisions. By default,
- * <code>org.apache.commons.collections4.comparators.ComparableComparator</code>
+ * comparisions. By default, a natural ordering comparator
* is used which imposes a natural order. If you want to change the order,
* then a custom Comparator should be created and passed into the
* appropriate constructor.