Package Torello.Browser
Class CommandBuilder<T>
- java.lang.Object
-
- Torello.Browser.AbstractBuilder<Script<T>>
-
- Torello.Browser.CommandBuilder<T>
-
- Type Parameters:
T- The return type produced by theScriptcreated by this builder'sbuild()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 constructScriptinstances 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-configuredCommandBuilder, already connected to the appropriateCommandDescriptor.
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 withnullplaceholders for optional command parameters.
Included below are example uses of the classCommandBuilder
Example:
Notice that the above example only assigns values to two of the parameters accepted byfinal RunTime.evaluate$$RET r = RunTime .evaluate() .accept("expression", "document.documentElement.outerHTML") .accept("returnByValue", true) .build() .exec(pws) .await();
RunTime.evaluate(). Thus, the other fourteen optional parameters will be automatically assigned null whenCommandBuilder.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
Hi-Lited Source-Code:This File's Source Code:
- View Here: Torello/Browser/CommandBuilder.java
- Open New Browser-Tab: Torello/Browser/CommandBuilder.java
File Size: 2,491 Bytes Line Count: 71 '\n' Characters Found
Command Building Class:
- View Here: BuildScript.java
- Open New Browser-Tab: BuildScript.java
File Size: 2,545 Bytes Line Count: 77 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field protected static longserialVersionUID-
Fields inherited from class Torello.Browser.AbstractBuilder
descriptor
-
-
Method Summary
Create a new Instance of CommandBuilder Modifier and Type Method static <T> CommandBuilder<T>builder(CommandDescriptor<T> descriptor)Build 'this' Instance into a Script Instance Modifier and Type Method Script<T>build()Methods: interface java.lang.Cloneable Modifier and Type Method CommandBuilder<T>clone()
-
-
-
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;
-
-
Method Detail
-
build
-
builder
public static <T> CommandBuilder<T> builder (CommandDescriptor<T> descriptor)
- Code:
- Exact Method Body:
java.util.Objects.requireNonNull(descriptor, "parameter 'descriptor' is null"); return new CommandBuilder<>(descriptor);
-
clone
public CommandBuilder<T> clone()
Clone the current instance- Specified by:
clonein classAbstractBuilder<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);
-
-