001package Torello.Java.Additional;
002
003import java.lang.reflect.Field;
004
005/**
006 * This simple generic-class allows for storing <B STYLE='color:red'>seven</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}, {@code Tuple7} &amp; {@link 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=7>
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'>last</B> member-field ('{@link #g7}').
025 */
026public class Tuple7<A1, B2, C3, D4, E5, F6, G7>
027    extends TupleN
028    implements java.io.Serializable, Cloneable
029{
030    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID>  */
031    protected static final long serialVersionUID = 1;
032
033    /** This holds a pointer the first field / instance. */
034    public A1 a1;
035
036    /** This holds a pointer to the second field / instance. */
037    public B2 b2;
038
039    /** This holds a pointer to the third field / instance. */
040    public C3 c3;
041
042    /** This holds a pointer to the fourth field / instance. */
043    public D4 d4;
044
045    /** This holds a pointer to the fifth field / instance. */
046    public E5 e5;
047
048    /** This holds a pointer to the sixth field / instance. */
049    public F6 f6;
050
051    /** This holds a pointer to the seventh field / instance. */
052    public G7 g7;
053
054    /** Constructs this object */
055    public Tuple7(A1 a1, B2 b2, C3 c3, D4 d4, E5 e5, F6 f6, G7 g7)
056    {
057        this.a1 = a1;
058        this.b2 = b2;
059        this.c3 = c3;
060        this.d4 = d4;
061        this.e5 = e5;
062        this.f6 = f6;
063        this.g7 = g7;
064    }
065
066    /** Constructs this object.  Initializes all fields to null. */
067    public Tuple7()
068    {
069        this.a1 = null;
070        this.b2 = null;
071        this.c3 = null;
072        this.d4 = null;
073        this.e5 = null;
074        this.f6 = null;
075        this.g7 = null;
076    }
077
078    /**
079     * Returns {@code '7'}, indicating how many fields are declared by this class.
080     * @return As an instance of {@code Tuple7}, this method returns {@code '7'};
081     */
082    public int n() { return 7; }
083
084    // Super-class uses this for toString, equals, and hashCode
085    // There is an optimization, so if this is requested multiple times, it is saved in a
086    // transient field.
087
088    final Object[] asArrayInternal()
089    { return new Object[] { a1, b2, c3, d4, e5, f6, g7 }; }
090
091    public Tuple7<A1, B2, C3, D4, E5, F6, G7> clone()
092    { return new Tuple7<>(this.a1, this.b2, this.c3, this.d4, this.e5, this.f6, this.g7); }
093
094    /**
095     * <EMBED CLASS=defs DATA-TEXT=", TagNode">
096     * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_EX_COMMON>
097     * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_GET_EX_6_8>
098     */
099    public Object get(final int i)
100    {
101        // Throws Exception if i not in [1..7]
102        CHECK_GET(i);
103
104        if (i <= 4) switch (i)
105        {
106            case 1:     return a1;
107            case 2:     return b2;
108            case 3:     return c3;
109            default:    return d4;
110        }
111
112        else switch (i)
113        {
114            case 5:     return e5;
115            case 6:     return f6;
116            default:    return g7;
117        }
118    }
119
120    public Ret7<A1, B2, C3, D4, E5, F6, G7> toImmutable()
121    { return new Ret7<>(this.a1, this.b2, this.c3, this.d4, this.e5, this.f6, this.g7); }
122}