Class CommandBuilder<T>

  • Type Parameters:
    T - The return type produced by the Script created by this builder's build() method.
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class CommandBuilder<T>
    extends AbstractBuilder<Script<T>>
    implements java.io.Serializable, java.lang.Cloneable
    A 'Builder' software design pattern that may be used to construct Script instances for CDP browser commands whose method signatures contain long lists of input parameters. This class is primarily intended for generated "abbreviated" command methods: zero-argument overloads that return a pre-configured CommandBuilder, already connected to the appropriate CommandDescriptor.

    In the generated CDP domain classes, these abbreviated methods are only emitted for commands that accept 5 or more input parameters. Shorter command methods should usually be invoked directly, since the ordinary method call is already clear enough, and no public abbreviated builder-entry method is generated for them.

    ⚠️ The main purpose of 'CommandBuilder' is to avoid long, repetitive invocations filled with null placeholders for optional command parameters.

    Included below are example uses of the class CommandBuilder

    Example:
    final RunTime.evaluate$$RET r = RunTime
        .evaluate()
        .accept("expression", "document.documentElement.outerHTML")
        .accept("returnByValue", true)
        .build()
        .exec(pws)
        .await();
    
    Notice that the above example only assigns values to two of the parameters accepted by RunTime.evaluate(). Thus, the other fourteen optional parameters will be automatically assigned null when CommandBuilder.build() is finally called.

    📌 The primary purpose of class CommandBuilder is to eliminate messy, cumbersome & arduous invocations for domain commands that contain many optional parameters.

    The code snippet below shows what "life would be like" invoking the same exact CDP command (having many optional parameters), using the standard method instead!

    final RunTime.evaluate$$RET r = RunTime.evaluate(
            "document.documentElement.outerHTML", // expression
            null, // objectGroup
            null, // includeCommandLineAPI
            null, // silent
            null, // contextId
            true, // returnByValue
            null, // generatePreview
            null, // userGesture
            null, // awaitPromise
            null, // throwOnSideEffect
            null, // timeout
            null, // disableBreaks
            null, // replMode
            null, // allowUnsafeEvalBlockedByCSP
            null, // uniqueContextId
            null  // SerializationOptions
        )
        .exec(pws)
        .await();
    
    See Also:
    CommandDescriptor, Script, Promise, Serialized Form


    • Field Detail

      • serialVersionUID

        🡇     🗕  🗗  🗖
        protected static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable 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 = 1L;
        
    • Method Detail

      • build

        🡅  🡇     🗕  🗗  🗖
        public Script<Tbuild()
        Convert 'this' Builder-Instance into an actual Object-Instance
        Specified by:
        build in class AbstractBuilder<Script<T>>
        Returns:
        A Script
        Code:
        Exact Method Body:
         return BuildScript.build
             ((CommandDescriptor<T>) this.descriptor, this.assignments, this.assigned);
        
      • clone

        🡅     🗕  🗗  🗖
        public CommandBuilder<Tclone()
        Clone the current instance
        Specified by:
        clone in class AbstractBuilder<Script<T>>
        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.
        Code:
        Exact Method Body:
         return new CommandBuilder<>(this);