001package Torello.Java.Additional; 002 003import java.lang.reflect.Field; 004 005/** 006 * This simple generic-class allows for storing <B STYLE='color:red'>four</B> objects with a 007 * single reference. 008 * 009 * <EMBED CLASS=globalDefs DATA-KIND=Tuple DATA-N=4> 010 * <EMBED CLASS='external-html' DATA-FILE-ID=MUTABLE_TUPLE> 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 Tuple4<A, B, C, D> 017 extends TupleN 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 field / instance. */ 024 public A a; 025 026 /** This holds a pointer to the second field / instance. */ 027 public B b; 028 029 /** This holds a pointer to the third field / instance. */ 030 public C c; 031 032 /** This holds a pointer to the fourth field / instance. */ 033 public D d; 034 035 /** Constructs this object */ 036 public Tuple4(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 /** Constructs this object. Initializes all fields to null. */ 045 public Tuple4() 046 { 047 this.a = null; 048 this.b = null; 049 this.c = null; 050 this.d = null; 051 } 052 053 /** 054 * Returns {@code '4'}, indicating how many fields are declared by this class. 055 * @return As an instance of {@code Tuple4}, this method returns {@code '4'}; 056 */ 057 public int n() { return 4; } 058 059 // Super-class uses this for toString, equals, and hashCode 060 // There is an optimization, so if this is requested multiple times, it is saved in a 061 // transient field. 062 063 final Object[] asArrayInternal() 064 { return new Object[] { a, b, c, d }; } 065 066 public Tuple4<A, B, C, D> clone() 067 { return new Tuple4<>(this.a, this.b, this.c, this.d); } 068 069 /** 070 * <EMBED CLASS=defs DATA-TEXT="Integer, Date, File"> 071 * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_EX_COMMON> 072 * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_GET_EXAMPLE> 073 */ 074 public Object get(final int i) 075 { 076 // Throws Exception if i not in [1..4] 077 CHECK_GET(i); 078 079 return (i <= 2) 080 ? ((i == 1) ? a : b) 081 : ((i == 3) ? c : d); 082 } 083 084 public Ret4<A, B, C, D> toImmutable() 085 { return new Ret4<>(this.a, this.b, this.c, this.d); } 086}