Package Torello.Java.Additional
Class Tuple5<A,B,C,D,E>
- java.lang.Object
-
- Torello.Java.Additional.MultiType
-
- Torello.Java.Additional.TupleN
-
- Torello.Java.Additional.Tuple5<A,B,C,D,E>
-
- Type Parameters:
A
- The type of the first member-field ('a
').B
- The type of the second member-field ('b
').C
- The type of the third member-field ('c
').D
- The type of the fourth member-field ('d
').E
- The type of the last member-field ('e
').
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class Tuple5<A,B,C,D,E> extends TupleN implements java.io.Serializable, java.lang.Cloneable
This simple generic-class allows for storing five objects with a single reference.
Modifiable, Read-Write
Classes which inherit Ancestor-ClassTupleN
will always contains fields which are not declared using the'final'
modifier. These classes are, therefore, "Mutable Tuples" - meaning their contents may be changed whenever necessary.
Remember: The classesRet5
andTuple5
completely identical, with the sole difference being thatRet5
fields are all declared final, but theTuple5
fields are not!- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/Java/Additional/Tuple5.java
- Open New Browser-Tab: Torello/Java/Additional/Tuple5.java
File Size: 3,022 Bytes Line Count: 97 '\n' Characters Found
-
-
Method Summary
Retrieve the Number of Fields in this Class Modifier and Type Method int
n()
Retrieve a Field by Field-Number Modifier and Type Method Object
get(int i)
Convert this instance to an Immutable RetN instance, of the same size Modifier and Type Method Ret5<A,B,C,D,E>
toImmutable()
Methods: interface java.lang.Cloneable Modifier and Type Method Tuple5<A,B,C,D,E>
clone()
-
-
-
Field Detail
-
serialVersionUID
protected static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable
. Using theSerializable
Implementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
protected static final long serialVersionUID = 1;
-
a
-
b
-
c
-
d
-
e
-
-
Constructor Detail
-
Tuple5
-
Tuple5
public Tuple5()
Constructs this object. Initializes all fields to null.
-
-
Method Detail
-
n
-
clone
-
get
public java.lang.Object get(int i)
This method will retreive theith
field of this instance. This can be useful when you wish to use the Ancestor / Parent classses:TupleN
orMultiType
for handling'this'
instance.
As a reminder, the fields inside this class have all been declaredpublic
! Referencing this instance' fields, directly, will always work in place of calling any of theget(...)
methods.
Type Casting:
This method can make for easier typing. When using either of the super-classes of this class - namelyTupleN
orMultiType
- you simply do not have to type (into your computer's keyboard) all of the FieldGeneric Types
(the stuff between the'<'
and'>'
less-than & greater-than symbols).
However, anytime one of these ancestor classes are used instead of the actualTuple5
instance, you will have to use one of the provided'get'
methods to retrieve a field inside theTuple5
instance. This is because the parent-ancestor classes do not actually have any fields to retrieve.
There are three'get'
methods provided in Root-Ancestor ClassMultiType
. Each of these three 'getters' allows for casting (this) sub-class' returned fields in a slightly different way. When you aren't referencing the actual instance, itself, but rather one of the two Parent-Tuple Classes, you must use one of their getters, and you will have to cast the fields that you wish to use, eventually!
Example:
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // No Cast Necessary // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // This line makes for longer typing, but DOES NOT REQUIRE A CAST TO RETRIEVE FIELDS. // Here the example Multi-Type Identifier is used: Tuple5. Tuple5<String, Integer, Date, File, DotPair> ref5 = some_function_returns_5(); String neededStrField = ref5.a; // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Less Keyboard-Typing (Less Eyesores), but Requires a Cast // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // If the Tuple5 super-class TupleN is used to reference this class data, // YOU WILL NEED TO CAST THE FIELDS BEFORE YOU CAN THEM, AS IN THE EXAMPLES BELOW: TupleN refN = some_function_returns5(); // Version #1: (this method) - simple 'get' @SuppressWarnings("unchecked") String neededStrField = (String) refN.get(1); // Version #1: The second Method-Parameter is a 'Class<T>' Type-Parameter // Note, again, that passing a '1' to the first parameter retrieves Tuple5.a String neededStrField = refN.get(1, String.class); // Version #3: "GET" (in all caps) utilizes Java "Type-Inferencing" - the Return-Type // is specified by the left side of the assignments statement. String needesStrField = refN.GET(1);
- Specified by:
get
in classMultiType
- Parameters:
i
- This specifies which field of the instance is being requested.
IMPORTANT: Unlike a Java array, when a'1'
is passed to this parameter, it is requesting the first field in this instance. Passing a value of '0' shall cause anIndexOutOfBoundsException
throw.- Returns:
- This returns the
ith
field of this class. - See Also:
MultiType.get(int, Class)
,MultiType.GET(int)
- Code:
- Exact Method Body:
// Throws Exception if i not in [1..5] CHECK_GET(i); if (i <= 3) switch (i) { case 1: return a; case 2: return b; default: return c; } else return (i == 4) ? d : e;
-
toImmutable
public Ret5<A,B,C,D,E> toImmutable()
Description copied from class:TupleN
- Specified by:
toImmutable
in classTupleN
- Returns:
- A
RetN
of the same size, which is an immutable type whose fields have been decorated with the'final'
modifier - and therefore cannot be changed once the instance has been constructed. - Code:
- Exact Method Body:
return new Ret5<>(this.a, this.b, this.c, this.d, this.e);
-
-