001package Torello.Java.Additional;
002
003import Torello.Java.StringParse;
004
005/**
006 * <CODE>Ret4 - Documentation.</CODE><BR /><BR />
007 * 
008 * This simple generic-class allows a function to return four objects as a result, instead of just
009 * one.   This is not always so useful, and can make code confusing.  However there are some
010 * instances where the only alternative would be to create an entirely new class/object, when only
011 * a single method result would use that object.
012 * 
013 * @param <A> The type of the first member-field ({@code 'a'}).
014 * @param <B> The type of the second member-field ({@code 'b'}).
015 * @param <C> The type of the third member-field ({@code 'c'}).
016 * @param <D> The type of the last member-field ({@code 'd'}).
017 */
018public class Ret4<A, B, C, D> implements java.io.Serializable
019{
020    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID>  */
021    public static final long serialVersionUID = 1;
022
023    /** This holds a pointer the first response object. */
024    public final A a;
025
026    /** This holds a pointer to the second response object. */
027    public final B b;
028
029    /** This holds a pointer to the third response object. */
030    public final C c;
031
032    /** This holds a pointer to the fourth response object. */
033    public final D d;
034
035    /** This constructs this object */
036    public Ret4(A a, B b, C c, D d)
037    {
038        this.a = a;
039        this.b = b;
040        this.c = c;
041        this.d = d;
042    }
043
044    /**
045     * Converts this instance of {@code Ret4} to a {@code String}.
046     * @return This instance-object as a {@code String}.
047     */
048    public String toString()
049    {
050        String[] types = new String[4];
051        types[0] = a.getClass().getSimpleName();
052        types[1] = b.getClass().getSimpleName();
053        types[2] = c.getClass().getSimpleName();
054        types[3] = d.getClass().getSimpleName();
055
056        int maxLen  = types[0].length();
057        int len     = 0;
058        for (int i=1; i < 4; i++) if ((len = types[i].length()) > maxLen) maxLen = len;
059
060        maxLen += 2;
061
062        return
063            "Ret4.a: " + StringParse.rightSpacePad(types[0], maxLen) +
064            (a.getClass().isArray()
065                ? RetHelper.toArrayString(a, types[0])
066                : RetHelper.indentIfNeeded(a.toString())) + '\n' +
067            "Ret4.b: " + StringParse.rightSpacePad(types[1], maxLen) +
068            (b.getClass().isArray()
069                ? RetHelper.toArrayString(b, types[1])
070                : RetHelper.indentIfNeeded(b.toString())) + '\n' +
071            "Ret4.c: " + StringParse.rightSpacePad(types[2], maxLen) +
072            (c.getClass().isArray()
073                ? RetHelper.toArrayString(c, types[2])
074                : RetHelper.indentIfNeeded(c.toString())) + '\n' +
075            "Ret4.d: " + StringParse.rightSpacePad(types[3], maxLen) +
076            (d.getClass().isArray()
077                ? RetHelper.toArrayString(d, types[3])
078                : RetHelper.indentIfNeeded(d.toString()));
079    }
080
081}