Package Torello.Browser
Class AbstractBuilder<T>
- java.lang.Object
-
- Torello.Browser.AbstractBuilder<T>
-
- Type Parameters:
T- The type produced by this builder'sbuild()method.
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
- Direct Known Subclasses:
CommandBuilder,TypeBuilder
public abstract class AbstractBuilder<T> extends java.lang.Object implements java.io.Serializable, java.lang.Cloneable
An abstract base class for builder-style objects that collect named assignments before producing a final CDP-related object.
This class provides the common assignment machinery used by bothTypeBuilderandCommandBuilder. Each assignment is checked against anAbstractDescriptor, which supplies the valid names and expected CDP type information for the builder.📌 Concrete subclasses decide whatbuild()produces. ATypeBuilderproduces a CDP data object, while aCommandBuilderproduces aScriptthat may be invoked against the browser.- See Also:
TypeBuilder,CommandBuilder,AbstractDescriptor, Serialized Form
Hi-Lited Source-Code:- View Here: Torello/Browser/AbstractBuilder.java
- Open New Browser-Tab: Torello/Browser/AbstractBuilder.java
File Size: 20,468 Bytes Line Count: 486 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field protected static longserialVersionUIDDescriptor for the Object which this Builder is building Modifier and Type Field AbstractDescriptordescriptor
-
Constructor Summary
Constructors Modifier Constructor protectedAbstractBuilder(AbstractBuilder<T> other)protectedAbstractBuilder(AbstractDescriptor descriptor)
-
Method Summary
Build 'this' Instance into the Actual Object Modifier and Type Method abstract Tbuild()Input Assignments: A CDP Class & an Array of CDP Classes Modifier and Type Method AbstractBuilder<T>accept(String name, BaseType<?> bt)AbstractBuilder<T>accept(String name, BaseType<?>[] btArr)Input Assignments: Standard Java Types Modifier and Type Method AbstractBuilder<T>accept(String name, Boolean b)AbstractBuilder<T>accept(String name, Integer i)AbstractBuilder<T>accept(String name, String s)AbstractBuilder<T>acceptBool(String name, boolean b)AbstractBuilder<T>acceptInt(String name, int i)AbstractBuilder<T>acceptNumber(String name, Number n)Input Assignments: One-Dimensional Array Types Modifier and Type Method AbstractBuilder<T>accept(String name, boolean[] arr1D)AbstractBuilder<T>accept(String name, int[] arr1D)AbstractBuilder<T>accept(String name, Number[] arr1D)AbstractBuilder<T>accept(String name, String[] arr1D)Input Assignments: Two-Dimensional Array Types Modifier and Type Method AbstractBuilder<T>accept(String name, boolean[][] arr2D)AbstractBuilder<T>accept(String name, int[][] arr2D)AbstractBuilder<T>accept(String name, Number[][] arr2D)AbstractBuilder<T>accept(String name, String[][] arr2D)Input Assignments: Unknown, Raw JSON Modifier and Type Method AbstractBuilder<T>accept(String name, JsonObject jo)Clear Assignment & Assign Null Modifier and Type Method AbstractBuilder<T>acceptNull(String name)AbstractBuilder<T>clear(String name)Methods: interface java.lang.Cloneable Modifier and Type Method abstract AbstractBuilder<T>clone()Methods: class java.lang.Object Modifier and Type Method booleanequals(Object o)inthashCode()StringtoString()
-
-
-
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 theSerializableImplementation 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 = 1L;
-
descriptor
public final AbstractDescriptor descriptor
The descriptor used by this builder. It provides the names, expected types, and ordering for each named assignment accepted by this builder.👉 ForTypeBuilder, these names correspond to fields in a CDP data type. ForCommandBuilder, they correspond to input parameters for a CDP command.- Code:
- Exact Field Declaration Expression:
public final AbstractDescriptor descriptor;
-
-
Constructor Detail
-
AbstractBuilder
protected AbstractBuilder(AbstractDescriptor descriptor)
Protected constructor used by the twoAbstractBuildersubclasses.- Parameters:
descriptor- The descriptor for the class or object which is ultimately being built- See Also:
NestedDescriptor,NestedHelper.descriptor(),CommandDescriptor
-
AbstractBuilder
protected AbstractBuilder(AbstractBuilder<T> other)
Protected constructor used by the'clone()'method, inside the two concrete subclasses of this type.- Parameters:
other- Another instance of this class
-
-
Method Detail
-
build
-
accept
public AbstractBuilder<T> accept(java.lang.String name, BaseType<?> bt)
Assign a CDP Class (extends BaseType<>) to a Builder InputAssigns: The value passed by parameter 'bt', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'BaseType>'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, bt, CDPTypes.CDP_TYPE);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, BaseType<?>[] btArr)
Assign an Array of BaseType> (any CDP Class) to a Builder InputAssigns: The value passed by parameter 'btArr', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'BaseType[]'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, btArr, CDPTypes.CDP_TYPE_ARRAY_1D);
-
acceptInt
public AbstractBuilder<T> acceptInt(java.lang.String name, int i)
Assign an 'int' Primitive to a Named Builder-InputAssigns: The value passed by parameter 'i', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'int'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, i, CDPTypes.PRIMITIVE_INT);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, java.lang.Integer i)
Assign a java.lang.Integer to a Named Builder-InputAssigns: The value passed by parameter 'i', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'Integer'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, i, CDPTypes.BOXED_INTEGER);
-
acceptBool
public AbstractBuilder<T> acceptBool(java.lang.String name, boolean b)
Assign a 'boolean' primitive to a Named Builder-InputAssigns: The value passed by parameter 'b', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'boolean'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, b, CDPTypes.PRIMITIVE_BOOLEAN);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, java.lang.Boolean b)
Assign a java.lang.Boolean to a Named Builder-InputAssigns: The value passed by parameter 'b', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'Boolean'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, b, CDPTypes.BOXED_BOOLEAN);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, java.lang.String s)
Assign a String to a Named Builder-InputAssigns: The value passed by parameter 's', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'String'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, s, CDPTypes.STRING);
-
acceptNumber
public AbstractBuilder<T> acceptNumber(java.lang.String name, java.lang.Number n)
Assign a java.lang.Number to a Named Builder-InputAssigns: The value passed by parameter 'n', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'Number'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, n, CDPTypes.NUMBER);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, int[] arr1D)
Assign an int[]-Array to a Named Builder-InputAssigns: The value passed by parameter 'arr1D', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'int[]'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, arr1D, CDPTypes.INT_ARRAY_1D);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, boolean[] arr1D)
Assign a boolean[]-Array to a Named Builder-InputAssigns: The value passed by parameter 'arr1D', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'boolean[]'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, arr1D, CDPTypes.BOOLEAN_ARRAY_1D);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, java.lang.String[] arr1D)
Assign a String[]-Array to a Named Builder-InputAssigns: The value passed by parameter 'arr1D', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'String[]'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, arr1D, CDPTypes.STRING_ARRAY_1D);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, java.lang.Number[] arr1D)
Assign a Number[]-Array to a Named Builder-InputAssigns: The value passed by parameter 'arr1D', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'Number[]'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, arr1D, CDPTypes.NUMBER_ARRAY_1D);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, int[][] arr2D)
Assign a Two Dimensional int[][]-Array to a Named Builder-InputAssigns: The value passed by parameter 'arr2D', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'int[][]'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, arr2D, CDPTypes.INT_ARRAY_2D);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, boolean[][] arr2D)
Assign a Two Dimensional boolean[][]-Array to a Named Builder-InputAssigns: The value passed by parameter 'arr2D', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'boolean[][]'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, arr2D, CDPTypes.BOOLEAN_ARRAY_2D);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, java.lang.String[][] arr2D)
Assign a Two Dimensional String[][]-Array to a Named Builder-InputAssigns: The value passed by parameter 'arr2D', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'String[][]'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, arr2D, CDPTypes.STRING_ARRAY_2D);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, java.lang.Number[][] arr2D)
Assign a Two Dimensional java.lang.Number[][]-Array to a Named Builder-InputAssigns: The value passed by parameter 'arr2D', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'Number[][]'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, arr2D, CDPTypes.NUMBER_ARRAY_2D);
-
accept
public AbstractBuilder<T> accept(java.lang.String name, JsonObject jo)
Assign a Raw JsonObject to a Named Builder-InputAssigns: The value passed by parameter 'jo', to the Named Builder-Input specified by parameter'name'.Throws: A TypeAssignmentExceptionif the specified Named Builder-Input isn't of type'JsonObject'An AssignmentNameExceptionif'name'is not the name of any input expected by this builder.Returns: The current instance, 'this', for convenience (invocation chaining)- Code:
- Exact Method Body:
return accept(name, jo, CDPTypes.RAW_JSON_VALUE);
-
acceptNull
public AbstractBuilder<T> acceptNull(java.lang.String name)
Explicitly assignsnullto a Named Builder-Input.🤷 If there is ever a need to ensure that an object property found in aJsonObjectthat is being transmitted over a web socket (and towards a browser) has an actualJson-Nullintentionally assigned to it, then invoking this method should be utilized. 🧠 This method guarantees that the internalisPresentboolean list is assignedTRUE, despite the fact that its value is still null.- Parameters:
name- The name of the Builder-Input to whichnullshall be assigned.- Returns:
'this'instance for invocation chaining- Throws:
AssignmentNameException- if'name'is not listed by this builder's descriptor.- See Also:
AbstractDescriptor.names- Code:
- Exact Method Body:
final int index = this.descriptor.names.indexOf(name); if (index < 0) throw new AssignmentNameException(name, this.descriptor); assignments[index] = null; assigned[index] = true; return this;
-
clear
public AbstractBuilder<T> clear(java.lang.String name)
Clears any value which may or may not have been assigned to a Named Builder-Input.- Parameters:
name- The name of the Builder-Input that the programmer would like cleared.- Returns:
'this'instance for invocation chaining- Throws:
AssignmentNameException- if'name'is not listed by this builder's descriptor.- See Also:
AbstractDescriptor.names- Code:
- Exact Method Body:
final int index = this.descriptor.names.indexOf(name); if (index < 0) throw new AssignmentNameException(name, this.descriptor); assignments[index] = null; assigned[index] = false; return this;
-
toString
public final java.lang.String toString()
Generate an insightful String representation of'this'instance👉 This method is declared final, meaning that it may not be modified by the concrete subclasses of this abstract parent.- Overrides:
toStringin classjava.lang.Object- Returns:
- A Java
String - Code:
- Exact Method Body:
return CDPToString.toString(this);
-
equals
public final boolean equals(java.lang.Object o)
Check whether'this'instance is equal to input parameter'o'👉 This method is declared final, meaning that it may not be modified by the concrete subclasses of this abstract parent.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- Any Java Object. Only another builder instance of the exact same runtime class, with the same descriptor and current assignment values, will returnTRUE.- Returns:
TRUEif and only if'this'is equal to'o'.- Code:
- Exact Method Body:
if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final AbstractBuilder<?> that = (AbstractBuilder<?>) o; return this.descriptor.equals(that.descriptor) && java.util.Arrays.equals(this.assignments, that.assignments) && java.util.Arrays.equals(this.assigned, that.assigned);
-
hashCode
public final int hashCode()
Generate a hashcode integer which may be used for placing this object into a hashtable data structure.👉 This method is declared final, meaning that it may not be modified by the concrete subclasses of this abstract parent.- Overrides:
hashCodein classjava.lang.Object- Returns:
- A (hopefully unique) integer value
- Code:
- Exact Method Body:
int result = this.descriptor.hashCode(); result = 31 * result + java.util.Arrays.hashCode(this.assignments); return result;
-
clone
public abstract AbstractBuilder<T> clone()
Clone the current instance- Overrides:
clonein classjava.lang.Object- Returns:
- An identical copy of
'this'.🔍 The concept known as a "Deep Clone" means that the internals of a type are also copied to the new instance. What is returned by this method is a "Partial Deep Clone" of'this'instance.
🧠 Since the internal'descriptor'instance is a read only, singleton instance, cloning it wouldn't have any real significance. Thus, the internal'descriptor'isn't cloned into the new instance; its reference is merely copied instead.
🎯 However, the two internal value-assignment arrays are cloned, resulting in a separate instance which has its own, independent assignments.
-
-