Package Torello.Browser
Class AbstractDescriptor
- java.lang.Object
-
- Torello.Browser.AbstractDescriptor
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<AbstractDescriptor>
- Direct Known Subclasses:
CommandDescriptor,NestedDescriptor
public abstract class AbstractDescriptor extends java.lang.Object implements java.lang.Comparable<AbstractDescriptor>, java.io.Serializable
Serves as the parent class for bothNestedDescriptorandCommandDescriptor. These two concrete subclass descriptors may be used to construct a 'builder' instance. Builders allow a programmer to assign values to a class' fields (NestedDescriptor) or values to the parameters of a command / method (CommandDescriptor).
Builder Design Pattern
๐คท There are quite a number of types / classes in the CDP which have a very long list of fields. There are also several methods in the domain classes which accept a very long parameter list. Since many, many of the class fields and method parameters are declared 'optional' by CDP, in order to use the constructor for these classes, or invoke these methods, he winds up typing very long lists of 'nulls'.
๐ Using a 'builder' to construct classes with large numbers of fields, or invoke methods with a lengthy parameter list, allows the programmer to only pass the necessary values to these fields & parameters, rather than a very long and sparse list of values, largely replete with many 'nulls'๐ The information returned by this class should be identical to that which would be generated by the classes injava.lang.reflect.*.
๐ฅ Using a precalculated'descriptor'class is an order of magnitude easier to read, and likely programatically faster than, using actual Java Reflection- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/Browser/AbstractDescriptor.java
- Open New Browser-Tab: Torello/Browser/AbstractDescriptor.java
File Size: 17,411 Bytes Line Count: 402 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field protected static longserialVersionUIDType or Method's Location & Size (in terms of Fields or Parameters) Modifier and Type Field DomainsdomainStringnameintsizeFlags which CDP Has Ascribed to the Fields & Parameters Contained by this Descriptor Modifier and Type Field ReadOnlyList<Boolean>experimentalsReadOnlyList<Boolean>optionalsThe Names & Types of the Fields & Parameters Contained by the Descriptor Modifier and Type Field ReadOnlyList<String>namesReadOnlyList<Byte>types
-
Method Summary
Retrieve an 'index' (location) within the RO Lists of this Descriptor Instance Modifier and Type Method intnameToIndex(String name)Methods: interface java.lang.Comparable Modifier and Type Method intcompareTo(AbstractDescriptor that)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;
-
name
public final java.lang.String name
This is simply the name of the type or command represented by this descriptor.- Code:
- Exact Field Declaration Expression:
public final String name;
-
domain
public final Domains domain
The Web Browser "Domain" in which the class / type (or command) represented by this descriptor exists.
๐ Inside of a Web Browser's Source Code, a "Domain" is essentially the same as a Java Package, and basically means just that.
Browser Automation Design
Java-HTML's Browser Package implements a Web-Browser's Domains as a single class, rather than an entire package. This is because the Java CDP Implementation does not have any actual browser code; but rather is nothing more than a series of wrappers and datagram envelopes which communicate with the actual source code inside of the browser.
๐ As a result, the methods & types of an entire Browser 'Domain' fit inside of a single Java Class, rather than occupying an entire Java Package. (Browser Domain'CSS', for instance, is wholly placed into a single Java Class:'CSS')- Code:
- Exact Field Declaration Expression:
public final Domains domain;
-
names
public final ReadOnlyList<java.lang.String> names
Provides the names of the CDP properties or command parameters represented by this descriptor. For aNestedDescriptor, these names correspond to the fields of a nested data type. For aCommandDescriptor, these names correspond to the parameters accepted by a domain command.
Specs as an AST
๐ก Within the Java-HTML Browser AST Parsing package (Torello.Browser.JsonAST), both concepts are actually represented by ASTPPR'snodes: named JSON values with a declared CDP type, optional status, and experimental status.๐ This list is a "Parallel List", meaning its length should be equal to the other lists which reside in this class, and that the values contained by the lists all correspond to the same class-field or method-parameter.- Code:
- Exact Field Declaration Expression:
public final ReadOnlyList<String> names;
-
types
public final ReadOnlyList<java.lang.Byte> types
The bytes stored in this class are identical to the specified constants in classCDPTypes.๐ This list is a "Parallel List", meaning its length should be equal to the other lists which reside in this class, and that the values contained by the lists all correspond to the same class-field or method-parameter.- Code:
- Exact Field Declaration Expression:
public final ReadOnlyList<Byte> types;
-
optionals
public final ReadOnlyList<java.lang.Boolean> optionals
Specifies which CDP properties or command parameters have been designated asoptional. Optional values are permitted to be absent from theJsonObjectwhich defines them.๐ This list is a "Parallel List", meaning its length should be equal to the other lists which reside in this class, and that the values contained by the lists all correspond to the same class-field or method-parameter.- Code:
- Exact Field Declaration Expression:
public final ReadOnlyList<Boolean> optionals;
-
experimentals
public final ReadOnlyList<java.lang.Boolean> experimentals
Google's Chrome DevTools Protocol occasionally designates certain properties or command parameters as "experimental." If the element described by a particular list index has been markedexperimental, then the same index in this list will be assigned'TRUE'.๐ This list is a "Parallel List", meaning its length should be equal to the other lists which reside in this class, and that the values contained by the lists all correspond to the same class-field or method-parameter.- Code:
- Exact Field Declaration Expression:
public final ReadOnlyList<Boolean> experimentals;
-
size
public final int size
The number of CDP properties or command parameters described by this descriptor-instance.๐ This number will be equal to the'size()'of each of the lists in this class.- Code:
- Exact Field Declaration Expression:
public final int size;
-
-
Method Detail
-
nameToIndex
public int nameToIndex(java.lang.String name)
Retrieves the array index associated with the CDP property or command parameter whose name is'fieldName'.Remember that the lists in this class are parallel lists! In order to find the type of a field name, look up the array index for a field's name, and then look at the same location in thetypeslist to find that particular field's type!It isn't mission critical to use this method, and one may simply refer to the Java-Doc Documentation to find the exact "array index" of a particular field. It isn't rocket science at all! The first field in the class will have an array index of'0', and the second will have an array index of'1'- and so on and so forth!- Parameters:
name- Must be ajava.lang.Stringthat is identicial to one of the field names (Java would call these "identifiers") within this class. If the provided name doen't correspond to any field in this class, thenUnknownPropertyExceptionthrows.- Returns:
- The 'number' associated with the field named by
'fieldName'. If a type or event type has 4 fields, then this method would return a value between 0 and 3. - Throws:
UnknownPropertyException- If the User-Provided'feildName'isn't found.- Code:
- Exact Method Body:
final int ret = names.indexOf(name); if (ret == -1) throw new UnknownPropertyException(name); return ret;
-
compareTo
public final int compareTo(AbstractDescriptor that)
Compares this descriptor to another descriptor for ordering purposes.
Ordering is performed first bydomain, and then byname.
๐ This method is declared final, meaning that it may not be modified by the concrete subclasses of this abstract parent.- Specified by:
compareToin interfacejava.lang.Comparable<AbstractDescriptor>- Parameters:
that- The descriptor instance being compared to this instance.- Returns:
- A negative integer, zero, or a positive integer if this descriptor is less than, equal to, or greater than the specified descriptor.
- Code:
- Exact Method Body:
final int ret = this.domain.compareTo(that.domain); if (ret != 0) return ret; else return this.name.compareTo(that.name);
-
toString
public java.lang.String toString()
Generates an insightfulStringrepresentation of'this'instance.โ ๏ธ Since this class is an abstract class, with concrete sub-classes doing the actual work, the output generated by this particular'toString()'method is not intended for use by a programmer, but rather used by the sub-classes to simplify their own'toString()'methods.- Overrides:
toStringin classjava.lang.Object- Returns:
- A Java
String - See Also:
NestedDescriptor.toString(),CommandDescriptor.toString()- Code:
- Exact Method Body:
// toCSV(Iterable<T> i, Function<? super T,โString> toString, boolean printNulls, // Integer maxLength) // // Conversion Map: Byte Constant into its Constant-Name, as a String // public static final ReadOnlyMap<java.lang.Byte,โjava.lang.String> names final String types = StrCSV.toCSV(this.types, CDPTypes.names::get, true, null); // toCSV(Iterable<?> i, boolean trim, boolean printNulls, Integer maxLength) final String names = StrCSV.toCSV(this.names, true, true, null); final String optionals = StrCSV.toCSV(this.optionals, true, true, null); final String experimentals = StrCSV.toCSV(this.experimentals, true, true, null); // wrapToIndentationPlusโ(String s, int firstLineLen, int lineLen, int extraSpaces) // // "Experimentals: ".length() ==> 15 // I4.length() ==> 4 // // firstLineLen = 80 - 15 - 4 ==> 61 // lineLen = 80 - 4 ==> 76 // // This is just here to make the code below more readable. This is a "Cute Little Lambda" // a.k.a. a Java Function Pointer. final Function<String, String> print = (String s) -> StrPrint.wrapToIndentationPlus(s, 61, 76, 4); // Remember, this class 'AbstractDescriptor' is an abstract class, and this 'toString' // method will only ever be invoked by the concrete subclasses 'toString'. Those // subclasses will "wrap" the output from this toString in curly-braces, and some nicer // looking labels. return I4 + "Domain: " + this.domain + '\n' + I4 + "Name: " + this.name + '\n' + I4 + "size: " + this.size + '\n' + '\n' + I4 + "Names: " + print.apply(names) + '\n' + I4 + "Types: " + print.apply(types) + '\n' + I4 + "Optionals: " + print.apply(optionals) + '\n' + I4 + "Experimentals: " + print.apply(experimentals);
-
equals
public final boolean equals(java.lang.Object o)
Check whether'this'instance is equal to input parameter'o'๐ This'equals'method merely checks the values assigned to fieldsnameanddomainfor equality. Each type and each command within CDP has its own, singleton, descriptor instance. These two fields can uniquely identify any descriptor instance in CDP.๐ 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 an instance ofAbstractDescriptorthat is identical to'this'instance will return'true'.- Returns:
TRUEif and only if'this'is equal to'o'.- See Also:
name,domain- Code:
- Exact Method Body:
if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final AbstractDescriptor that = (AbstractDescriptor) o; return this.name.equals(that.name) && this.domain.equals(that.domain);
-
hashCode
public final int hashCode()
Generates a hashcode for this instance. This method utilizes the same fields for its hashing computation as the fields used by theequals(Object)method.
๐ 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 Java
int - See Also:
equals(Object)- Code:
- Exact Method Body:
return this.name.hashCode() + 31 * this.domain.hashCode();
-
-