[ https://issues.apache.org/jira/browse/LANG-675?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13156545#comment-13156545 ]
Henri Yandell commented on LANG-675: ------------------------------------ See Henning's patch at: https://github.com/apache/commons-lang/pull/1 > Add Triplet class (similar to Pair) > ----------------------------------- > > Key: LANG-675 > URL: https://issues.apache.org/jira/browse/LANG-675 > Project: Commons Lang > Issue Type: New Feature > Components: lang.* > Reporter: Axel Fontaine > Fix For: 3.x > > > Similar to Pair, a Triplet is a common need. > Here is an adaptation of the commons-lang Pair that also takes a middle > argument: > import java.io.Serializable; > import org.apache.commons.lang.ObjectUtils; > import org.apache.commons.lang.builder.HashCodeBuilder; > /** > * Similar to Pair, using 3 instead of 2 Objects. > * > * @param <L> > * The "left" object of the triplet. > * @param <M> > * The "middle" object of the triplet. > * @param <R> > * The "right" object of the triplet. > */ > public final class Triplet<L, M, R> implements Serializable { > /** Serialization version */ > private static final long serialVersionUID = -8359217847916721612L; > /** > * Static fluent creation method for a Pair<L, R>: <code>Pair.of(left, > right)</code> > * > * @param <L> > * The "left" object of the triplet. > * @param <M> > * The "middle" object of the triplet. > * @param <R> > * The "right" object of the triplet. > * > * @param left > * The "left" object of the triplet. > * @param middle > * The "middle" object of the triplet. > * @param right > * The "right" object of the triplet. > * > * @return The newly created triplet. > */ > public static <L, M, R> Triplet<L, M, R> of(final L left, final M middle, > final R right) { > return new Triplet<L, M, R>(left, middle, right); > } > /** Left object */ > public final L left; > /** Middle object */ > public final M middle; > /** Right object */ > public final R right; > /** > * Create a new Triplet instance > * > * @param left > * the left object > * @param middle > * The "middle" object of the triplet. > * @param right > * the right object > */ > public Triplet(final L left, final M middle, final R right) { > this.left = left; > this.middle = middle; > this.right = right; > } > /** > * {@inheritDoc} > * > * @see java.lang.Object#equals(java.lang.Object) > */ > @Override > public boolean equals(final Object obj) { > if (obj == this) { > return true; > } > if (obj instanceof Triplet<?, ?, ?> == false) { > return false; > } > final Triplet<?, ?, ?> other = (Triplet<?, ?, ?>) obj; > return ObjectUtils.equals(this.left, other.left) && > ObjectUtils.equals(this.middle, other.middle) > && ObjectUtils.equals(this.right, other.right); > } > /** > * {@inheritDoc} > * > * @see java.lang.Object#hashCode() > */ > @Override > public int hashCode() { > return new > HashCodeBuilder().append(this.left).append(this.middle).append(this.right).toHashCode(); > } > /** > * Returns a String representation of the Pair in the form: (L,R) > * > * {@inheritDoc} > * > * @see java.lang.Object#toString() > */ > @Override > public String toString() { > return new > StringBuilder().append("(").append(this.left).append(",").append(this.middle).append(",") > .append(this.right).append(")").toString(); > } > Feel free to use it if you wish to include it. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira