Package Torello.Java.Additional
Class Ret6<A1,B2,C3,D4,E5,F6>
- java.lang.Object
-
- Torello.Java.Additional.MultiType
-
- Torello.Java.Additional.RetN
-
- Torello.Java.Additional.Ret6<A1,B2,C3,D4,E5,F6>
-
- Type Parameters:
A1
- The type of the first member-field ('a1
').B2
- The type of the second member-field ('b2
').C3
- The type of the third member-field ('c3
').D4
- The type of the fourth member-field ('d4
').E5
- The type of the fifth member-field ('e5
').F6
- The type of the last member-field ('f6
').
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class Ret6<A1,B2,C3,D4,E5,F6> extends RetN implements java.io.Serializable, java.lang.Cloneable
This simple generic-class allows a function to return six objects as a result, instead of just one. This is not always so useful, and can make code confusing. However there are some instances where the only alternative would be to create an entirely new class/object, when only a single method result would use that object.
Field Name Change:
For the classesRet6
,Ret7
&Ret8
- the field names include a number as well (seea1
,b2
,c3
etc...). This is simply due to the fact that these Field-Names become progressively more difficult to read or even look at after the first four or five letters -'a', 'b', 'c', 'd'
and'e'
.
Immutable, Read-Only
Classes which inherit Ancestor-ClassRetN
will always contains fields declared using the'final'
modifier. These classes are, therefore, "Unmodifiable Tuples" - meaning their contents can never change once they have been instantiated.
Remember: The classesRet6
andTuple6
completely identical, with the sole difference being thatRet6
fields are all declared final, but theTuple6
fields are not!- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/Java/Additional/Ret6.java
- Open New Browser-Tab: Torello/Java/Additional/Ret6.java
File Size: 3,875 Bytes Line Count: 105 '\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 a Read-Write Tuple, of the same size Modifier and Type Method Tuple6<A1,B2,C3,D4,E5,F6>
toModifiable()
Methods: interface java.lang.Cloneable Modifier and Type Method Ret6<A1,B2,C3,D4,E5,F6>
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;
-
a1
-
b2
-
c3
-
d4
-
e5
-
f6
-
-
Method Detail
-
n
-
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:RetN
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 - namelyRetN
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 actualRet6
instance, you will have to use one of the provided'get'
methods to retrieve a field inside theRet6
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: Ret6. Ret6<String, Integer, Date, File, DotPair, HTMLNode> ref6 = some_function_returns_6(); String neededStrField = ref6.a1; // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Less Keyboard-Typing (Less Eyesores), but Requires a Cast // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // If the Ret6 super-class RetN is used to reference this class data, // YOU WILL NEED TO CAST THE FIELDS BEFORE YOU CAN THEM, AS IN THE EXAMPLES BELOW: RetN refN = some_function_returns6(); // Version #1: (this method) - simple 'get' @SuppressWarnings("unchecked") String neededStrField = (String) refN.get(1); // Version #2: The second Method-Parameter is a 'Class<T>' Type-Parameter // Note, again, that passing a '1' to the first parameter retrieves Ret6.a1 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..6] CHECK_GET(i); if (i <= 3) switch (i) { case 1: return a1; case 2: return b2; default: return c3; } else switch (i) { case 4: return d4; case 5: return e5; default: return f6; }
-
toModifiable
public Tuple6<A1,B2,C3,D4,E5,F6> toModifiable()
Description copied from class:RetN
- Specified by:
toModifiable
in classRetN
- Returns:
- A
TupleN
of the same size, which is a modifiable type whose fields are not decorated with the'final'
modifier - as the fields in this class are. - Code:
- Exact Method Body:
return new Tuple6<>(this.a1, this.b2, this.c3, this.d4, this.e5, this.f6);
-
-