1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package Torello.Java.Additional;

/**
 * This simple Generic-Class exists mainly for the case where a function or Type-Parameter needs
 * to return a class that inherits {@link RetN}, but only has <B STYLE='color:red'>one</B>
 * return-value.  Outside of that particular scenario, there isn't much point to a {@code Ret1}
 * instance.
 * 
 * <EMBED CLASS=globalDefs DATA-KIND=Ret DATA-N=1>
 * <EMBED CLASS='external-html' DATA-N=1 DATA-FILE-ID=IMMUTABLE_RET>
 * @param <A> The type of the <B STYLE='color:red'>only</B> member-field ('{@link #a}').
 */
public class Ret1<A>
    extends RetN
    implements java.io.Serializable, Cloneable
{
    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID>  */
    protected static final long serialVersionUID = 1;

    /** This holds a pointer the first and only response object. */
    public final A a;

    /** Constructs this object */
    public Ret1(A a) { this.a = a; }

    /**
     * Returns {@code '1'}, indicating how many fields are declared by this class.
     * @return As an instance of {@code Ret1}, this method returns {@code '1'};
     */
    public int n() { return 1; }

    // Super-class uses this for toString, equals, and hashCode
    // There is an optimization, so if this is requested multiple times, it is saved in a
    // transient field.

    final Object[] asArrayInternal()
    { return new Object[] { a }; }

    public Ret1<A> clone()
    { return new Ret1<>(this.a); }

    /**
     * Returns this {@code Ret1} instance's only field - field {@link #a}.  This method may only
     * be invoked on an input value of {@code '1'}, or else it throws.  A {@code Ret1} instance
     * has only a single field that may be retrieved.
     * 
     * <BR /><BR />This method must be included to properly, fully, implement the ancestor 
     * {@link MultiType} interface.
     * 
     * @param i This must be passed {@code '1'}, or else this method throws IOOBEX.
     * 
     * @returns The reference contained by field {@link #a}.  If this method returns, its returned
     * type will always be {@link <A>}.
     * 
     * @throws IndexOutOfBoundsException As this {@code Ret1} instance has but a single field,
     * <I>this exceptions throws for all values of {@code 'i'} - except {@code '1'}</I>.
     */
    public A get(final int i)
    {
        if (i != 1) throw new IndexOutOfBoundsException(
            "This is an instance of Ret1, and therefore '1' is the only valid value which may " +
            "be passed to 'i'"
        );

        return a;
    }

    public Tuple1<A> toModifiable()
    { return new Tuple1<>(this.a); }
}