commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (Resolved) (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (LANG-675) Add Triplet class (similar to Pair)
Date Thu, 24 Nov 2011 06:21:39 GMT

     [ https://issues.apache.org/jira/browse/LANG-675?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Henri Yandell resolved LANG-675.
--------------------------------

       Resolution: Fixed
    Fix Version/s:     (was: 3.x)
                   3.2

svn ci -m "Adding Henning's GitHub pull request with a Triple implementation. LANG-675"
Adding         src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java
Adding         src/main/java/org/apache/commons/lang3/tuple/MutableTriple.java
Adding         src/main/java/org/apache/commons/lang3/tuple/Triple.java
Sending        src/site/changes/changes.xml
Adding         src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java
Adding         src/test/java/org/apache/commons/lang3/tuple/MutableTripleTest.java
Adding         src/test/java/org/apache/commons/lang3/tuple/TripleTest.java
Transmitting file data .......
Committed revision 1205734.

                
> 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.2
>
>
> 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

        

Mime
View raw message