Package Torello.Browser
Class BaseType<DOMAIN_NESTED extends BaseType<DOMAIN_NESTED>>
- java.lang.Object
-
- Torello.Browser.BaseType<DOMAIN_NESTED>
-
- All Implemented Interfaces:
java.lang.Comparable<BaseType<?>>
- Direct Known Subclasses:
🔥 There are exactly 425 classes which inherit BaseType<?>
Please Click Here to see the Complete List
public abstract class BaseType<DOMAIN_NESTED extends BaseType<DOMAIN_NESTED>> extends java.lang.Object implements java.lang.Comparable<BaseType<?>>
This class is declared'abstract'and serves as the root ancestor clas for all data record types & events in all domains in within the Chrome DevTools Protocol (CDP) API.
This class utilizes a "Singleton Design Pattern." Each of the types and events in CDP ('Torello.Browser.*') are declared as nested classes within a parent or "container" class, rather than as standalone types. This decision helps make clear which types belong to which domains in CDP.
Programatically, it would likely be a little bit more "clear" to have a separate Java Package for Google Domain. In fact, within the Web-Browser Source-Code, a "domain" is essentially idential to the word "Java Package." What's the catch? Owing to the fact that the domains, types & events in the CDP-API (this Java-Wrapper) are nothing more than "Wrapper Code" that sends JSON requests to the browser, and parses responses from the browser.Essentially, the classes, methods & types in the Browser & JavaScript API's are just "messengers" to and from Google Chrome. As such, the actual source code for these "domains" is not in Java, but inside Chrome, itself. Thusly, compacting all of the types & events into a single Java Class (one class per domain) seems an intelligent design choice.
Each of the types & in every domain of the CDP uses this abstract class as its root ancestor.
Hi-Lited Source-Code:- View Here: Torello/Browser/BaseType.java
- Open New Browser-Tab: Torello/Browser/BaseType.java
File Size: 20,839 Bytes Line Count: 465 '\n' Characters Found
-
-
Field Summary
Helper-Singleton: 'Portal' into the Helper (similar to Java's 'Impl' Classes) Modifier and Type Field Description NestedHelper<DOMAIN_NESTED>helperSingletonSingleton Instance of the Nested Helper Class.Some Abstract Root-Ancestor (this class) Meta-Data about Descendant Class' Fields. Modifier and Type Field Description DomainsdomainIt was decided by somebody other than I that there are to be two API's of the browser Remote-Debug-Port interface.ReadOnlyList<Boolean>isPresentThe'isPresent'boolean-array cannot be assigned inside of this abstract ancestor class' constructor.StringnameThe event has a name, and this name happens to be the exact same name as the event-classitself.intnumFieldsThis is the number of fields in this class.
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseType(NestedHelper<DOMAIN_NESTED> helperSingleton, Domains domain, String name, int numFields)Constructor for thisabstract-class
-
Method Summary
Convert this instance into a JsonObject Modifier and Type Method Description voidtoJSON(String name, JsonGenerator jGen)Serializes'this'object into JSON.Accessor Method for the 'isPresentList' field Modifier and Type Method Description ReadOnlyList<Boolean>isPresent()Accessor method for the private, internal'isPresent'instance field.Instance Integrity: Enumerated String Field Checks Modifier and Type Method Description ReadOnlyMap<String,
ReadOnlyList<String>>allEnumStrROLs()Retrieves aReadOnlyMapmapping field names to aReadOnlyListof validStringvalues for each field in the map.ReadOnlyList<String>enumStrList(String fieldName)Retrieve any associated string-enumeration lists for a given field, if they exist.IntStreamenumStrValidate()This method will investigate the contents of any & string fields in the concrete sub-type of'this'instance for validity against pre-defined enumerated string constants.voidenumStrValidateThrow()Generates a properly formatted exception throw message using the output produced byoptionalsValidate(), and then throwsInvalidEnumStrException.Instance Integrity: Optional, non-Null Field Checks Modifier and Type Method Description IntStreamoptionalsValidate()Checks whether the state of a type or event is actually valid, according to the CDP specifications, as per the field's "Optional Flag." Google's Json-Specifications File for the CDP-API declares that some fields (referred to as 'properties' in the CDP-API Json-Spec File) for some of the API's types & events are not actually mandatory or required.voidoptionalsValidateThrow()Generates a properly formatted exception throw message using the output produced byoptionalsValidate(), and then throwsNullNonOptionalException.Methods: interface java.lang.Comparable Modifier and Type Method Description intcompareTo(BaseType<?> o)Compares thisBaseTypeto another for ordering.Methods: class java.lang.Object Modifier and Type Method Description booleanequals(Object other)Checks the Contents of this class again the input parameter'other'for euality.inthashCode()Generates a Hash-Code for this class, which may be used for hashing into maps and sets.StringtoString()This method uses Java Reflection to convert the inheriting object into aString.
-
-
-
Field Detail
-
helperSingleton
public final NestedHelper<DOMAIN_NESTED extends BaseType<DOMAIN_NESTED>> helperSingleton
Singleton Instance of the Nested Helper Class. This is how the "Singleton Design Pattern" is implemented. The methods & fields in this class implement many of the features offered by abstract class'BaseType'.- Code:
- Exact Field Declaration Expression:
public final NestedHelper<DOMAIN_NESTED> helperSingleton;
-
domain
public final Domains domain
It was decided by somebody other than I that there are to be two API's of the browser Remote-Debug-Port interface. The two API's were decided to be theJavaScriptAPI, and theBrowserAPI. These two do not have a lot of distinction or meaning.
💡 Each API has several categories of methods, and these are calledDomain's.- Code:
- Exact Field Declaration Expression:
public final Domains domain;
-
name
public final java.lang.String name
The event has a name, and this name happens to be the exact same name as the event-classitself.- Code:
- Exact Field Declaration Expression:
public final String name;
-
numFields
public final int numFields
This is the number of fields in this class. It is like a reflection-field reflecting information for the concrete subclass instance.- Code:
- Exact Field Declaration Expression:
public final int numFields;
-
isPresent
public ReadOnlyList<java.lang.Boolean> isPresent
The'isPresent'boolean-array cannot be assigned inside of this abstract ancestor class' constructor. Thus, the only other option for actually using or retrieving the values in this list is to include a simple'getter'or'accessor'method. See method:isPresent()
The'isPresent'list cannot be assigned until after the fields of the concrete instance sub-class have been assigned. Since it was not until JDK 22+ that statements prior to the invocation ofsuper()were allowed inside of constructors, this field shall simply remain'protected'and inaccessible to outside modification.- See Also:
isPresent()- Code:
- Exact Field Declaration Expression:
public ReadOnlyList<Boolean> isPresent;
-
-
Constructor Detail
-
BaseType
protected BaseType(NestedHelper<DOMAIN_NESTED> helperSingleton, Domains domain, java.lang.String name, int numFields)
Constructor for thisabstract-class
-
-
Method Detail
-
equals
public final boolean equals(java.lang.Object other)
Checks the Contents of this class again the input parameter'other'for euality.💡 This method's implementation is hereby delegated to this class' 'helper singleton'.
🧠 It is an intentional design choice to place as much source code and as many method bodies as possible into an internal helper. Removing code from both the actual concrete sub-class and this abstract parent class makes the concrete CDP data-type much easier to read and understand.- Overrides:
equalsin classjava.lang.Object- Returns:
'TRUE'if and only if the two instances are equal.- See Also:
NestedHelper.equals(BaseType, Object)- Code:
- Exact Method Body:
return helperSingleton.equals(THIS, other);
-
hashCode
public final int hashCode()
Generates a Hash-Code for this class, which may be used for hashing into maps and sets.💡 This method's implementation is hereby delegated to this class' 'helper singleton'.
🧠 It is an intentional design choice to place as much source code and as many method bodies as possible into an internal helper. Removing code from both the actual concrete sub-class and this abstract parent class makes the concrete CDP data-type much easier to read and understand.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a valid hash code for this object.
- See Also:
NestedHelper.hashCode(BaseType)- Code:
- Exact Method Body:
return helperSingleton.hashCode(THIS);
-
toString
public final java.lang.String toString()
This method uses Java Reflection to convert the inheriting object into aString.- Overrides:
toStringin classjava.lang.Object- Returns:
- A
java.lang.Stringrepresentation of'this'object - Code:
- Exact Method Body:
return CDPToString.toString(THIS);
-
compareTo
public final int compareTo(BaseType<?> o)
Compares thisBaseTypeto another for ordering.
Comparison is performed in two steps:- First by
domain - Then by
nameif domains are equal
- Specified by:
compareToin interfacejava.lang.Comparable<DOMAIN_NESTED extends BaseType<DOMAIN_NESTED>>- Parameters:
o- TheBaseTypeto be compared.- Returns:
- A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
java.lang.NullPointerException- Ifoisnull.- Code:
- Exact Method Body:
final int i = this.domain.compareTo(o.domain); if (i != 0) return i; return this.name.compareTo(o.name);
- First by
-
toJSON
public final void toJSON(java.lang.String name, JsonGenerator jGen)
Serializes'this'object into JSON.- It is OK if 'name' is null.
- It is NOT-OK if 'jGen' is null.
💡 This method's implementation is hereby delegated to this class' 'helper singleton'.
🧠 It is an intentional design choice to place as much source code and as many method bodies as possible into an internal helper. Removing code from both the actual concrete sub-class and this abstract parent class makes the concrete CDP data-type much easier to read and understand.- Parameters:
name- The name being assigned to thisJsonObjectProperty. This name may be null. If null is passed here, theJsonGeneratorwill treat this Object as the top level JSON Object, not a property of a larger object.jGen- This is the generator instance. Note that often, when serializing Java Objects to JSON (and vice-versa!), one object may be a property or field of another object. When serializing an object to JSON, if there is a field that also needs to be serialized as aJsonObject, just pass the name and this generator instance in order to include that field as a sub-property.- See Also:
NestedHelper.toJSON(BaseType, String, JsonGenerator)- Code:
- Exact Method Body:
helperSingleton.toJSON(THIS, name, jGen);
-
optionalsValidate
public final java.util.stream.IntStream optionalsValidate()
Checks whether the state of a type or event is actually valid, according to the CDP specifications, as per the field's "Optional Flag." Google's Json-Specifications File for the CDP-API declares that some fields (referred to as 'properties' in the CDP-API Json-Spec File) for some of the API's types & events are not actually mandatory or required. When Google Chrome (or another CDP compliant Web-Browser) returns a type, or fires / generates an event, the browser may choose to omit certain fields in the classes that are constructed and returned to you, the end user.Generally, such fields are assigned null. This design choice explains why Java's Boxed-Types (such asjava.lang.Integermay seem ubiquitous in this API). Note that fields which are declared as simple types such as'int'are indeed declared using a Java Primitive'int', not the boxed type'java.lang.Integer'.
There are only two minor issues. One, Google Chrome is not under "developmental control" of "Torello Software." Though, theoretically, Chome would never omit a "non optional property", on the off chance that it has done so, this method can be used to scan for such an occurence.
Since both types and events can be constructed using their respective public constructors, if a user has omitted a field (Google doesn't use the term 'field' or 'class', instead it refers to such concepts as 'types', 'events', and 'properties'), then this method may als be used to validate user constructed objects.- Returns:
- returns an
java.util.stream.IntStreamcontaining all indices of fields which meets these criteria:- hasn't been declared optional in the CDP specifications
- is asserted not to be present, as per the value of
'this'isPresentList
If there are no such fields, then this method simply returns an emptyjava.util.stream.IntStream. - See Also:
AbstractDescriptor.optionals,isPresent()- Code:
- Exact Method Body:
final IntStream.Builder b = IntStream.builder(); final ReadOnlyList<Boolean> optionals = helperSingleton.descriptor().optionals; final ReadOnlyList<Boolean> isPresent = this.isPresent(); final int NUM = optionals.size(); for (int i=0; i < NUM; i++) if (! optionals.get(i)) // TRUE => 'optional', FALSE => 'mandatory' if (!isPresent.get(i)) // TRUE => 'included', FALSE => 'omitted' b.accept(i); return b.build();
-
optionalsValidateThrow
public void optionalsValidateThrow()
Generates a properly formatted exception throw message using the output produced byoptionalsValidate(), and then throwsNullNonOptionalException.If the outputIntStreamreturned byoptionalsValidateis empty, then this method simply exits, and returns gracefull - WITHOUT THROWING.- Throws:
NullNonOptionalException- If theIntStreamreturned byoptionalsValidate()has a non-zero length.- See Also:
optionalsValidate(),AbstractDescriptor.optionals,isPresent()- Code:
- Exact Method Body:
final int[] errors = optionalsValidate().toArray(); if (errors.length == 0) return; throw new NullNonOptionalException (printHelper(errors, "isn't present, but also isn't optional"));
-
enumStrValidate
public final java.util.stream.IntStream enumStrValidate()
This method will investigate the contents of any & string fields in the concrete sub-type of'this'instance for validity against pre-defined enumerated string constants.
If'this'concrete sub-type doesn't have any string fields among its public fields, or the string fields which it has have not been designted as members of a domain "enum type", then this method returns an emptyjava.util.stream.IntStream.💡 This method's implementation is hereby delegated to this class' 'helper singleton'.
🧠 It is an intentional design choice to place as much source code and as many method bodies as possible into an internal helper. Removing code from both the actual concrete sub-class and this abstract parent class makes the concrete CDP data-type much easier to read and understand.- Returns:
- returns an
java.util.stream.IntStreamcontaining all indices of fields which meets these criteria:- is declared as a CDP (or Java)
String - has failed to abide by a pre-specified list of enumerated string constants
If there are no such fields, then this method simply returns an emptyjava.util.stream.IntStream. - is declared as a CDP (or Java)
- See Also:
NestedHelper.enumStrValidate(BaseType)- Code:
- Exact Method Body:
return helperSingleton.enumStrValidate(THIS);
-
enumStrValidateThrow
public void enumStrValidateThrow()
Generates a properly formatted exception throw message using the output produced byoptionalsValidate(), and then throwsInvalidEnumStrException.If the outputIntStreamreturned byenumStrValidateis empty, then this method simply exits, and returns gracefull - WITHOUT THROWING.- Throws:
InvalidEnumStrException- If theIntStreamreturned byoptionalsValidate()has a non-zero length.- See Also:
enumStrValidate(),NestedHelper.enumStrValidate(BaseType)- Code:
- Exact Method Body:
final int[] errors = enumStrValidate().toArray(); if (errors.length == 0) return; throw new InvalidEnumStrException (printHelper(errors, "has an invalid string value"));
-
isPresent
public final ReadOnlyList<java.lang.Boolean> isPresent()
Accessor method for the private, internal'isPresent'instance field. This field cannot be assigned inside of this abstract ancestor class' constructor. Thus, the'isPresent'field also cannot be declared'final'. As a result, the only other option for actually using or retrieving the values in this list is to include this simple'getter'or'accessor'method.
This getter shields the internal, non-final field value from modification.- Returns:
- The list contained by the
'isPresent'instace field. - Code:
- Exact Method Body:
return this.isPresent;
-
allEnumStrROLs
public ReadOnlyMap<java.lang.String,ReadOnlyList<java.lang.String>> allEnumStrROLs ()
Retrieves aReadOnlyMapmapping field names to aReadOnlyListof validStringvalues for each field in the map.-
🧱 Some
Stringfields declared within CDP data-types may have their values restricted to a fixed set of enumerated strings (similar to a Javaenum).
-
🔧 CDP classes which contain enumeration-restricted
Stringfields do not automatically validate those values within the class constructor itself. However, the CDP root ancestor class (BaseType) provides a dedicated validation method namedenumStrValidate().
-
🎯 The map returned by this method contains references to the enumerated-string set associated
with each restricted
Stringfield in this class.
You may query the map using the field's name (as ajava.lang.String).
If the returned value is non-null, then the queried field is enumeration-restricted, and the returned list contains all valid string values for that field.
-
🔍 If the returned map is queried using a string which is not the name of a valid
Stringfield in this class, then the map will simply returnnull.
No exception is thrown by the map'sget()method in this situation.
-
💡 This method returns a non-null, empty map if this particular CDP type does not contain any
Stringfields, or if none of the string fields in this class are enumeration-restricted.
- See Also:
NestedHelper.allEnumStrROLs(),enumStrValidate(),enumStrValidateThrow()- Code:
- Exact Method Body:
return helperSingleton.allEnumStrROLs();
-
🧱 Some
-
enumStrList
public ReadOnlyList<java.lang.String> enumStrList (java.lang.String fieldName)
Retrieve any associated string-enumeration lists for a given field, if they exist.- Parameters:
fieldName- The name of any field in this class, as ajava.lang.String- Returns:
- A read-only list of strings containing the string-enumeration that restricts the
value of the field / property indicated by
'fieldName'
This method shall return'null'if:- The indicated field is not a
Stringfield or property in the first place - The field is a
Stringproperty, but isn't restricted by an string-enumeration lists, as per the CDP specification-definition files.
- The indicated field is not a
- Throws:
UnknownPropertyException- If theClasswhich defines'this'instance does not have the specified field in its class definition.- See Also:
allEnumStrROLs(),NestedHelper.allEnumStrROLs()- Code:
- Exact Method Body:
// If this class doesn't have a field named 'fieldName', then throw. if (! helperSingleton.descriptor().names.contains(fieldName)) throw new UnknownPropertyException(fieldName); // Returns the list if it exists, and null if this field isn't an enum-restricted field return helperSingleton.allEnumStrROLs().get(fieldName);
-
-