001package Torello.Java.Additional; 002 003/** 004 * This simple generic-class allows a function to return <B STYLE='color:red'>five</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=5> 010 * <EMBED CLASS='external-html' DATA-N=5 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'>fourth</B> member-field ('{@link #d}'). 015 * @param <E> The type of the <B STYLE='color:red'>last</B> member-field ('{@link #e}'). 016 */ 017public class Ret5<A, B, C, D, E> 018 extends RetN 019 implements java.io.Serializable, Cloneable 020{ 021 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 022 protected static final long serialVersionUID = 1; 023 024 /** This holds a pointer the first response object. */ 025 public final A a; 026 027 /** This holds a pointer to the second response object. */ 028 public final B b; 029 030 /** This holds a pointer to the third response object. */ 031 public final C c; 032 033 /** This holds a pointer to the fourth response object. */ 034 public final D d; 035 036 /** This holds a pointer to the fifth response object. */ 037 public final E e; 038 039 /** Constructs this object */ 040 public Ret5(A a, B b, C c, D d, E e) 041 { 042 this.a = a; 043 this.b = b; 044 this.c = c; 045 this.d = d; 046 this.e = e; 047 } 048 049 /** 050 * Returns {@code '5'}, indicating how many fields are declared by this class. 051 * @return As an instance of {@code Ret5}, this method returns {@code '5'}; 052 */ 053 public int n() { return 5; } 054 055 056 // Super-class uses this for toString, equals, and hashCode 057 // There is an optimization, so if this is requested multiple times, it is saved in a 058 // transient field. 059 060 final Object[] asArrayInternal() 061 { return new Object[] { a, b, c, d, e }; } 062 063 public Ret5<A, B, C, D, E> clone() 064 { return new Ret5<>(this.a, this.b, this.c, this.d, this.e); } 065 066 /** 067 * <EMBED CLASS=defs DATA-TEXT="Integer, Date, File, DotPair"> 068 * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_EX_COMMON> 069 * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_GET_EXAMPLE> 070 */ 071 public Object get(final int i) 072 { 073 // Throws Exception if i not in [1..5] 074 CHECK_GET(i); 075 076 if (i <= 3) switch (i) 077 { 078 case 1: return a; 079 case 2: return b; 080 default: return c; 081 } 082 083 else return (i == 4) ? d : e; 084 } 085 086 public Tuple5<A, B, C, D, E> toModifiable() 087 { return new Tuple5<>(this.a, this.b, this.c, this.d, this.e); } 088}