Package org.organicdesign.fp.tuple
Class Tuple2<A,B>
- java.lang.Object
-
- org.organicdesign.fp.tuple.Tuple2<A,B>
-
- All Implemented Interfaces:
java.io.Serializable,java.util.Map.Entry<A,B>,UnmodMap.UnEntry<A,B>
public class Tuple2<A,B> extends java.lang.Object implements java.util.Map.Entry<A,B>, UnmodMap.UnEntry<A,B>, java.io.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 fieldbooleanequals(java.lang.Object other)AgetKey()Returns the first field of the tuple.BgetValue()Returns the second field of the tuple.inthashCode()static <A,B>
Tuple2<A,B>of(A a, B b)Public static factory methodstatic <K,V>
Tuple2<K,V>of(java.util.Map.Entry<K,V> entry)Map.Entry factory methodBsetValue(B value)Deprecated.java.lang.StringtoString()
-
-
-
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
-
of
public static <K,V> Tuple2<K,V> of(java.util.Map.Entry<K,V> entry)
Map.Entry factory method
-
_1
public A _1()
Returns the 1st field
-
_2
public B _2()
Returns the 2nd field
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.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.
-
-