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/05/10 13:11:07 UTC
[commons-lang] branch master updated: Sort methods.
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-lang.git
The following commit(s) were added to refs/heads/master by this push:
new ffb8b29 Sort methods.
ffb8b29 is described below
commit ffb8b29790cf781765fed9d1da6ec6988842ad18
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri May 10 09:11:02 2019 -0400
Sort methods.
---
.../apache/commons/lang3/tuple/ImmutablePair.java | 30 ++++----
.../commons/lang3/tuple/ImmutableTriple.java | 34 ++++-----
.../apache/commons/lang3/tuple/MutablePair.java | 32 ++++----
.../apache/commons/lang3/tuple/MutableTriple.java | 50 ++++++------
.../java/org/apache/commons/lang3/tuple/Pair.java | 88 +++++++++++-----------
.../org/apache/commons/lang3/tuple/Triple.java | 50 ++++++------
6 files changed, 142 insertions(+), 142 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/tuple/ImmutablePair.java b/src/main/java/org/apache/commons/lang3/tuple/ImmutablePair.java
index e494e12..488fd7c 100644
--- a/src/main/java/org/apache/commons/lang3/tuple/ImmutablePair.java
+++ b/src/main/java/org/apache/commons/lang3/tuple/ImmutablePair.java
@@ -44,6 +44,16 @@ public final class ImmutablePair<L, R> extends Pair<L, R> {
public static final ImmutablePair<?, ?>[] EMPTY_ARRAY = new ImmutablePair[0];
/**
+ * An immutable pair of nulls.
+ */
+ // This is not defined with generics to avoid warnings in call sites.
+ @SuppressWarnings("rawtypes")
+ private static final ImmutablePair NULL = of(null, null);
+
+ /** Serialization version */
+ private static final long serialVersionUID = 4954918890077093841L;
+
+ /**
* Returns the empty array singleton that can be assigned without compiler warning.
*
* @param <L> the left element type
@@ -58,16 +68,6 @@ public final class ImmutablePair<L, R> extends Pair<L, R> {
}
/**
- * An immutable pair of nulls.
- */
- // This is not defined with generics to avoid warnings in call sites.
- @SuppressWarnings("rawtypes")
- private static final ImmutablePair NULL = of(null, null);
-
- /** Serialization version */
- private static final long serialVersionUID = 4954918890077093841L;
-
- /**
* Returns an immutable pair of nulls.
*
* @param <L> the left element of this pair. Value is {@code null}.
@@ -79,11 +79,6 @@ public final class ImmutablePair<L, R> extends Pair<L, R> {
return NULL;
}
- /** Left object */
- public final L left;
- /** Right object */
- public final R right;
-
/**
* <p>Obtains an immutable pair of two objects inferring the generic types.</p>
*
@@ -99,6 +94,11 @@ public final class ImmutablePair<L, R> extends Pair<L, R> {
public static <L, R> ImmutablePair<L, R> of(final L left, final R right) {
return new ImmutablePair<>(left, right);
}
+ /** Left object */
+ public final L left;
+
+ /** Right object */
+ public final R right;
/**
* Create a new pair instance.
diff --git a/src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java b/src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java
index 2588f6a..f51df45 100644
--- a/src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java
+++ b/src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java
@@ -45,6 +45,16 @@ public final class ImmutableTriple<L, M, R> extends Triple<L, M, R> {
public static final ImmutableTriple<?, ?, ?>[] EMPTY_ARRAY = new ImmutableTriple[0];
/**
+ * An immutable triple of nulls.
+ */
+ // This is not defined with generics to avoid warnings in call sites.
+ @SuppressWarnings("rawtypes")
+ private static final ImmutableTriple NULL = of(null, null, null);
+
+ /** Serialization version */
+ private static final long serialVersionUID = 1L;
+
+ /**
* Returns the empty array singleton that can be assigned without compiler warning.
*
* @param <L> the left element type
@@ -60,16 +70,6 @@ public final class ImmutableTriple<L, M, R> extends Triple<L, M, R> {
}
/**
- * An immutable triple of nulls.
- */
- // This is not defined with generics to avoid warnings in call sites.
- @SuppressWarnings("rawtypes")
- private static final ImmutableTriple NULL = of(null, null, null);
-
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
- /**
* Returns an immutable triple of nulls.
*
* @param <L> the left element of this triple. Value is {@code null}.
@@ -82,13 +82,6 @@ public final class ImmutableTriple<L, M, R> extends Triple<L, M, R> {
return NULL;
}
- /** Left object */
- public final L left;
- /** Middle object */
- public final M middle;
- /** Right object */
- public final R right;
-
/**
* <p>Obtains an immutable triple of three objects inferring the generic types.</p>
*
@@ -106,6 +99,13 @@ public final class ImmutableTriple<L, M, R> extends Triple<L, M, R> {
public static <L, M, R> ImmutableTriple<L, M, R> of(final L left, final M middle, final R right) {
return new ImmutableTriple<>(left, middle, right);
}
+ /** Left object */
+ public final L left;
+ /** Middle object */
+ public final M middle;
+
+ /** Right object */
+ public final R right;
/**
* Create a new triple instance.
diff --git a/src/main/java/org/apache/commons/lang3/tuple/MutablePair.java b/src/main/java/org/apache/commons/lang3/tuple/MutablePair.java
index a480071..58a66a7 100644
--- a/src/main/java/org/apache/commons/lang3/tuple/MutablePair.java
+++ b/src/main/java/org/apache/commons/lang3/tuple/MutablePair.java
@@ -38,6 +38,9 @@ public class MutablePair<L, R> extends Pair<L, R> {
*/
public static final MutablePair<?, ?>[] EMPTY_ARRAY = new MutablePair[0];
+ /** Serialization version */
+ private static final long serialVersionUID = 4954918890077093841L;
+
/**
* Returns the empty array singleton that can be assigned without compiler warning.
*
@@ -52,14 +55,6 @@ public class MutablePair<L, R> extends Pair<L, R> {
return (MutablePair<L, R>[]) EMPTY_ARRAY;
}
- /** Serialization version */
- private static final long serialVersionUID = 4954918890077093841L;
-
- /** Left object */
- public L left;
- /** Right object */
- public R right;
-
/**
* <p>Obtains a mutable pair of two objects inferring the generic types.</p>
*
@@ -75,6 +70,11 @@ public class MutablePair<L, R> extends Pair<L, R> {
public static <L, R> MutablePair<L, R> of(final L left, final R right) {
return new MutablePair<>(left, right);
}
+ /** Left object */
+ public L left;
+
+ /** Right object */
+ public R right;
/**
* Create a new pair instance of two nulls.
@@ -105,6 +105,14 @@ public class MutablePair<L, R> extends Pair<L, R> {
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public R getRight() {
+ return right;
+ }
+
+ /**
* Sets the left element of the pair.
*
* @param left the new value of the left element, may be null
@@ -114,14 +122,6 @@ public class MutablePair<L, R> extends Pair<L, R> {
}
/**
- * {@inheritDoc}
- */
- @Override
- public R getRight() {
- return right;
- }
-
- /**
* Sets the right element of the pair.
*
* @param right the new value of the right element, may be null
diff --git a/src/main/java/org/apache/commons/lang3/tuple/MutableTriple.java b/src/main/java/org/apache/commons/lang3/tuple/MutableTriple.java
index 4cf9474..b3352ac 100644
--- a/src/main/java/org/apache/commons/lang3/tuple/MutableTriple.java
+++ b/src/main/java/org/apache/commons/lang3/tuple/MutableTriple.java
@@ -39,6 +39,9 @@ public class MutableTriple<L, M, R> extends Triple<L, M, R> {
*/
public static final MutableTriple<?, ?, ?>[] EMPTY_ARRAY = new MutableTriple[0];
+ /** Serialization version */
+ private static final long serialVersionUID = 1L;
+
/**
* Returns the empty array singleton that can be assigned without compiler warning.
*
@@ -54,16 +57,6 @@ public class MutableTriple<L, M, R> extends Triple<L, M, R> {
return (MutableTriple<L, M, R>[]) EMPTY_ARRAY;
}
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
- /** Left object */
- public L left;
- /** Middle object */
- public M middle;
- /** Right object */
- public R right;
-
/**
* <p>Obtains a mutable triple of three objects inferring the generic types.</p>
*
@@ -81,6 +74,13 @@ public class MutableTriple<L, M, R> extends Triple<L, M, R> {
public static <L, M, R> MutableTriple<L, M, R> of(final L left, final M middle, final R right) {
return new MutableTriple<>(left, middle, right);
}
+ /** Left object */
+ public L left;
+ /** Middle object */
+ public M middle;
+
+ /** Right object */
+ public R right;
/**
* Create a new triple instance of three nulls.
@@ -113,37 +113,37 @@ public class MutableTriple<L, M, R> extends Triple<L, M, R> {
}
/**
- * Sets the left element of the triple.
- *
- * @param left the new value of the left element, may be null
+ * {@inheritDoc}
*/
- public void setLeft(final L left) {
- this.left = left;
+ @Override
+ public M getMiddle() {
+ return middle;
}
/**
* {@inheritDoc}
*/
@Override
- public M getMiddle() {
- return middle;
+ public R getRight() {
+ return right;
}
/**
- * Sets the middle element of the triple.
+ * Sets the left element of the triple.
*
- * @param middle the new value of the middle element, may be null
+ * @param left the new value of the left element, may be null
*/
- public void setMiddle(final M middle) {
- this.middle = middle;
+ public void setLeft(final L left) {
+ this.left = left;
}
/**
- * {@inheritDoc}
+ * Sets the middle element of the triple.
+ *
+ * @param middle the new value of the middle element, may be null
*/
- @Override
- public R getRight() {
- return right;
+ public void setMiddle(final M middle) {
+ this.middle = middle;
}
/**
diff --git a/src/main/java/org/apache/commons/lang3/tuple/Pair.java b/src/main/java/org/apache/commons/lang3/tuple/Pair.java
index 1a25f17..b64af80 100644
--- a/src/main/java/org/apache/commons/lang3/tuple/Pair.java
+++ b/src/main/java/org/apache/commons/lang3/tuple/Pair.java
@@ -40,9 +40,6 @@ import org.apache.commons.lang3.builder.CompareToBuilder;
*/
public abstract class Pair<L, R> implements Map.Entry<L, R>, Comparable<Pair<L, R>>, Serializable {
- /** Serialization version */
- private static final long serialVersionUID = 4954918890077093841L;
-
private static final class PairAdapter<L, R> extends Pair<L, R> {
private static final long serialVersionUID = 1L;
@@ -64,6 +61,9 @@ public abstract class Pair<L, R> implements Map.Entry<L, R>, Comparable<Pair<L,
}
+ /** Serialization version */
+ private static final long serialVersionUID = 4954918890077093841L;
+
/**
* An empty array.
* <p>
@@ -106,22 +106,36 @@ public abstract class Pair<L, R> implements Map.Entry<L, R>, Comparable<Pair<L,
//-----------------------------------------------------------------------
/**
- * <p>Gets the left element from this pair.</p>
- *
- * <p>When treated as a key-value pair, this is the key.</p>
+ * <p>Compares the pair based on the left element followed by the right element.
+ * The types must be {@code Comparable}.</p>
*
- * @return the left element, may be null
+ * @param other the other pair, not null
+ * @return negative if this is less, zero if equal, positive if greater
*/
- public abstract L getLeft();
+ @Override
+ public int compareTo(final Pair<L, R> other) {
+ return new CompareToBuilder().append(getLeft(), other.getLeft())
+ .append(getRight(), other.getRight()).toComparison();
+ }
/**
- * <p>Gets the right element from this pair.</p>
- *
- * <p>When treated as a key-value pair, this is the value.</p>
+ * <p>Compares this pair to another based on the two elements.</p>
*
- * @return the right element, may be null
+ * @param obj the object to compare to, null returns false
+ * @return true if the elements of the pair are equal
*/
- public abstract R getRight();
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof Map.Entry<?, ?>) {
+ final Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;
+ return Objects.equals(getKey(), other.getKey())
+ && Objects.equals(getValue(), other.getValue());
+ }
+ return false;
+ }
/**
* <p>Gets the key from this pair.</p>
@@ -136,50 +150,36 @@ public abstract class Pair<L, R> implements Map.Entry<L, R>, Comparable<Pair<L,
return getLeft();
}
+ //-----------------------------------------------------------------------
/**
- * <p>Gets the value from this pair.</p>
+ * <p>Gets the left element from this pair.</p>
*
- * <p>This method implements the {@code Map.Entry} interface returning the
- * right element as the value.</p>
+ * <p>When treated as a key-value pair, this is the key.</p>
*
- * @return the right element as the value, may be null
+ * @return the left element, may be null
*/
- @Override
- public R getValue() {
- return getRight();
- }
+ public abstract L getLeft();
- //-----------------------------------------------------------------------
/**
- * <p>Compares the pair based on the left element followed by the right element.
- * The types must be {@code Comparable}.</p>
+ * <p>Gets the right element from this pair.</p>
*
- * @param other the other pair, not null
- * @return negative if this is less, zero if equal, positive if greater
+ * <p>When treated as a key-value pair, this is the value.</p>
+ *
+ * @return the right element, may be null
*/
- @Override
- public int compareTo(final Pair<L, R> other) {
- return new CompareToBuilder().append(getLeft(), other.getLeft())
- .append(getRight(), other.getRight()).toComparison();
- }
+ public abstract R getRight();
/**
- * <p>Compares this pair to another based on the two elements.</p>
+ * <p>Gets the value from this pair.</p>
*
- * @param obj the object to compare to, null returns false
- * @return true if the elements of the pair are equal
+ * <p>This method implements the {@code Map.Entry} interface returning the
+ * right element as the value.</p>
+ *
+ * @return the right element as the value, may be null
*/
@Override
- public boolean equals(final Object obj) {
- if (obj == this) {
- return true;
- }
- if (obj instanceof Map.Entry<?, ?>) {
- final Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;
- return Objects.equals(getKey(), other.getKey())
- && Objects.equals(getValue(), other.getValue());
- }
- return false;
+ public R getValue() {
+ return getRight();
}
/**
diff --git a/src/main/java/org/apache/commons/lang3/tuple/Triple.java b/src/main/java/org/apache/commons/lang3/tuple/Triple.java
index f99f246..c52fd67 100644
--- a/src/main/java/org/apache/commons/lang3/tuple/Triple.java
+++ b/src/main/java/org/apache/commons/lang3/tuple/Triple.java
@@ -39,9 +39,6 @@ import org.apache.commons.lang3.builder.CompareToBuilder;
*/
public abstract class Triple<L, M, R> implements Comparable<Triple<L, M, R>>, Serializable {
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
private static final class TripleAdapter<L, M, R> extends Triple<L, M, R> {
private static final long serialVersionUID = 1L;
@@ -63,6 +60,9 @@ public abstract class Triple<L, M, R> implements Comparable<Triple<L, M, R>>, Se
}
+ /** Serialization version */
+ private static final long serialVersionUID = 1L;
+
/**
* An empty array.
* <p>
@@ -108,28 +108,6 @@ public abstract class Triple<L, M, R> implements Comparable<Triple<L, M, R>>, Se
//-----------------------------------------------------------------------
/**
- * <p>Gets the left element from this triple.</p>
- *
- * @return the left element, may be null
- */
- public abstract L getLeft();
-
- /**
- * <p>Gets the middle element from this triple.</p>
- *
- * @return the middle element, may be null
- */
- public abstract M getMiddle();
-
- /**
- * <p>Gets the right element from this triple.</p>
- *
- * @return the right element, may be null
- */
- public abstract R getRight();
-
- //-----------------------------------------------------------------------
- /**
* <p>Compares the triple based on the left element, followed by the middle element,
* finally the right element.
* The types must be {@code Comparable}.</p>
@@ -164,6 +142,28 @@ public abstract class Triple<L, M, R> implements Comparable<Triple<L, M, R>>, Se
return false;
}
+ //-----------------------------------------------------------------------
+ /**
+ * <p>Gets the left element from this triple.</p>
+ *
+ * @return the left element, may be null
+ */
+ public abstract L getLeft();
+
+ /**
+ * <p>Gets the middle element from this triple.</p>
+ *
+ * @return the middle element, may be null
+ */
+ public abstract M getMiddle();
+
+ /**
+ * <p>Gets the right element from this triple.</p>
+ *
+ * @return the right element, may be null
+ */
+ public abstract R getRight();
+
/**
* <p>Returns a suitable hash code.</p>
*