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
package Torello.Java.Additional;

import Torello.Java.*;

/**
 * This is the parent class of the 'Multiple Return Type' classes. ({@code Ret0 ... Ret8}) 
 * All classes which inherit {@code RetN} have ReadOnly, {@code final}, fields.
 */
public abstract class RetN extends MultiType
{
    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID>  */
    protected static final long serialVersionUID = 1;

    RetN() { }
        // Cannot be private, because of the 'abstract' modifier
        // Cannot be public (the auto-generated, zero-arg constructor is always public)
        //      because then it makes my JavaDoc ugly

    // Optimization: This is saved, so that it is only generated once by the descendant classes
    // The 'transient' modifier implies that if an instance of, say "Ret3", is peristed using
    // Object-serialization, this field will not be saved.

    private transient Object[] objArr = null;

    final Object[] asArrayMain()
    {
        // This variant-implementation of 'asArray' saves the returned array, since it only needs
        // to be generated ONCE.  This is because all instances of "RetN" are Read-Only, which of
        // course means their values can never change.  This means the array, once created, can be
        // saved and returned if it is ever needed again.  This DOES NOT WORK for "TupleN" which is
        // Read-Write.

        if (this.objArr == null) this.objArr = asArrayInternal();
        return this.objArr;        
    }

    /**
     * Converts {@code 'this'} Read-Only {@code RetN} instance into a Read-Write {@link TupleN}.
     * 
     * @return A {@link TupleN} of the same size, which is a modifiable type whose fields are not 
     * decorated with the {@code 'final'} modifier - <I>as the fields in this class are</I>.
     */
    public abstract TupleN toModifiable();
}