Sort methods.
This commit is contained in:
parent
13354cd132
commit
ffb8b29790
|
@ -43,6 +43,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.
|
||||
*
|
||||
|
@ -57,16 +67,6 @@ public final class ImmutablePair<L, R> extends Pair<L, R> {
|
|||
return (ImmutablePair<L, R>[]) EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -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.
|
||||
|
|
|
@ -44,6 +44,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.
|
||||
*
|
||||
|
@ -59,16 +69,6 @@ public final class ImmutableTriple<L, M, R> extends Triple<L, M, R> {
|
|||
return (ImmutableTriple<L, M, R>[]) EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
@ -104,6 +104,14 @@ public class MutablePair<L, R> extends Pair<L, R> {
|
|||
return left;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public R getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left element of the pair.
|
||||
*
|
||||
|
@ -113,14 +121,6 @@ public class MutablePair<L, R> extends Pair<L, R> {
|
|||
this.left = left;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public R getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right element of the pair.
|
||||
*
|
||||
|
|
|
@ -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,20 +113,28 @@ 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 left element of the triple.
|
||||
*
|
||||
* @param left the new value of the left element, may be null
|
||||
*/
|
||||
public void setLeft(final L left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,14 +146,6 @@ public class MutableTriple<L, M, R> extends Triple<L, M, R> {
|
|||
this.middle = middle;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public R getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right element of the triple.
|
||||
*
|
||||
|
|
|
@ -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>
|
||||
|
@ -104,51 +104,6 @@ public abstract class Pair<L, R> implements Map.Entry<L, R>, Comparable<Pair<L,
|
|||
return new ImmutablePair<>(left, right);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Gets the left element from this pair.</p>
|
||||
*
|
||||
* <p>When treated as a key-value pair, this is the key.</p>
|
||||
*
|
||||
* @return the left element, may be null
|
||||
*/
|
||||
public abstract L getLeft();
|
||||
|
||||
/**
|
||||
* <p>Gets the right element from this pair.</p>
|
||||
*
|
||||
* <p>When treated as a key-value pair, this is the value.</p>
|
||||
*
|
||||
* @return the right element, may be null
|
||||
*/
|
||||
public abstract R getRight();
|
||||
|
||||
/**
|
||||
* <p>Gets the key from this pair.</p>
|
||||
*
|
||||
* <p>This method implements the {@code Map.Entry} interface returning the
|
||||
* left element as the key.</p>
|
||||
*
|
||||
* @return the left element as the key, may be null
|
||||
*/
|
||||
@Override
|
||||
public final L getKey() {
|
||||
return getLeft();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Gets the value from this pair.</p>
|
||||
*
|
||||
* <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 R getValue() {
|
||||
return getRight();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Compares the pair based on the left element followed by the right element.
|
||||
|
@ -182,6 +137,51 @@ public abstract class Pair<L, R> implements Map.Entry<L, R>, Comparable<Pair<L,
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Gets the key from this pair.</p>
|
||||
*
|
||||
* <p>This method implements the {@code Map.Entry} interface returning the
|
||||
* left element as the key.</p>
|
||||
*
|
||||
* @return the left element as the key, may be null
|
||||
*/
|
||||
@Override
|
||||
public final L getKey() {
|
||||
return getLeft();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Gets the left element from this pair.</p>
|
||||
*
|
||||
* <p>When treated as a key-value pair, this is the key.</p>
|
||||
*
|
||||
* @return the left element, may be null
|
||||
*/
|
||||
public abstract L getLeft();
|
||||
|
||||
/**
|
||||
* <p>Gets the right element from this pair.</p>
|
||||
*
|
||||
* <p>When treated as a key-value pair, this is the value.</p>
|
||||
*
|
||||
* @return the right element, may be null
|
||||
*/
|
||||
public abstract R getRight();
|
||||
|
||||
/**
|
||||
* <p>Gets the value from this pair.</p>
|
||||
*
|
||||
* <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 R getValue() {
|
||||
return getRight();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns a suitable hash code.
|
||||
* The hash code follows the definition in {@code Map.Entry}.</p>
|
||||
|
|
|
@ -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>
|
||||
|
@ -106,28 +106,6 @@ public abstract class Triple<L, M, R> implements Comparable<Triple<L, M, R>>, Se
|
|||
return new ImmutableTriple<>(left, middle, right);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* <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,
|
||||
|
@ -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>
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue