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