public class Tuples
extends java.lang.Object
A Tuple library to make it easy to return two or more values from a method.
Requires Java 1.5. To use do something like
Note that this is typesafe where returning an Object[] is not. Note that it
is always a good idea to consider making a real class for the return value.
Especially if you need a tuple of more than 4 values (only T2,T3 and T4 are
provided in this class) you probably should make it a real class.
import static com.gripstudios.utils.Tuples.*;
...
T2<Integer,String> foo(int x,int y){
return t2(y,new String(x));
}
...
The Tuple classes override equals to check the equality for each element of the tuples respectively. hashCode is also overridden so Tuples can safely be used in hashMaps. You may put nulls in tuples.
Note that tuples are immutable, you can't change the elements in them.
Instead create a new tuple, for example
T2<String,Integer> a=t2("aaa",2);
...
a=t2(a.e1,a.e2+1);
Note that t2("",new Vector()) will create a T2t2(String,(Collection)new Vector())
or
t2(String,(Collection<Integer>)new Vector())
to be more specific.
Modifier and Type | Class and Description |
---|---|
static class |
Tuples.T2<E1,E2> |
static class |
Tuples.T3<E1,E2,E3> |
static class |
Tuples.T4<E1,E2,E3,E4> |
static class |
Tuples.T5<E1,E2,E3,E4,E5> |
static class |
Tuples.T6<E1,E2,E3,E4,E5,E6> |
Modifier | Constructor and Description |
---|---|
private |
Tuples() |
Modifier and Type | Method and Description |
---|---|
private static boolean |
e(java.lang.Object o1,
java.lang.Object o2) |
static <E1,E2> Tuples.T2<E1,E2> |
t2(E1 e1,
E2 e2) |
static <E1,E2,E3> Tuples.T3<E1,E2,E3> |
t3(E1 e1,
E2 e2,
E3 e3) |
static <E1,E2,E3,E4> |
t4(E1 e1,
E2 e2,
E3 e3,
E4 e4) |
static <E1,E2,E3,E4,E5> |
t5(E1 e1,
E2 e2,
E3 e3,
E4 e4,
E5 e5) |
static <E1,E2,E3,E4,E5,E6> |
t6(E1 e1,
E2 e2,
E3 e3,
E4 e4,
E5 e5,
E6 e6) |
private static boolean e(java.lang.Object o1, java.lang.Object o2)
public static <E1,E2> Tuples.T2<E1,E2> t2(E1 e1, E2 e2)
public static <E1,E2,E3> Tuples.T3<E1,E2,E3> t3(E1 e1, E2 e2, E3 e3)
public static <E1,E2,E3,E4> Tuples.T4<E1,E2,E3,E4> t4(E1 e1, E2 e2, E3 e3, E4 e4)
public static <E1,E2,E3,E4,E5> Tuples.T5<E1,E2,E3,E4,E5> t5(E1 e1, E2 e2, E3 e3, E4 e4, E5 e5)
public static <E1,E2,E3,E4,E5,E6> Tuples.T6<E1,E2,E3,E4,E5,E6> t6(E1 e1, E2 e2, E3 e3, E4 e4, E5 e5, E6 e6)
Copyright 2004-2015 Wandora Team