You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Matt Benson (JIRA)" <ji...@apache.org> on 2010/02/06 21:45:27 UTC

[jira] Created: (LANG-588) Create a basic Pair class

Create a basic Pair<L, R> class
-------------------------------

                 Key: LANG-588
                 URL: https://issues.apache.org/jira/browse/LANG-588
             Project: Commons Lang
          Issue Type: New Feature
          Components: lang.*
            Reporter: Matt Benson
             Fix For: 3.0


[lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Created: (LANG-588) Create a basic Pair class

Posted by Henri Yandell <fl...@gmail.com>.
I can contribute
http://www.osjava.org/genjava/multiproject/gj-core/xref/com/generationjava/util/Pair.html
if you want to start from something different to help avoid IP issues.

It was written while reading a Lisp book years ago, thus some of the
naming. Because I wasn't using it in anywhere production I didn't both
sending in Lang's direction.

Hen

On Sat, Feb 6, 2010 at 12:45 PM, Matt Benson (JIRA) <ji...@apache.org> wrote:
> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

[jira] Closed: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed LANG-588.
------------------------------

    Resolution: Fixed

svn ci -m "Adding toString test. LANG-588"
Sending        src/test/java/org/apache/commons/lang3/PairTest.java
Transmitting file data .
Committed revision 916099.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, Pair.java, PairTest.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12838167#action_12838167 ] 

Henri Yandell commented on LANG-588:
------------------------------------

I also made the class final.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, Pair.java, PairTest.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830653#action_12830653 ] 

Henri Yandell edited comment on LANG-588 at 2/7/10 5:23 AM:
------------------------------------------------------------

It was for IP sake - I wrote it as an exercise instead of for any use. Happy to use yours instead.

Comments on your patches:

* Javadoc for pairOf/matchedPairOf needs filling in.
* @since should be '3.0' and not 'Lang 3.0'
* The static import in the tests makes me cringe, but I know you like using them. First time I looked at the code (as I looked at tests first) I went looking in the file to see where the utility pairOf method was, while wondering why you'd done such a thing.
* I'm not sure about the Iterable concept for MatchedPair. It could be in the parent as well as an Object iteration.
* I do like the notion of Iterable if it becomes a tree walker - i.e. it iterates down Pairs of Pairs. It could be:  depthFirstIterate() & breadthFirstIterate().
* Possibly some kind of construction parameter that sets the default to be depthFirst or breadthFirst. Or we could just declare one to be the default.

      was (Author: bayard):
    It was for IP sake - I wrote it as an exercise instead of for any use. Happy to use yours instead.

Comments on your patches:

* Javadoc for pairOf/matchedPairOf needs filling in.
* @since should be '3.0' and not 'Lang 3.0'
* The static import in the tests makes me cringe, but I know you like using them. First time I looked at the code (as I looked at tests first) I went looking in the file to see where the utility pairOf method was, while wondering why you'd done such a thing.
* I'm not sure about the Iterable concept for MatchedPair.
* I do like the notion of Iterable if it becomes a tree walker - i.e. it iterates down Pairs of Pairs. It could then be in the parent and could be:  depthFirstIterate() & breadthFirstIterate().
  
> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830659#action_12830659 ] 

Matt Benson edited comment on LANG-588 at 2/7/10 6:03 AM:
----------------------------------------------------------

I'll respond to your first three comments in order:

* RE Javadoc of static methods:  What are you looking for, beyond completing the @param tags such that checkstyle is happy?
* RE @since:  Okay.
* RE static imports:  don't know what to say; 'tis a matter of opinion.  If as a community we turn out to fall in favor of not using static imports I will abide.

WRT MatchedPair<T> as Iterable<T>, to be honest MatchedPair exists, in my mind, mostly because only when the L and R types of Pair are the same can we provide a typed Iterator.  As for the tree walker concept, that never occurred to me though I suppose I can see where you're coming from now that you mention it.  Perhaps your impression of a Pair as a LISP concept and my lack of similar background account for the difference in perspective.  However, as you mentioned this would only really work if we sacrifice type-safety by making Pair Iterable<Object>, and in that case it could be argued that the whole notion of iterating over nested Iterables in depth-first or breadth-first fashion could be extracted to a completely separate class, and be a more versatile approach into the bargain, no?

In this case I'd be satisfied to drop MatchedPair as a class, drop Iterable from Pair, and move matchedPairOf to Pair.  Then I'd simply add:
{code}
    public static <T> Iterator<T> pairIterator(final Pair<? extends T, ? extends T> pair) {
        return new Iterator<T>() {
            private int index = -1;

            public boolean hasNext() {
                return index < 1;
            }

            public T next() {
                if (index >= 1) {
                    throw new NoSuchElementException();
                }
                return ++index == 0 ? pair.left : pair.right;
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
{code}

      was (Author: mbenson):
    I'll respond to your first three comments in order:

* RE Javadoc of static methods:  What are you looking for, beyond completing the @param tags such that checkstyle is happy?
* RE @since:  Okay.
* RE static imports:  don't know what to say; 'tis a matter of opinion.  If as a community we turn out to fall in favor of not using static imports I will abide.

WRT MatchedPair<T> as Iterable<T>, to be honest MatchedPair exists, in my mind, mostly because only when the L and R types of Pair are the same can we provide a typed Iterator.  As for the tree walker concept, that never occurred to me though I suppose I can see where you're coming from now that you mention it.  Perhaps your impression of a Pair as a LISP concept and my lack of similar background account for the difference in perspective.  However, as you mentioned this would only really work if we sacrifice type-safety by making Pair Iterable<Object>, and in that case it could be argued that the whole notion of iterating over nested Iterables in depth-first or breadth-first fashion could be extracted to a completely separate class, and be a more versatile approach into the bargain, no?
  
> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830659#action_12830659 ] 

Matt Benson commented on LANG-588:
----------------------------------

I'll respond to your first three comments in order:

* RE Javadoc of static methods:  What are you looking for, beyond completing the @param tags such that checkstyle is happy?
* RE @since:  Okay.
* RE static imports:  don't know what to say; 'tis a matter of opinion.  If as a community we turn out to fall in favor of not using static imports I will abide.

WRT MatchedPair<T> as Iterable<T>, to be honest MatchedPair exists, in my mind, mostly because only when the L and R types of Pair are the same can we provide a typed Iterator.  As for the tree walker concept, that never occurred to me though I suppose I can see where you're coming from now that you mention it.  Perhaps your impression of a Pair as a LISP concept and my lack of similar background account for the difference in perspective.  However, as you mentioned this would only really work if we sacrifice type-safety by making Pair Iterable<Object>, and in that case it could be argued that the whole notion of iterating over nested Iterables in depth-first or breadth-first fashion could be extracted to a completely separate class, and be a more versatile approach into the bargain, no?

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-588:
-------------------------------

    Attachment: PairTest.java
                Pair.java

Updating the Pair.java file. toString added, hashCode no longer uses cached value, pairOf method renamed to of.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, Pair.java, PairTest.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Benson updated LANG-588:
-----------------------------

    Attachment: MatchedPair.java

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Paul Benedict (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832093#action_12832093 ] 

Paul Benedict commented on LANG-588:
------------------------------------

I vote for T1 and T2.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12833164#action_12833164 ] 

Matt Benson commented on LANG-588:
----------------------------------

That would kind of kill the "pair members are final so let's access them via public final members" vibe, but I suppose we could put it to a vote if necessary... :|

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830713#action_12830713 ] 

Sebb commented on LANG-588:
---------------------------

Why do you need readObject()? Surely the hashCode could just be serialised along with the objects?

If readObject() really is needed, then hashCode needs to be made volatile.
Otherwise make it final.

I think it would be helpful to expand the class Javadoc to include some use cases for the class.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832056#action_12832056 ] 

Matt Benson commented on LANG-588:
----------------------------------

I'm not _that_ attached to L/R-left/right.  That said, I like left/right because they are short, sweet and monosyllabic.  They just feel good to me.  Happy to bikeshed about any other possibilities that roll off the keyboard in a similar way.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832107#action_12832107 ] 

Matt Benson commented on LANG-588:
----------------------------------

So do T1/T2 type variable names correspond to the Seussian thing1/thing2 nomenclature for you, Paul?

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830855#action_12830855 ] 

Henri Yandell commented on LANG-588:
------------------------------------

What's the value in being able to iterate (without looking like an Iterable) an item with 2 things in?

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832181#action_12832181 ] 

Matt Benson commented on LANG-588:
----------------------------------

I understand that, but apparently what I am not conveying is my assumption that the type parameters would carry a mnemonic correlation with the class members that carry the constituent parts of the Pair.  I would thus expect, perhaps:

left/right->L/R
a/b->A/B
x/y->X/Y
thing1/thing2->T1/T2

...and my more facetious suggestions are perhaps too ridiculous for this exercise.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Benson updated LANG-588:
-----------------------------

    Attachment:     (was: MatchedPair.java)

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Benson updated LANG-588:
-----------------------------

    Attachment: MatchedPair.java
                Pair.java

proposed Pair and MatchedPair code

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, Pair.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830636#action_12830636 ] 

Matt Benson commented on LANG-588:
----------------------------------

How much of the LISPy stuff do you want to keep?  Or are you just popping it in for IP's sake?

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Stephen Colebourne (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12836146#action_12836146 ] 

Stephen Colebourne commented on LANG-588:
-----------------------------------------

I should note that EnumSet and JSR-310 use Classname.of - its becoming a new standard. The benefit of static imports seems to wane by comparison. So, +1 to Pair.of()

As explained above this class shouldn't cache the hash code, as mutable objects might be stashed within.

I should say that I find the L/R notation perfectly acceptable for this class - it doesn't overly imply anything to me.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Benson updated LANG-588:
-----------------------------

    Attachment:     (was: Pair.java)

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12836235#action_12836235 ] 

Matt Benson commented on LANG-588:
----------------------------------

Okay, I know I said I was happy to bikeshed, but as it turns out I don't really feel that happy.  ;)  We now have seemingly too many divergent suggestions to achieve consensus.  By using interfaces we would also seem to give up a convenient place to keep our static factory methods.  I will additionally note that I will make no argument against emulating the emerging of() standard if indeed it is such (I'll take your word on this, Stephen).

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832079#action_12832079 ] 

Henri Yandell commented on LANG-588:
------------------------------------


Left/Right does imply tree/graph like structures are going to be built. Agreed on the niceness of the name though.

I think we do imply order in the Pair, especially with all the iteration conversation - how about First, Second?

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Paul Benedict (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831450#action_12831450 ] 

Paul Benedict commented on LANG-588:
------------------------------------

I would advise against the L and R mnemonic. It should just be T1 and T2 or U and V, etc. We shouldn't imply its usage.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12837706#action_12837706 ] 

Henri Yandell commented on LANG-588:
------------------------------------

I think consensus isn't lost.

I'm +1 to L/R. I think there's majority happiness there. Same for the name Pair. The iteration code is out by your own declaration.



> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831129#action_12831129 ] 

Matt Benson commented on LANG-588:
----------------------------------

@Stephen:  do you have a reason to say "List" specifically, or would Iterable satisfy you?  If so, it sounds like we're zeroing in on agreement.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Benson updated LANG-588:
-----------------------------

    Attachment:     (was: MatchedPairTest.java)

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Stephen Colebourne (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831373#action_12831373 ] 

Stephen Colebourne commented on LANG-588:
-----------------------------------------

I have no specific requirement for a List. However I would advise against an Iterable, simply because its not that widely accepted in other APIs.

The ability to merge pairs into a single list will be a requested feature I suspect.

As I said, I'm strongly against caching the hash code - premature optimisation and unsafe with mutable classes.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "gabriele renzi (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12836144#action_12836144 ] 

gabriele renzi commented on LANG-588:
-------------------------------------

FWIW, the Pair class we use on my $WORK is more or less the same (bar not caching the hashcode, I just xor the existing ones which should be usually ok) but there are two differences:
* pairOf is just of , which allows us to just write Pair.of(a,b). This also goes into the direection of behing more coherent with com.sun.tools.javac.util.Pair, although not compatile anyway
* can we have a proper toString method? :)

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830659#action_12830659 ] 

Matt Benson edited comment on LANG-588 at 2/7/10 6:16 AM:
----------------------------------------------------------

I'll respond to your first three comments in order:

* RE Javadoc of static methods:  What are you looking for, beyond completing the @param tags such that checkstyle is happy?
* RE @since:  Okay.
* RE static imports:  don't know what to say; 'tis a matter of opinion.  If as a community we turn out to fall in favor of not using static imports I will abide.

WRT MatchedPair<T> as Iterable<T>, to be honest MatchedPair exists, in my mind, mostly because only when the L and R types of Pair are the same can we provide a typed Iterator.  As for the tree walker concept, that never occurred to me though I suppose I can see where you're coming from now that you mention it.  Perhaps your impression of a Pair as a LISP concept and my lack of similar background account for the difference in perspective.  However, as you mentioned this would only really work if we sacrifice type-safety by making Pair Iterable<Object>, and in that case it could be argued that the whole notion of iterating over nested Iterables in depth-first or breadth-first fashion could be extracted to a completely separate class, and be a more versatile approach into the bargain, no?

In this case I'd be satisfied to drop MatchedPair as a class, and add to Pair:
{code}
    public static <T> Iterator<T> pairIterator(final Pair<? extends T, ? extends T> pair) {
        return new Iterator<T>() {
            private int index = -1;

            public boolean hasNext() {
                return index < 1;
            }

            public T next() {
                if (index >= 1) {
                    throw new NoSuchElementException();
                }
                return ++index == 0 ? pair.left : pair.right;
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
{code}

      was (Author: mbenson):
    I'll respond to your first three comments in order:

* RE Javadoc of static methods:  What are you looking for, beyond completing the @param tags such that checkstyle is happy?
* RE @since:  Okay.
* RE static imports:  don't know what to say; 'tis a matter of opinion.  If as a community we turn out to fall in favor of not using static imports I will abide.

WRT MatchedPair<T> as Iterable<T>, to be honest MatchedPair exists, in my mind, mostly because only when the L and R types of Pair are the same can we provide a typed Iterator.  As for the tree walker concept, that never occurred to me though I suppose I can see where you're coming from now that you mention it.  Perhaps your impression of a Pair as a LISP concept and my lack of similar background account for the difference in perspective.  However, as you mentioned this would only really work if we sacrifice type-safety by making Pair Iterable<Object>, and in that case it could be argued that the whole notion of iterating over nested Iterables in depth-first or breadth-first fashion could be extracted to a completely separate class, and be a more versatile approach into the bargain, no?

In this case I'd be satisfied to drop MatchedPair as a class, drop Iterable from Pair, and move matchedPairOf to Pair.  Then I'd simply add:
{code}
    public static <T> Iterator<T> pairIterator(final Pair<? extends T, ? extends T> pair) {
        return new Iterator<T>() {
            private int index = -1;

            public boolean hasNext() {
                return index < 1;
            }

            public T next() {
                if (index >= 1) {
                    throw new NoSuchElementException();
                }
                return ++index == 0 ? pair.left : pair.right;
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
{code}
  
> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Benson updated LANG-588:
-----------------------------

    Attachment: PairTest.java
                MatchedPair.java
                Pair.java

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Paul Benedict (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12833044#action_12833044 ] 

Paul Benedict commented on LANG-588:
------------------------------------

Should we provide a Pair<X, Y> interface as well as an implementation?

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Benson updated LANG-588:
-----------------------------

    Attachment:     (was: MatchedPair.java)

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12833242#action_12833242 ] 

Gary Gregory commented on LANG-588:
-----------------------------------

In the Smalltalk world, this was called an Association with a key and value, so in Java we could have Association<K,V>.

If you really care about providing immutable assocs, then you can a mutable and immutable interface.

I too have written and re-written many versions of this class through time. This is really a public version of what the JRE provides in the MapEntry class of course. I usually end up with Maps of Associations.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Stephen Colebourne (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830876#action_12830876 ] 

Stephen Colebourne commented on LANG-588:
-----------------------------------------

I wouldn't cache the hash code in this class. If the pair contains a mutable object, then the hash code of the mutable could change during the lifetime of the Pair, causing the Pair hash code to break. Just calculate the hash code on demand.

I'd also avoid MatchedPair if possible. I'd like to see Pair be final and immutable (dependent on contained data).

I don't especially see the value of the iterator per se, but having a way to convert a Pair to a list might be useful. That method could have an option to expand any pairs it finds (and this could be built on an iterator internally, rather than up front extraction...)

In general though, a [lang] Pair needs to be simple and non-religious :-)

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830860#action_12830860 ] 

Matt Benson commented on LANG-588:
----------------------------------

Yeah, I was originally thinking someone could choose to create the Iterable and delegate the Iterator creation to that method; instead now I am thinking of making the method return an Iterable with an option to return Iterables for nested Pairs.  This would probably work best for our hypothetical Depth/BreadthFirst iterations...

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832084#action_12832084 ] 

Matt Benson commented on LANG-588:
----------------------------------

Hmm... I could _live_ with those, but I'm not crazy about 'em...

Other possibilities, some siller than others:

a/b?
x/y?
thing1/thing2?
fric/frac?
dee/dum?
one/other?
him/her?

this and that would be nice if not for that little reserved word problem...

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830639#action_12830639 ] 

Matt Benson commented on LANG-588:
----------------------------------

Yeah, I've never yet taken the time to find out what all the fuss was about wrt LISP, though I plan to one day.  :)  I was basically ready to attach my proposed code as patches for discussion, having rewritten the basics quite quickly...

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Paul Benedict (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832176#action_12832176 ] 

Paul Benedict commented on LANG-588:
------------------------------------

They are type parameters. They correspond to type parameter 1 and type parameter 2.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830723#action_12830723 ] 

Matt Benson edited comment on LANG-588 at 2/7/10 4:25 PM:
----------------------------------------------------------

My concern regarding the hashCode, Seb, is that a different calculation may be gotten on different running VMs.  I am certainly open to making the field {{volatile}} if necessary, but TBH I don't see why it would be, unless it's possible for hashCode() be called (a) before the constructor has executed, or (b) before deserialization has completed.  Educate me here.  :)

      was (Author: mbenson):
    My concern regarding the hashCode, Seb, is that a different calculation may be gotten on different running VMs.  I'll add {{volatile}} as you suggest.
  
> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Benson updated LANG-588:
-----------------------------

    Attachment:     (was: MatchedPair.java)

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831145#action_12831145 ] 

Matt Benson commented on LANG-588:
----------------------------------

Actually I'm now having second thoughts about how much call there is for iterating Pairs ;) , and if there is there's a fairly quick way to do it already:
{code}
Pair<Integer, Double> pair = pairOf(10, 100d);
List<? extends Number> l = Arrays.asList(pair.left, pair.right);
{code}

So in this case, we could drop the iteration issue, calculate hashCode always, and be done?

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830634#action_12830634 ] 

Henri Yandell commented on LANG-588:
------------------------------------

I'll commit http://www.osjava.org/genjava/multiproject/gj-core/xref/com/generationjava/util/Pair.html and you can tweak/rewrite from there :)

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832084#action_12832084 ] 

Matt Benson edited comment on LANG-588 at 2/10/10 5:37 PM:
-----------------------------------------------------------

Hmm... I could _live_ with those, but I'm not crazy about 'em...

Other possibilities, some sillier than others:

a/b?
x/y?
thing1/thing2?
fric/frac?
dee/dum?
one/other?
him/her?

this and that would be nice if not for that little reserved word problem...

      was (Author: mbenson):
    Hmm... I could _live_ with those, but I'm not crazy about 'em...

Other possibilities, some siller than others:

a/b?
x/y?
thing1/thing2?
fric/frac?
dee/dum?
one/other?
him/her?

this and that would be nice if not for that little reserved word problem...
  
> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830723#action_12830723 ] 

Matt Benson commented on LANG-588:
----------------------------------

My concern regarding the hashCode, Seb, is that a different calculation may be gotten on different running VMs.  I'll add {{volatile}} as you suggest.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12838169#action_12838169 ] 

Henri Yandell commented on LANG-588:
------------------------------------

Noting that I applied the files in r916098.

Needing to add unit tests around the toString method before closing the issue.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: Pair.java, Pair.java, PairTest.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830653#action_12830653 ] 

Henri Yandell commented on LANG-588:
------------------------------------

It was for IP sake - I wrote it as an exercise instead of for any use. Happy to use yours instead.

Comments on your patches:

* Javadoc for pairOf/matchedPairOf needs filling in.
* @since should be '3.0' and not 'Lang 3.0'
* The static import in the tests makes me cringe, but I know you like using them. First time I looked at the code (as I looked at tests first) I went looking in the file to see where the utility pairOf method was, while wondering why you'd done such a thing.
* I'm not sure about the Iterable concept for MatchedPair.
* I do like the notion of Iterable if it becomes a tree walker - i.e. it iterates down Pairs of Pairs. It could then be in the parent and could be:  depthFirstIterate() & breadthFirstIterate().

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830774#action_12830774 ] 

Sebb commented on LANG-588:
---------------------------

The reason is visibility of the variable. 
There's no guarantee that a non-final variable set in one thread will be seen by other threads in the absence of some form of synch.

It's unlikely that the problem will occur, but it's possible, and will be extremely hard to track down if it does.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-588) Create a basic Pair class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830637#action_12830637 ] 

Henri Yandell commented on LANG-588:
------------------------------------

One question is whether the weighting concept is desirable or should be removed. i.e. that less of a Pair and more of a weighted Split. I suspect it could be deleted.

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-588) Create a basic Pair class

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-588?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Benson updated LANG-588:
-----------------------------

    Attachment: MatchedPairTest.java

> Create a basic Pair<L, R> class
> -------------------------------
>
>                 Key: LANG-588
>                 URL: https://issues.apache.org/jira/browse/LANG-588
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Matt Benson
>             Fix For: 3.0
>
>         Attachments: MatchedPair.java, MatchedPairTest.java, Pair.java, PairTest.java
>
>
> [lang] is the perfect place to provide a basic typed Pair class.  I have written such a class for my employer (who hasn't?) but can/will rewrite blind to avoid IP issues.  I think it's also nice to go ahead and extend this to MatchedPair<T> extends Pair<T, T> as well.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.