001package Torello.Java.Additional; 002 003/** 004 * This simple generic-class allows a function to return <B STYLE='color:red'>four</B> objects as a 005 * result, instead of just one. This is not always so useful, and can make code confusing. 006 * However there are some instances where the only alternative would be to create an entirely new 007 * class/object, when only a single method result would use that object. 008 * 009 * <EMBED CLASS=globalDefs DATA-KIND=Ret DATA-N=4> 010 * <EMBED CLASS='external-html' DATA-FILE-ID=IMMUTABLE_RET> 011 * @param <A> The type of the <B STYLE='color:red'>first</B> member-field ('{@link #a}'). 012 * @param <B> The type of the <B STYLE='color:red'>second</B> member-field ('{@link #b}'). 013 * @param <C> The type of the <B STYLE='color:red'>third</B> member-field ('{@link #c}'). 014 * @param <D> The type of the <B STYLE='color:red'>last</B> member-field ('{@link #d}'). 015 */ 016public class Ret4<A, B, C, D> 017 extends RetN 018 implements java.io.Serializable, Cloneable 019{ 020 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 021 protected 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 /** 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 * Returns {@code '4'}, indicating how many fields are declared by this class. 046 * @return As an instance of {@code Ret4}, this method returns {@code '4'}; 047 */ 048 public int n() { return 4; } 049 050 // Super-class uses this for toString, equals, and hashCode 051 // There is an optimization, so if this is requested multiple times, it is saved in a 052 // transient field. 053 054 final Object[] asArrayInternal() 055 { return new Object[] { a, b, c, d }; } 056 057 public Ret4<A, B, C, D> clone() 058 { return new Ret4<>(this.a, this.b, this.c, this.d); } 059 060 /** 061 * <EMBED CLASS=defs DATA-TEXT="Integer, Date, File"> 062 * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_EX_COMMON> 063 * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_GET_EXAMPLE> 064 */ 065 public Object get(final int i) 066 { 067 // Throws Exception if i not in [1..4] 068 CHECK_GET(i); 069 070 return (i <= 2) 071 ? ((i == 1) ? a : b) 072 : ((i == 3) ? c : d); 073 } 074 075 public Tuple4<A, B, C, D> toModifiable() 076 { return new Tuple4<>(this.a, this.b, this.c, this.d); } 077}