Package org.organicdesign.fp.tuple
Class Tuple2<A,B>
- java.lang.Object
-
- org.organicdesign.fp.tuple.Tuple2<A,B>
-
- All Implemented Interfaces:
Serializable
,Map.Entry<A,B>
,UnmodMap.UnEntry<A,B>
public class Tuple2<A,B> extends Object implements Map.Entry<A,B>, UnmodMap.UnEntry<A,B>, Serializable
Holds 2 items of potentially different types, and implements Map.Entry (and UnmodMap.UnEntry (there is no ImMap.ImEntry)). Designed to let you easily create immutable subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and toString() methods.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.organicdesign.fp.collections.UnmodMap.UnEntry
UnmodMap.UnEntry.EntryToUnEntryIter<K,V>, UnmodMap.UnEntry.EntryToUnEntrySortedIter<K,V>, UnmodMap.UnEntry.UnmodKeyIter<K,V>, UnmodMap.UnEntry.UnmodSortedKeyIter<K,V>, UnmodMap.UnEntry.UnmodSortedValIter<K,V>, UnmodMap.UnEntry.UnmodValIter<K,V>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description A
_1()
Returns the 1st fieldB
_2()
Returns the 2nd fieldboolean
equals(Object other)
A
getKey()
Returns the first field of the tuple.B
getValue()
Returns the second field of the tuple.int
hashCode()
static <A,B>
Tuple2<A,B>of(A a, B b)
Public static factory methodstatic <K,V>
Tuple2<K,V>of(Map.Entry<K,V> entry)
Map.Entry factory methodB
setValue(B value)
Deprecated.String
toString()
-
-
-
Constructor Detail
-
Tuple2
protected Tuple2(A a, B b)
Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public static factory methods are better than constructors because they have names, they can return an existing object instead of a new one, and they can return a sub-type. Therefore, you have more flexibility with a static factory as part of your public API then with a public constructor.
-
-
Method Detail
-
of
public static <A,B> Tuple2<A,B> of(A a, B b)
Public static factory method
-
_1
public A _1()
Returns the 1st field
-
_2
public B _2()
Returns the 2nd field
-
equals
public boolean equals(Object other)
-
hashCode
public int hashCode()
-
getKey
public A getKey()
Returns the first field of the tuple. To implement Map.Entry.
-
getValue
public B getValue()
Returns the second field of the tuple. To implement Map.Entry.
-
-