001package Torello.Java.Additional;
002
003import java.lang.reflect.Field;
004
005/**
006 * This simple generic-class allows for storing <B STYLE='color:red'>five</B> objects with a 
007 * single reference.
008 *
009 * <EMBED CLASS=globalDefs DATA-KIND=Tuple DATA-N=5>
010 * <EMBED CLASS='external-html' DATA-FILE-ID=MUTABLE_TUPLE>
011 * @param <A> The type of the <B STYLE='color:red'>first</B> member-field ('{@link #a}').
012 * @param <B> The type of the <B STYLE='color:red'>second</B> member-field ('{@link #b}').
013 * @param <C> The type of the <B STYLE='color:red'>third</B> member-field ('{@link #c}').
014 * @param <D> The type of the <B STYLE='color:red'>fourth</B> member-field ('{@link #d}').
015 * @param <E> The type of the <B STYLE='color:red'>last</B> member-field ('{@link #e}').
016 */
017public class Tuple5<A, B, C, D, E>
018    extends TupleN
019    implements java.io.Serializable, Cloneable
020{
021    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID>  */
022    protected static final long serialVersionUID = 1;
023
024    /** This holds a pointer the first field / instance. */
025    public A a;
026
027    /** This holds a pointer to the second field / instance. */
028    public B b;
029
030    /** This holds a pointer to the third field / instance. */
031    public C c;
032
033    /** This holds a pointer to the fourth field / instance. */
034    public D d;
035
036    /** This holds a pointer to the fifth field / instance. */
037    public E e;
038
039    /** Constructs this object */
040    public Tuple5(A a, B b, C c, D d, E e)
041    {
042        this.a = a;
043        this.b = b;
044        this.c = c;
045        this.d = d;
046        this.e = e;
047    }
048
049    /** Constructs this object.  Initializes all fields to null. */
050    public Tuple5()
051    {
052        this.a = null;
053        this.b = null;
054        this.c = null;
055        this.d = null;
056        this.e = null;
057    }
058
059    /**
060     * Returns {@code '5'}, indicating how many fields are declared by this class.
061     * @return As an instance of {@code Tuple5}, this method returns {@code '5'};
062     */
063    public int n() { return 5; }
064
065    // Super-class uses this for toString, equals, and hashCode
066    // There is an optimization, so if this is requested multiple times, it is saved in a
067    // transient field.
068
069    final Object[] asArrayInternal()
070    { return new Object[] { a, b, c, d, e }; }
071
072    public Tuple5<A, B, C, D, E> clone()
073    { return new Tuple5<>(this.a, this.b, this.c, this.d, this.e); }
074
075    /**
076     * <EMBED CLASS=defs DATA-TEXT="Integer, Date, File, DotPair">
077     * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_EX_COMMON>
078     * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_GET_EXAMPLE>
079     */
080    public Object get(final int i)
081    {
082        // Throws Exception if i not in [1..5]
083        CHECK_GET(i);
084
085        if (i <= 3) switch (i)
086        {
087            case 1:     return a;
088            case 2:     return b;
089            default:    return c;
090        }
091
092        else return (i == 4) ? d : e;
093    }
094
095    public Ret5<A, B, C, D, E> toImmutable()
096    { return new Ret5<>(this.a, this.b, this.c, this.d, this.e); }
097}