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 fieldbooleanequals(Object other)AgetKey()Returns the first field of the tuple.BgetValue()Returns the second field of the tuple.inthashCode()static <A,B>
@NotNull Tuple2<A,B>of(A a, B b)Public static factory methodstatic <K,V>
@NotNull Tuple2<K,V>of(Map.Entry<K,V> entry)Map.Entry factory methodBsetValue(B value)Deprecated.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
@NotNull public static <A,B> @NotNull Tuple2<A,B> of(A a, B b)
Public static factory method
-
of
@NotNull public static <K,V> @NotNull Tuple2<K,V> of(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
-
equals
public boolean equals(Object other)
-
hashCode
public int hashCode()
-
getKey
@Contract(pure=true) public A getKey()
Returns the first field of the tuple. To implement Map.Entry.
-
getValue
@Contract(pure=true) public B getValue()
Returns the second field of the tuple. To implement Map.Entry.
-
-