001package Torello.Java.Additional;
002
003/**
004 * This simple generic-class allows a function to return <B STYLE='color:red'>eight</B> objects as
005 * a 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 {@link Ret6}, {@link Ret7} &amp; {@code 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=8>
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'>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 Ret8<A1, B2, C3, D4, E5, F6, G7, H8>
028    extends RetN
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 response object. */
035    public final A1 a1;
036
037    /** This holds a pointer to the second response object. */
038    public final B2 b2;
039
040    /** This holds a pointer to the third response object. */
041    public final C3 c3;
042
043    /** This holds a pointer to the fourth response object. */
044    public final D4 d4;
045
046    /** This holds a pointer to the fifth response object. */
047    public final E5 e5;
048
049    /** This holds a pointer to the sixth response object. */
050    public final F6 f6;
051
052    /** This holds a pointer to the seventh response object. */
053    public final G7 g7;
054
055    /** This holds a pointer to the seventh response object. */
056    public final H8 h8;
057
058    /** Constructs this object */
059    public Ret8(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    /**
073     * Returns {@code '8'}, indicating how many fields are declared by this class.
074     * @return As an instance of {@code Ret8}, this method returns {@code '8'};
075     */
076    public int n() { return 8; }
077
078
079    // Super-class uses this for toString, equals, and hashCode
080    // There is an optimization, so if this is requested multiple times, it is saved in a
081    // transient field.
082
083    final Object[] asArrayInternal()
084    { return new Object[] { a1, b2, c3, d4, e5, f6, g7, h8 }; }
085
086    public Ret8<A1, B2, C3, D4, E5, F6, G7, H8> clone()
087    { return new Ret8<>(this.a1, this.b2, this.c3, this.d4, this.e5, this.f6, this.g7, this.h8); }
088
089    /**
090     * <EMBED CLASS=defs DATA-TEXT=", TagNode, TextNode">
091     * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_EX_COMMON>
092     * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_GET_EX_6_8>
093     */
094    public Object get(final int i)
095    {
096        // Throws Exception if i not in [1..8]
097        CHECK_GET(i);
098
099        if (i <= 4) switch (i)
100        {
101            case 1:     return a1;
102            case 2:     return b2;
103            case 3:     return c3;
104            default:    return d4;
105        }
106
107        else switch (i)
108        {
109            case 5:     return e5;
110            case 6:     return f6;
111            case 7:     return g7;
112            default:    return h8;
113        }
114    }
115
116    public Tuple8<A1, B2, C3, D4, E5, F6, G7, H8> toModifiable()
117    {
118        return new Tuple8<>
119            (this.a1, this.b2, this.c3, this.d4, this.e5, this.f6, this.g7, this.h8);
120    }
121}