United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4947273 : (coll) Create a standard Pair class (based on C++ pair class)

Details
Type:
Enhancement
Submit Date:
2003-10-31
Status:
Open
Updated Date:
2012-10-08
Project Name:
JDK
Resolved Date:
Component:
core-libs
OS:
generic,solaris_9
Sub-Component:
java.util:collections
CPU:
generic,sparc
Priority:
P4
Resolution:
Unresolved
Affected Versions:
1.4.2,6
Targeted Versions:

Related Reports
Duplicate:

Sub Tasks

Description

Name: rmT116609			Date: 10/31/2003


A DESCRIPTION OF THE REQUEST :
A standard pair class would assist developers who constantly write such helper classes.

JUSTIFICATION :
This class is simple to write and would go a long way towards making code more readable as we would not so many little classes which are all 99% the same. Also, could be the base class for other objects and replace Map.Entry which in my opinion should have been an immutable Pair object which would have simplified writing Map implementations, i.e. having an actual class instead of having to re-implement (which while easy is tiresome).

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would like pair classes that are mutable, immutable & thread-safe. I would also like second parameters to be optiunal based on either an inheritance model or something else. I also would like a pair that supports the Comparable interface. Note that equals(), hashCode() and toString() should be overridden and implemented to handle first and second.
ACTUAL -
Pair p = new Pair(new Integer(3), "abcde");
p.getFirst();
p.getSecond();
p.toString();

CUSTOMER SUBMITTED WORKAROUND :
I wrote my own pair class.

Pair - optional second
StrictPair - second required
MutablePair - mutable
ComparablePair - first and second are comparable and non-null
ThreadsafePair - mutable and thread-safe
(Incident Review ID: 218844) 
======================================================================

                                    

Comments



Hardware and Software, Engineered to Work Together