1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | package Torello.Java.Additional; import java.lang.reflect.Field; /** * This simple generic-class allows for storing <B STYLE='color:red'>five</B> objects with a * single reference. * * <EMBED CLASS=globalDefs DATA-KIND=Tuple DATA-N=5> * <EMBED CLASS='external-html' DATA-FILE-ID=MUTABLE_TUPLE> * @param <A> The type of the <B STYLE='color:red'>first</B> member-field ('{@link #a}'). * @param <B> The type of the <B STYLE='color:red'>second</B> member-field ('{@link #b}'). * @param <C> The type of the <B STYLE='color:red'>third</B> member-field ('{@link #c}'). * @param <D> The type of the <B STYLE='color:red'>fourth</B> member-field ('{@link #d}'). * @param <E> The type of the <B STYLE='color:red'>last</B> member-field ('{@link #e}'). */ public class Tuple5<A, B, C, D, E> extends TupleN implements java.io.Serializable, Cloneable { /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ protected static final long serialVersionUID = 1; /** This holds a pointer the first field / instance. */ public A a; /** This holds a pointer to the second field / instance. */ public B b; /** This holds a pointer to the third field / instance. */ public C c; /** This holds a pointer to the fourth field / instance. */ public D d; /** This holds a pointer to the fifth field / instance. */ public E e; /** Constructs this object */ public Tuple5(A a, B b, C c, D d, E e) { this.a = a; this.b = b; this.c = c; this.d = d; this.e = e; } /** Constructs this object. Initializes all fields to null. */ public Tuple5() { this.a = null; this.b = null; this.c = null; this.d = null; this.e = null; } /** * Returns {@code '5'}, indicating how many fields are declared by this class. * @return As an instance of {@code Tuple5}, this method returns {@code '5'}; */ public int n() { return 5; } // Super-class uses this for toString, equals, and hashCode // There is an optimization, so if this is requested multiple times, it is saved in a // transient field. final Object[] asArrayInternal() { return new Object[] { a, b, c, d, e }; } public Tuple5<A, B, C, D, E> clone() { return new Tuple5<>(this.a, this.b, this.c, this.d, this.e); } /** * <EMBED CLASS=defs DATA-TEXT="Integer, Date, File, DotPair"> * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_EX_COMMON> * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_GET_EXAMPLE> */ public Object get(final int i) { // Throws Exception if i not in [1..5] CHECK_GET(i); if (i <= 3) switch (i) { case 1: return a; case 2: return b; default: return c; } else return (i == 4) ? d : e; } public Ret5<A, B, C, D, E> toImmutable() { return new Ret5<>(this.a, this.b, this.c, this.d, this.e); } } |