1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package Torello.Browser;

import Torello.Browser.AbstractBuilder;
import Torello.Browser.CommandDescriptor;
import Torello.Browser.TypeBuilder;

/**
 * A 'Builder' software design pattern that may be used to construct {@link 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 {@code CommandBuilder}, already connected to the appropriate
 * {@link CommandDescriptor}.
 * 
 * <BR /><BR />
 * 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.
 * 
 * <BR /><BR />
 * ⚠️ The main purpose of {@code 'CommandBuilder'} is to avoid long, repetitive invocations filled
 * with {@code null} placeholders for optional command parameters.
 * 
 * <EMBED CLASS='external-html' DATA-FILE-ID=CB.Example>
 * 
 * @param <T> The return type produced by the {@link Script} created by this builder's
 * {@link #build()} method.
 * 
 * @see CommandDescriptor
 * @see Script
 * @see Promise
 */
public class CommandBuilder<T>
    extends AbstractBuilder<Script<T>>
    implements java.io.Serializable, Cloneable
{
    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
    protected static final long serialVersionUID = 1L;

    /** 
     * Convert 'this' Builder-Instance into an actual Object-Instance 
     * @return A Script
     */
    @Override
    @SuppressWarnings("unchecked")
    public Script<T> build()
    {
        return BuildScript.build
            ((CommandDescriptor<T>) this.descriptor, this.assignments, this.assigned);
    }

    // used by 'clone'
    private CommandBuilder(final CommandBuilder<T> other)
    { super(other); }

    // used by 'builder'
    private CommandBuilder(final CommandDescriptor<?> descriptor)
    { super(descriptor); }

    public static <T> CommandBuilder<T> builder(final CommandDescriptor<T> descriptor)
    {
        java.util.Objects.requireNonNull(descriptor, "parameter 'descriptor' is null");
        return new CommandBuilder<>(descriptor);
    }

    /** {@inheritDoc} */
    @Override
    public CommandBuilder<T> clone()
    { return new CommandBuilder<>(this); }
    
}