Class BaseType<DOMAIN_NESTED extends 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.


    • Field Summary

       
      Helper-Singleton: 'Portal' into the Helper (similar to Java's 'Impl' Classes)
      Modifier and Type Field Description
      NestedHelper<DOMAIN_NESTED> helperSingleton
      Singleton Instance of the Nested Helper Class.
       
      Some Abstract Root-Ancestor (this class) Meta-Data about Descendant Class' Fields.
      Modifier and Type Field Description
      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.
      ReadOnlyList<Boolean> isPresent
      The 'isPresent' boolean-array cannot be assigned inside of this abstract ancestor class' constructor.
      String name
      The event has a name, and this name happens to be the exact same name as the event-class itself.
      int numFields
      This is the number of fields in this class.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected BaseType​(NestedHelper<DOMAIN_NESTED> helperSingleton, Domains domain, String name, int numFields)
      Constructor for this abstract-class
    • Method Summary

       
      Convert this instance into a JsonObject
      Modifier and Type Method Description
      void toJSON​(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 a ReadOnlyMap mapping field names to a ReadOnlyList of valid String values for each field in the map.
      ReadOnlyList<String> enumStrList​(String fieldName)
      Retrieve any associated string-enumeration lists for a given field, if they exist.
      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.
      void enumStrValidateThrow()
      Generates a properly formatted exception throw message using the output produced by optionalsValidate(), and then throws InvalidEnumStrException.
       
      Instance Integrity: Optional, non-Null Field Checks
      Modifier and Type Method Description
      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.
      void optionalsValidateThrow()
      Generates a properly formatted exception throw message using the output produced by optionalsValidate(), and then throws NullNonOptionalException.
       
      Methods: interface java.lang.Comparable
      Modifier and Type Method Description
      int compareTo​(BaseType<?> o)
      Compares this BaseType to another for ordering.
       
      Methods: class java.lang.Object
      Modifier and Type Method Description
      boolean equals​(Object other)
      Checks the Contents of this class again the input parameter 'other' for euality.
      int hashCode()
      Generates a Hash-Code for this class, which may be used for hashing into maps and sets.
      String toString()
      This method uses Java Reflection to convert the inheriting object into a String.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 the JavaScript API, and the Browser API. These two do not have a lot of distinction or meaning.

        💡 Each API has several categories of methods, and these are called Domain'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-class itself.
        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 of super() 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;
        
    • 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:
        equals in class java.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:
        hashCode in class java.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 a String.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A java.lang.String representation of 'this' object
        Code:
        Exact Method Body:
         return CDPToString.toString(THIS);
        
      • compareTo

        🡅  🡇     🗕  🗗  🗖
        public final int compareTo​(BaseType<?> o)
        Compares this BaseType to another for ordering.

        Comparison is performed in two steps:

        1. First by domain
        2. Then by name if domains are equal
        Specified by:
        compareTo in interface java.lang.Comparable<DOMAIN_NESTED extends BaseType<DOMAIN_NESTED>>
        Parameters:
        o - The BaseType to 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 - If o is null.
        Code:
        Exact Method Body:
         final int i = this.domain.compareTo(o.domain);
         if (i != 0) return i;
        
         return this.name.compareTo(o.name);
        
      • toJSON

        🡅  🡇     🗕  🗗  🗖
        public final void toJSON​(java.lang.String name,
                                 JsonGenerator jGen)
        Serializes 'this' object into JSON.

        1. It is OK if 'name' is null.
        2. 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 this JsonObject Property. This name may be null. If null is passed here, the JsonGenerator will 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 a JsonObject, 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 as java.lang.Integer may 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.IntStream containing 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 empty java.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();
        
      • 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 empty java.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.IntStream containing 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 empty java.util.stream.IntStream.
        See Also:
        NestedHelper.enumStrValidate(BaseType)
        Code:
        Exact Method Body:
         return helperSingleton.enumStrValidate(THIS);
        
      • 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 a ReadOnlyMap mapping field names to a ReadOnlyList of valid String values for each field in the map.

        • 🧱 Some String fields declared within CDP data-types may have their values restricted to a fixed set of enumerated strings (similar to a Java enum).

        • 🔧 CDP classes which contain enumeration-restricted String fields do not automatically validate those values within the class constructor itself. However, the CDP root ancestor class (BaseType) provides a dedicated validation method named enumStrValidate() .

        • 🎯 The map returned by this method contains references to the enumerated-string set associated with each restricted String field in this class.

          You may query the map using the field's name (as a java.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 String field in this class, then the map will simply return null.

          No exception is thrown by the map's get() method in this situation.

        • 💡 This method returns a non-null, empty map if this particular CDP type does not contain any String fields, 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();
        
      • 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 a java.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 String field or property in the first place
        • The field is a String property, but isn't restricted by an string-enumeration lists, as per the CDP specification-definition files.
        Throws:
        UnknownPropertyException - If the Class which 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);