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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package Torello.JavaDoc.SyntaxHiLite;

import Torello.CSS.ClassNameCSSException;

import Torello.HTML.HTMLTags;
import Torello.HTML.TagNode;
import Torello.HTML.SD;
import Torello.HTML.TC;

import Torello.Java.Additional.Ret2;
import Torello.JavaDoc.Annotations.LinkJavaSource;

import java.util.Objects;
import java.util.Arrays;

public class AbstractConfig<T extends AbstractConfig<T>>
    implements java.io.Serializable
{    
    protected static final long serialVersionUID = 1;


    // ********************************************************************************************
    // ********************************************************************************************
    // Class-Config - Fields (These a)
    // ********************************************************************************************
    // ********************************************************************************************


    protected final String[] classNames;

    protected final boolean[] spansOrBolds, utilize;

    protected boolean   upperOrLower_TagName        = true;
    protected boolean   upperOrLower_ClassAttrName  = true;
    protected SD        quotes                      = null;

    final int CONFIG_ARR_LEN;

    final Class<T> captureTheClassDummy;

    protected AbstractConfig(
            final int       CONFIG_ARR_LEN,
            final boolean[] spansOrBolds,
            final Class<T>  captureTheClassDummy
        )
    {
        Objects.requireNonNull
            (spansOrBolds, "The array passed to parameter 'spansOrBolds' is null");

        Objects.requireNonNull
            (captureTheClassDummy, "The class passed to parameter 'captureTheClassDummy' is null");

        if (CONFIG_ARR_LEN < 1) throw new IllegalArgumentException(
            '[' + CONFIG_ARR_LEN + "] was passed to CONFIG_ARR_LEN, but this value must be a " +
            "positive integer that is greater than 0."
        );

        if (spansOrBolds.length != CONFIG_ARR_LEN) throw new IllegalArgumentException(
            "The length of the Array-Parameter 'spansOrBolds' is [" + spansOrBolds.length + "], " +
            "but the value passed to parameter CONFIG_ARR_LENGTH was [" + CONFIG_ARR_LEN + "].  " +
            "These values must be equals."
        );

        this.CONFIG_ARR_LEN         = CONFIG_ARR_LEN;
        this.captureTheClassDummy   = captureTheClassDummy;

        this.classNames     = new String[CONFIG_ARR_LEN];
        this.spansOrBolds   = new boolean[CONFIG_ARR_LEN];
        this.utilize        = new boolean[CONFIG_ARR_LEN];

        for (int i=1; i < CONFIG_ARR_LEN; i++) this.classNames[i]   = "HL-" + i;
        for (int i=0; i < CONFIG_ARR_LEN; i++) this.spansOrBolds[i] = spansOrBolds[i];
        for (int i=0; i < CONFIG_ARR_LEN; i++) this.utilize[i]      = true;
    }

    protected AbstractConfig(AbstractConfig<T> c)
    {
        final int L = this.CONFIG_ARR_LEN = c.CONFIG_ARR_LEN;

        this.captureTheClassDummy = c.captureTheClassDummy;

        this.classNames      = new String[c.CONFIG_ARR_LEN];
        this.spansOrBolds    = new boolean[c.CONFIG_ARR_LEN];
        this.utilize         = new boolean[c.CONFIG_ARR_LEN];

        System.arraycopy(c.classNames,   0, this.classNames,    0, L);
        System.arraycopy(c.spansOrBolds, 0, this.spansOrBolds,  0, L);
        System.arraycopy(c.utilize,      0, this.utilize,       0, L);

        this.upperOrLower_TagName       = c.upperOrLower_TagName;
        this.upperOrLower_ClassAttrName = c.upperOrLower_ClassAttrName;
        this.quotes                     = c.quotes;
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // Class-Config - "Setters" and "Getters" (This is SYNCHRONIZED, That's Why)
    // ********************************************************************************************
    // ********************************************************************************************


    public synchronized AbstractConfig<T> setClassNameCSS(byte whichOne, String className)
    {
        checkWhichOne(whichOne);
        ClassNameCSSException.check(className);
        this.classNames[whichOne] = className;
        return this;
    }

    public synchronized String getClassName(byte whichOne)
    { checkWhichOne(whichOne);  return this.classNames[whichOne]; }

    public synchronized AbstractConfig<T> setSpanOrBold(byte whichOne, boolean spanOrBold)
    {
        checkWhichOne(whichOne);
        this.spansOrBolds[whichOne] = spanOrBold;
        return this;
    }

    public synchronized boolean getSpansOrBolds(byte whichOne)
    { checkWhichOne(whichOne);  return this.spansOrBolds[whichOne]; }

    public synchronized AbstractConfig<T> setUtilizeOrForget(byte whichOne, boolean useOrForget)
    {
        checkWhichOne(whichOne);
        this.utilize[whichOne] = useOrForget;
        return this;
    }

    public synchronized boolean getUtilized(byte whichOne)
    { checkWhichOne(whichOne);  return this.utilize[whichOne]; }

    private void checkWhichOne(byte whichOne)
    {
        if ((whichOne < 1) || (whichOne >= this.CONFIG_ARR_LEN))

            throw new IllegalArgumentException(
                "You have passed an invalid value [" + whichOne + "], to parameter 'whichOne'.  " +
                "This must be a valid byte, whose value is between 1 and " +
                (this.CONFIG_ARR_LEN - 1)
            );
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // STUFF
    // ********************************************************************************************
    // ********************************************************************************************


    @LinkJavaSource(handle="ACGenerateHelper")
    protected Ret2<TagNode[], TagNode[]> generateHiLiterHelper() 
    { return ACGenerateHelper.generate(this); }

    @LinkJavaSource(handle="ACEqualsToString")
    public boolean equals(Object other)
    { return ACEqualsToString.equals(this, other); }

    @LinkJavaSource(handle="ACEqualsToString")
    public int hashCode()
    { return ACEqualsToString.hashCode(this); }
}