001package Torello.Java.Additional; 002 003import java.lang.reflect.Field; 004 005/** 006 * This simple generic-class allows for storing <B STYLE='color:red'>six</B> objects with a 007 * single reference. 008 * 009 * <BR /><BR /><B CLASS=JDDescLabel>Field Name Change:</B> 010 * 011 * <BR />For the classes {@code Tuple6}, {@link Tuple7} & {@link Tuple8} - the field names 012 * include a number as well (see {@link #a1}, {@link #b2}, {@link #c3} etc...). This is simply due 013 * to the fact that these Field-Names become progressively more difficult to read or even look at 014 * after the first four or five letters - {@code 'a', 'b', 'c', 'd'} and {@code 'e'}. 015 * 016 * <EMBED CLASS=globalDefs DATA-KIND=Tuple DATA-N=6> 017 * <EMBED CLASS='external-html' DATA-FILE-ID=MUTABLE_TUPLE> 018 * @param <A1> The type of the <B STYLE='color:red'>first</B> member-field ('{@link #a1}'). 019 * @param <B2> The type of the <B STYLE='color:red'>second</B> member-field ('{@link #b2}'). 020 * @param <C3> The type of the <B STYLE='color:red'>third</B> member-field ('{@link #c3}'). 021 * @param <D4> The type of the <B STYLE='color:red'>fourth</B> member-field ('{@link #d4}'). 022 * @param <E5> The type of the <B STYLE='color:red'>fifth</B> member-field ('{@link #e5}'). 023 * @param <F6> The type of the <B STYLE='color:red'>last</B> member-field ('{@link #f6}'). 024 */ 025public class Tuple6<A1, B2, C3, D4, E5, F6> 026 extends TupleN 027 implements java.io.Serializable, Cloneable 028{ 029 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 030 protected static final long serialVersionUID = 1; 031 032 /** This holds a pointer the first field / instance. */ 033 public A1 a1; 034 035 /** This holds a pointer to the second field / instance. */ 036 public B2 b2; 037 038 /** This holds a pointer to the third field / instance. */ 039 public C3 c3; 040 041 /** This holds a pointer to the fourth field / instance. */ 042 public D4 d4; 043 044 /** This holds a pointer to the fifth field / instance. */ 045 public E5 e5; 046 047 /** This holds a pointer to the sixth field / instance. */ 048 public F6 f6; 049 050 /** Constructs this object */ 051 public Tuple6(A1 a1, B2 b2, C3 c3, D4 d4, E5 e5, F6 f6) 052 { 053 this.a1 = a1; 054 this.b2 = b2; 055 this.c3 = c3; 056 057 this.d4 = d4; 058 this.e5 = e5; 059 this.f6 = f6; 060 } 061 062 /** Constructs this object. Initializes all fields top null. */ 063 public Tuple6() 064 { 065 this.a1 = null; 066 this.b2 = null; 067 this.c3 = null; 068 069 this.d4 = null; 070 this.e5 = null; 071 this.f6 = null; 072 } 073 074 /** 075 * Returns {@code '6'}, indicating how many fields are declared by this class. 076 * @return As an instance of {@code Tuple6}, this method returns {@code '6'}; 077 */ 078 public int n() { return 6; } 079 080 // Super-class uses this for toString, equals, and hashCode 081 // There is an optimization, so if this is requested multiple times, it is saved in a 082 // transient field. 083 084 final Object[] asArrayInternal() 085 { return new Object[] { a1, b2, c3, d4, e5, f6 }; } 086 087 public Tuple6<A1, B2, C3, D4, E5, F6> clone() 088 { return new Tuple6<>(this.a1, this.b2, this.c3, this.d4, this.e5, this.f6); } 089 090 /** 091 * <EMBED CLASS=defs DATA-TEXT=""> 092 * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_EX_COMMON> 093 * <EMBED CLASS='external-html' DATA-FILE-ID=MULTI_TYPE_GET_EX_6_8> 094 */ 095 public Object get(final int i) 096 { 097 // Throws Exception if i not in [1..6] 098 CHECK_GET(i); 099 100 if (i <= 3) switch (i) 101 { 102 case 1: return a1; 103 case 2: return b2; 104 default: return c3; 105 } 106 107 else switch (i) 108 { 109 case 4: return d4; 110 case 5: return e5; 111 default: return f6; 112 } 113 } 114 115 public Ret6<A1, B2, C3, D4, E5, F6> toImmutable() 116 { return new Ret6<>(this.a1, this.b2, this.c3, this.d4, this.e5, this.f6); } 117}