001package Torello.Java.Additional;
002
003
004/**
005 * This simple generic-class allows a function to return <B STYLE='color:red'>two</B> objects as a
006 * result, instead of just one.   This is not always so useful, and can make code confusing.
007 * However there are some instances where the only alternative would be to create an entirely new 
008 * class/object, when only a single method result would use that object.
009 * 
010 * @param <A> The type of the <B STYLE='color:red'>first</B> member-field ({@code 'a'}).
011 * @param <B> The type of the <B STYLE='color:red'>second</B> member-field ({@code 'b'}).
012 */
013public class Ret2<A, B>
014    extends RetN
015    implements java.io.Serializable, Cloneable
016{
017    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID>  */
018    protected static final long serialVersionUID = 1;
019
020    /** This holds a pointer the first response object. */
021    public final A a;
022
023    /** This holds a pointer to the second response object. */
024    public final B b;
025
026    /** Constructs this object */
027    public Ret2(A a, B b)
028    {
029        this.a = a;
030        this.b = b;
031    }
032
033    /**
034     * Returns {@code '2'}, indicating how many fields are declared by this class.
035     * 
036     * @return As in instance of {@code Ret2}, this method returns {@code '2'};
037     */
038    public int n() { return 2; }
039
040    // Super-class uses this for toString, equals, and hashCode
041    // There is an optimization, so if this is requested multiple times, it is saved in a
042    // transient field.
043
044    final Object[] asArrayInternal()
045    { return new Object[] { a, b }; }
046
047    /**
048     * Fulfills Java's {@code interface Cloneable} requirements.
049     * 
050     * @return A copy of {@code 'this'} instance of {@code Ret2}.
051     */
052    public Ret2<A, B> clone()
053    { return new Ret2<>(this.a, this.b); }
054
055}