001package Torello.Java.Additional;
002
003import Torello.Java.*;
004
005/**
006 * This is the parent class of the 'Multiple Return Type' classes. ({@code Ret0 ... Ret8}) 
007 * All classes which inherit {@code RetN} have ReadOnly, {@code final}, fields.
008 */
009public abstract class RetN extends MultiType
010{
011    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID>  */
012    protected static final long serialVersionUID = 1;
013
014    RetN() { }
015        // Cannot be private, because of the 'abstract' modifier
016        // Cannot be public (the auto-generated, zero-arg constructor is always public)
017        //      because then it makes my JavaDoc ugly
018
019    // Optimization: This is saved, so that it is only generated once by the descendant classes
020    // The 'transient' modifier implies that if an instance of, say "Ret3", is peristed using
021    // Object-serialization, this field will not be saved.
022
023    private transient Object[] objArr = null;
024
025    final Object[] asArrayMain()
026    {
027        // This variant-implementation of 'asArray' saves the returned array, since it only needs
028        // to be generated ONCE.  This is because all instances of "RetN" are Read-Only, which of
029        // course means their values can never change.  This means the array, once created, can be
030        // saved and returned if it is ever needed again.  This DOES NOT WORK for "TupleN" which is
031        // Read-Write.
032
033        if (this.objArr == null) this.objArr = asArrayInternal();
034        return this.objArr;        
035    }
036
037    /**
038     * Converts {@code 'this'} Read-Only {@code RetN} instance into a Read-Write {@link TupleN}.
039     * 
040     * @return A {@link TupleN} of the same size, which is a modifiable type whose fields are not 
041     * decorated with the {@code 'final'} modifier - <I>as the fields in this class are</I>.
042     */
043    public abstract TupleN toModifiable();
044}