001package Torello.Java.Additional;
002
003/**
004 * This simple generic-class allows a function to return <B STYLE='color:red'>six</B> objects as a
005 * result, instead of just one.   This is not always so useful, and can make code confusing.
006 * However there are some instances where the only alternative would be to create an entirely new
007 * class/object, when only a single method result would use that object.
008 *
009 * <BR /><BR /><B CLASS=JDDescLabel>Field Name Change:</B>
010 * 
011 * <BR />For the classes {@code Ret6}, {@link Ret7} &amp; {@link Ret8} - the field names include a
012 * number as well (see {@link #a1}, {@link #b2}, {@link #c3} etc...).  This is simply due to the
013 * fact that these Field-Names become progressively more difficult to read or even look at after
014 * the first four or five letters - {@code 'a', 'b', 'c', 'd'} and {@code 'e'}.
015 * 
016 * <EMBED CLASS=globalDefs DATA-KIND=Ret DATA-N=6>
017 * <EMBED CLASS='external-html' DATA-FILE-ID=IMMUTABLE_RET>
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'>last</B> member-field ('{@link #f6}').
024 */
025public class Ret6<A1, B2, C3, D4, E5, F6>
026    extends RetN
027    implements java.io.Serializable, Cloneable
028{
029    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID>  */
030    protected static final long serialVersionUID = 1;
031
032    /** This holds a pointer the first response object. */
033    public final A1 a1;
034
035    /** This holds a pointer to the second response object. */
036    public final B2 b2;
037
038    /** This holds a pointer to the third response object. */
039    public final C3 c3;
040
041    /** This holds a pointer to the fourth response object. */
042    public final D4 d4;
043
044    /** This holds a pointer to the fifth response object. */
045    public final E5 e5;
046
047    /** This holds a pointer to the sixth response object. */
048    public final F6 f6;
049
050    /** Constructs this object */
051    public Ret6(A1 a1, B2 b2, C3 c3, D4 d4, E5 e5, F6 f6)
052    {
053        this.a1 = a1;
054        this.b2 = b2;
055        this.c3 = c3;
056
057        this.d4 = d4;
058        this.e5 = e5;
059        this.f6 = f6;
060    }
061
062    /**
063     * Returns {@code '6'}, indicating how many fields are declared by this class.
064     * @return As an instance of {@code Ret6}, this method returns {@code '6'};
065     */
066    public int n() { return 6; }
067
068    // Super-class uses this for toString, equals, and hashCode
069    // There is an optimization, so if this is requested multiple times, it is saved in a
070    // transient field.
071
072    final Object[] asArrayInternal()
073    { return new Object[] { a1, b2, c3, d4, e5, f6 }; }
074
075    public Ret6<A1, B2, C3, D4, E5, F6> clone()
076    { return new Ret6<>(this.a1, this.b2, this.c3, this.d4, this.e5, this.f6); }
077
078    /**
079     * <EMBED CLASS=defs DATA-TEXT="">
080     * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_EX_COMMON>
081     * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_GET_EX_6_8>
082     */
083    public Object get(final int i)
084    {
085        // Throws Exception if i not in [1..6]
086        CHECK_GET(i);
087
088        if (i <= 3) switch (i)
089        {
090            case 1:     return a1;
091            case 2:     return b2;
092            default:    return c3;
093        }
094
095        else switch (i)
096        {
097            case 4:     return d4;
098            case 5:     return e5;
099            default:    return f6;
100        }
101    }
102
103    public Tuple6<A1, B2, C3, D4, E5, F6> toModifiable()
104    { return new Tuple6<>(this.a1, this.b2, this.c3, this.d4, this.e5, this.f6); }
105}