001package Torello.Java.Additional;
002
003import java.lang.reflect.Field;
004
005/**
006 * This simple generic-class allows for storing <B STYLE='color:red'>eight</B> objects with a 
007 * single reference.
008 *
009 * <BR /><BR /><B CLASS=JDDescLabel>Field Name Change:</B>
010 * 
011 * <BR />For the classes {@link Tuple6}, {@link Tuple7} &amp; {@code Tuple8} - the field names
012 * include a number as well (see {@link #a1}, {@link #b2}, {@link #c3} etc...).  This is simply due
013 * to the fact that these Field-Names become progressively more difficult to read or even look at
014 * after the first four or five letters - {@code 'a', 'b', 'c', 'd'} and {@code 'e'}.
015 * 
016 * <EMBED CLASS=globalDefs DATA-KIND=Tuple DATA-N=8>
017 * <EMBED CLASS='external-html' DATA-FILE-ID=MUTABLE_TUPLE>
018 * @param <A1> The type of the <B STYLE='color:red'>first</B> member-field ('{@link #a1}').
019 * @param <B2> The type of the <B STYLE='color:red'>second</B> member-field ('{@link #b2}').
020 * @param <C3> The type of the <B STYLE='color:red'>third</B> member-field ('{@link #c3}').
021 * @param <D4> The type of the <B STYLE='color:red'>fourth</B> member-field ('{@link #d4}').
022 * @param <E5> The type of the <B STYLE='color:red'>fifth</B> member-field ('{@link #e5}').
023 * @param <F6> The type of the <B STYLE='color:red'>sixth</B> member-field ('{@link #f6}').
024 * @param <G7> The type of the <B STYLE='color:red'>seventh</B> member-field ('{@link #g7}').
025 * @param <H8> The type of the <B STYLE='color:red'>last</B> member-field ('{@link #h8}').
026 */
027public class Tuple8<A1, B2, C3, D4, E5, F6, G7, H8>
028    extends TupleN
029    implements java.io.Serializable, Cloneable
030{
031    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID>  */
032    protected static final long serialVersionUID = 1;
033
034    /** This holds a pointer the first field / instance. */
035    public A1 a1;
036
037    /** This holds a pointer to the second field / instance. */
038    public B2 b2;
039
040    /** This holds a pointer to the third field / instance. */
041    public C3 c3;
042
043    /** This holds a pointer to the fourth field / instance. */
044    public D4 d4;
045
046    /** This holds a pointer to the fifth field / instance. */
047    public E5 e5;
048
049    /** This holds a pointer to the sixth field / instance. */
050    public F6 f6;
051
052    /** This holds a pointer to the seventh field / instance. */
053    public G7 g7;
054
055    /** This holds a pointer to the seventh field / instance. */
056    public H8 h8;
057
058    /** Constructs this object */
059    public Tuple8(A1 a1, B2 b2, C3 c3, D4 d4, E5 e5, F6 f6, G7 g7, H8 h8)
060    {
061        this.a1 = a1;
062        this.b2 = b2;
063        this.c3 = c3;
064        this.d4 = d4;
065
066        this.e5 = e5;
067        this.f6 = f6;
068        this.g7 = g7;
069        this.h8 = h8;
070    }
071
072    /** Constructs this object.  Initializes all fields to null. */
073    public Tuple8()
074    {
075        this.a1 = null;
076        this.b2 = null;
077        this.c3 = null;
078        this.d4 = null;
079
080        this.e5 = null;
081        this.f6 = null;
082        this.g7 = null;
083        this.h8 = null;
084    }
085
086    /**
087     * Returns {@code '8'}, indicating how many fields are declared by this class.
088     * @return As an instance of {@code Tuple8}, this method returns {@code '8'};
089     */
090    public int n() { return 8; }
091
092    // Super-class uses this for toString, equals, and hashCode
093    // There is an optimization, so if this is requested multiple times, it is saved in a
094    // transient field.
095
096    final Object[] asArrayInternal()
097    { return new Object[] { a1, b2, c3, d4, e5, f6, g7, h8 }; }
098
099    public Tuple8<A1, B2, C3, D4, E5, F6, G7, H8> clone()
100    {
101        return new Tuple8<>
102            (this.a1, this.b2, this.c3, this.d4, this.e5, this.f6, this.g7, this.h8);
103    }
104
105    /**
106     * <EMBED CLASS=defs DATA-TEXT=", TagNode, TextNode">
107     * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_EX_COMMON>
108     * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_GET_EX_6_8>
109     */
110    public Object get(final int i)
111    {
112        // Throws Exception if i not in [1..8]
113        CHECK_GET(i);
114
115        if (i <= 4) switch (i)
116        {
117            case 1:     return a1;
118            case 2:     return b2;
119            case 3:     return c3;
120            default:    return d4;
121        }
122
123        else switch (i)
124        {
125            case 5:     return e5;
126            case 6:     return f6;
127            case 7:     return g7;
128            default:    return h8;
129        }
130    }
131
132    public Ret8<A1, B2, C3, D4, E5, F6, G7, H8> toImmutable()
133    {
134        return new Ret8<>
135            (this.a1, this.b2, this.c3, this.d4, this.e5, this.f6, this.g7, this.h8);
136    }
137}