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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
package Torello.HTML;

import Torello.Java.StringParse;
import Torello.Java.StrCmpr;
import Torello.Java.StrFilter;

import Torello.HTML.NodeSearch.CSSStrException;
import Torello.HTML.NodeSearch.TextComparitor;

import java.util.Vector;
import java.util.Properties;
import java.util.Map;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

import java.util.stream.Stream;

import javax.management.AttributeNotFoundException;

import java.util.function.Predicate;

import Torello.HTML.HelperPackages.parse.HTMLRegEx;
import Torello.HTML.HelperPackages.TagNode.*;

/**
 * Represents an HTML Element Tag, and is the flagship class of the Java-HTML Library.
 * 
 * <EMBED CLASS='external-html' DATA-FILE-ID=TAG_NODE>
 * <EMBED CLASS='external-html' DATA-FILE-ID=HTML_NODE_SUB_IMG>
 * 
 * @see TextNode
 * @see CommentNode
 * @see HTMLNode
 */
@Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="HTML_NODE_SUBCLASS")
public final class TagNode 
    extends HTMLNode 
    implements CharSequence, java.io.Serializable, Cloneable, Comparable<TagNode>
{
    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
    public static final long serialVersionUID = 1;


    // ********************************************************************************************
    // ********************************************************************************************
    // NON-STATIC FIELDS
    // ********************************************************************************************
    // ********************************************************************************************


    /** <EMBED CLASS='external-html' DATA-FILE-ID=TAGNODE_TOK> */
    public final String tok;

    /** <EMBED CLASS='external-html' DATA-FILE-ID=TAGNODE_IS_CLOSING> */
    public final boolean isClosing;



    // ********************************************************************************************
    // ********************************************************************************************
    // Package-Private Constructors - NO ERROR CHECKING DONE WHATSOEVER
    // ********************************************************************************************
    // ********************************************************************************************


    // ONLY USED BY THE "TagNodeHelpers" and in conjunction with "Generate Element String"
    // 
    // It presumes that the node was properly constructed and needs to error-checking
    // It is only used for opening TagNode's

    TagNode(String tok, String str)
    {
        super(str);

        this.tok        = HTMLTags.getTag_MEM_HEAP_CHECKOUT_COPY(tok);
        this.isClosing  = false;
    }

    // USED-INTERNALLY - bypasses all checks.  used when creating new HTML Element-Names
    // ONLY: class 'HTMLTags' via method 'addTag(...)' shall ever invoke this constructor.
    //
    // NOTE: This only became necessary because of the MEM_COPY_HEAP optimization.  This
    //       optimization expects that there is already a TagNode with element 'tok' in
    //       the TreeSet, which is always OK - except for the method that CREATES NEW HTML
    //       TAGS... a.k.a. HTMLTags.addTag(String).

    TagNode(String token, TC openOrClosed)
    {
        super("<" + ((openOrClosed == TC.ClosingTags) ? "/" : "") + token + ">");

        // ONLY CHANGE CASE HERE, NOT IN PREVIOUS-LINE.  PAY ATTENTION.  
        this.tok = token.toLowerCase();

        this.isClosing = (openOrClosed == TC.ClosingTags) ? true : false;
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // Public Constructors
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_C_DESC_1>
     * 
     * @param s Any valid HTML tag, for instance: {@code <H1>, <A HREF="somoe url">,
     * <DIV ID="some id">} etc...
     * 
     * @throws MalformedTagNodeException If the passed {@code String} wasn't valid - meaning <I>it
     * did not match the regular-expression {@code parser}.</I> 
     * 
     * @throws HTMLTokException If the {@code String} found where the usual HTML token-element is
     * situated <I>is not a valid HTML element</I> then the {@code HTMLTokException} will be
     * thrown.
     * 
     * @see HTMLTags#getTag_MEM_HEAP_CHECKOUT_COPY(String)
     */
    public TagNode(String s)
    {
        super(s);

        // If the second character of the string is a forward-slash, this must be a closing-element
        // For Example: </SPAN>, </DIV>, </A>, etc...

        isClosing = s.charAt(1) == '/';

        // This is the Element & Attribute Matcher used by the RegEx Parser.  If this Matcher
        // doesn't find a match, the parameter 's' cannot be a valid HTML Element.  NOTE: The
        // results of this matcher are also used to retrieve attribute-values, but here below,
        // its results are ignored.

        Matcher m = HTMLRegEx.P1.matcher(s);

        if (! m.find()) throw new MalformedTagNodeException(
            "The parser's regular-expression did not match the constructor-string.\n" +
            "The exact input-string was: [" + s + "]\n" +
            "NOTE:  The parameter-string is included as a field (ex.str) to this Exception.", s
        );

        if ((m.start() != 0) || (m.end() != s.length()))

            throw new MalformedTagNodeException(
                "The parser's regular-expression did not match the entire-string-length of the " +
                "string-parameter to this constructor: m.start()=" + m.start() + ", m.end()=" + 
                m.end() + ".\nHowever, the length of the Input-Parameter String was " +
                '[' + s.length() + "]\nThe exact input-string was: [" + s + "]\nNOTE: The " +
                "parameter-string is included as a field (ex.str) to this Exception.", s
            );

        // MINOR/MAJOR IMPROVEMENT... REUSE THE "ALLOCATED STRING TOKEN" from HTMLTag's class
        // THINK: Let the Garbage Collector take out as many duplicate-strings as is possible..
        // AND SOONER.  DECEMBER 2019: "Optimization" or ... "Improvement"
        // 
        // Get a copy of the 'tok' string that was already allocated on the heap; (OPTIMIZATON)
        //
        // NOTE: There are already myriad strings for the '.str' field.
        // 
        // ALSO: Don't pay much attention to this line if it doesn't make sense... it's not
        //       that important.  If the HTML Token found was not a valid HTML5 token, this field
        //       will be null.
        // 
        // Java 14+ has String.intern() - that's what this is....

        this.tok = HTMLTags.getTag_MEM_HEAP_CHECKOUT_COPY(m.group(1));

        // Now do the usual error check.
        if (this.tok == null) throw new HTMLTokException(
            "The HTML Tag / Token Element that is specified by the input string " +
            "[" + m.group(1).toLowerCase() + "] is not a valid HTML Element Name.\n" +
            "The exact input-string was: [" + s + "]"
        );
    }

    /**
     * Convenience Constructor.
     * <BR />Invokes: {@link #TagNode(String, Properties, Iterable, SD, boolean)}
     * <BR />Passes: null to the Boolean / Key-Only Attributes {@code Iterable}
     */
    public TagNode(
            String      tok,
            Properties  attributes,
            SD          quotes,
            boolean     addEndingForwardSlash
        ) 
    {
        this(
            tok,
            GeneralPurpose.generateElementString(
                tok,
                attributes,
                null, // keyOnlyAttributes,
                quotes,
                addEndingForwardSlash
            ));
    }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_C_DESC_2>
     * @param tok                   <EMBED CLASS='external-html' DATA-FILE-ID=TN_C_TOK>
     * @param attributes            <EMBED CLASS='external-html' DATA-FILE-ID=TN_C_ATTRIBUTES>
     * @param keyOnlyAttributes     <EMBED CLASS='external-html' DATA-FILE-ID=TN_C_KO_ATTRIBUTES>
     * @param quotes                <EMBED CLASS='external-html' DATA-FILE-ID=TN_C_QUOTES>
     * @param addEndingForwardSlash <EMBED CLASS='external-html' DATA-FILE-ID=TN_C_AEFS>
     * @throws InnerTagKeyException <EMBED CLASS='external-html' DATA-FILE-ID=IT_KEY_EX_PROP_TN>
     * @throws QuotesException      <EMBED CLASS='external-html' DATA-FILE-ID=QEX>
     * 
     * @throws HTMLTokException if an invalid HTML 4 or 5 token is not present
     * <B>(check is {@code CASE_INSENSITIVE})</B>, or a token which has been registered with class
     * {@code HTMLTags}.
     * 
     * @see InnerTagKeyException#check(String, String)
     * @see QuotesException#check(String, SD, String)
     */
    public TagNode(
            String              tok,
            Properties          attributes,
            Iterable<String>    keyOnlyAttributes,
            SD                  quotes,
            boolean             addEndingForwardSlash
        )
    {
        this(
            tok,
            GeneralPurpose.generateElementString
                (tok, attributes, keyOnlyAttributes, quotes, addEndingForwardSlash)
        );
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // HTMLNode Overidden - Loop & Stream Optimization Methods
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * This method identifies that {@code 'this'} instance of (abstract parent-class)
     * {@link HTMLNode} is, indeed, an instance of sub-class {@code TagNode}.
     *
     * <BR /><BR /><B CLASS=JDDescLabel>Final Method:</B>
     * 
     * <BR />This method is final, and cannot be modified by sub-classes.
     * 
     * @return This method shall always return {@code TRUE}  It overrides the parent-class
     * {@code HTMLNode} method {@link #isTagNode()}, which always returns {@code FALSE}.
     */
    @Override
    public final boolean isTagNode() { return true; }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_IF_TN_DESC>
     * <BR /><BR /><B CLASS=JDDescLabel>Final Method:</B>
     * <BR />This method is final, and cannot be modified by sub-classes.
     * @return <EMBED CLASS='external-html' DATA-FILE-ID=TN_IF_TN_RET>
     */
    @Override
    public final TagNode ifTagNode() { return this; }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_OPENTAG_PWA_DESC>
     * <BR /><BR /><B CLASS=JDDescLabel>Final Method:</B>
     * <BR />This method is final, and cannot be modified by sub-classes.
     * @return <EMBED CLASS='external-html' DATA-FILE-ID=TN_OPENTAG_PWA_RET>
     */
    @Override
    public final TagNode openTagPWA()
    {
        // Closing TagNode's simply may not have attributes
        if (this.isClosing) return null;

        // A TagNode whose '.str' field is not AT LEAST 4 characters LONGER than the length of the
        // HTML-Tag / Token, simply cannot have an attribute.
        //
        // NOTE: Below is the shortest possible HTML tag that could have an attribute.
        // COMPUTE: '<' + TOK.LENGTH + SPACE + 'c' + '>'

        if (this.str.length() < (this.tok.length() + 4)) return null;

        // This TagNode is an opening HTML tag (like <DIV ...>, rather than </DIV>),
        // and there are at least two additional characters after the token, such as: <DIV A...>
        // It is not guaranteed that this tag has attributes, but it is possibly - based on these
        /// optimization methods, and further investigation would have merit.

        return this;
    }

    /**
     * This is a loop-optimization method that makes finding opening {@code TagNode's} - <B>with
     * attribute-</B><B STYLE='color: red;'>values</B> - quites a bit faster.  All {@link HTMLNode}
     * subclasses implement this method, but only {@code TagNode} instances will ever return a
     * non-null value.
     * 
     * <BR /><BR /><B CLASS=JDDescLabel>Final Method:</B>
     * 
     * <BR />This method is final, and cannot be modified by sub-classes.
     * 
     * @return Returns null if and only if {@code 'this'} instance' {@link #isClosing} field is
     * false.  When a non-null return-value is acheived, that value will always be {@code 'this'}
     * instance.
     */
    @Override
    public final TagNode openTag()
    { return isClosing ? null : this; }

    /**
     * This method is an optimization method that overrides the one by the same name in class
     * {@link HTMLNode}.
     * 
     * {@inheritdoc}
     */
    @Override
    public boolean isOpenTagPWA()
    {
        if (this.isClosing) return false;
        if (this.str.length() < (this.tok.length() + 4)) return false;
        return true;
    }

    /**
     * This method is an optimization method that overrides the one by the same name in class
     * {@link HTMLNode}.
     * 
     * {@inheritdoc}
     */
    @Override
    public boolean isOpenTag()
    { return ! isClosing; }


    // ********************************************************************************************
    // ********************************************************************************************
    // isTag
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_IS_TAG1_DESC>
     * @param possibleTags  A non-null list of potential HTML tags to be checked again {@link #tok}
     * @return              <EMBED CLASS='external-html' DATA-FILE-ID=TN_IS_TAG1_RET>
     * @see                 #tok
     */
    public boolean isTag(String... possibleTags)
    { 
        for (String htmlTag : possibleTags) if (htmlTag.equalsIgnoreCase(this.tok)) return true;
        return false;
    }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_IS_TAG_EX1_DESC>
     * @param possibleTags  A non-null list of potential HTML tags to be checked again {@link #tok}
     * @return              <EMBED CLASS='external-html' DATA-FILE-ID=TN_IS_TAG_EX1_RET>
     * @see                 #tok
     * @see                 #isTag(String[])
     */
    public boolean isTagExcept(String... possibleTags)
    { 
        for (String htmlTag : possibleTags) if (htmlTag.equalsIgnoreCase(this.tok)) return false;
        return true;
    }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_IS_TAG2_DESC>
     * @param tagCriteria   <EMBED CLASS='external-html' DATA-FILE-ID=TN_IS_TAG2_PARAM>
     * @param possibleTags  A non-null list of potential HTML tags to be checked again {@link #tok}
     * @return              <EMBED CLASS='external-html' DATA-FILE-ID=TN_IS_TAG2_RET>
     * @see                 #tok
     */
    public boolean isTag(TC tagCriteria, String... possibleTags)
    { return IsTag.isTag(this, tagCriteria, possibleTags); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_IS_TAG_EX2_DESC>
     * @param tagCriteria   <EMBED CLASS='external-html' DATA-FILE-ID=TN_IS_TAG_EX2_PARAM>
     * @param possibleTags  A non-null list of potential HTML tags to be checked again {@link #tok}
     * @return              <EMBED CLASS='external-html' DATA-FILE-ID=TN_IS_TAG_EX2_RET>
     * @see                 #tok
     */
    public boolean isTagExcept(TC tagCriteria, String... possibleTags)
    { return IsTag.isTagExcept(this, tagCriteria, possibleTags); }


    // ********************************************************************************************
    // ********************************************************************************************
    // Main Method 'AV'
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_AV_DESC>
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_AV_DESC_EXAMPLE>
     * @param innerTagAttribute <EMBED CLASS='external-html' DATA-FILE-ID=TN_AV_ITA>
     * @return                  <EMBED CLASS='external-html' DATA-FILE-ID=TN_AV_RET>
     * @see StringParse#ifQuotesStripQuotes(String)
     */
    public String AV(String innerTagAttribute)
    { return GetSetAttr.AV(this, innerTagAttribute, false); }

    /**
     * Identical to {@link #AV(String)}, except that if the
     * Attribute-<B STYLE='color: red;'>value</B> had quotes surrounding it, those are included in
     * the returned {@code String}.
     */
    // To-Do, finish this after brekfast
    // public String preserveQuotesAV(String innerTagAttribute)
    // { return GetSetAttr.AV(this, innerTagAttribute, true); }

    /**
     * <B STYLE='color: red;'>AVOPT: Attribute-Value - Optimized</B>
     * 
     * <BR /><BR /> This is an "optimized" version of method {@link #AV(String)}.  This method does
     * the exact same thing as {@code AV(...)}, but leaves out parameter-checking and
     * error-checking. This is used internally (and repeatedly) by the NodeSearch Package Search
     * Loops.
     * 
     * @param innerTagAttribute This is the inner-tag / attribute <B STYLE='color: red;'>name</B>
     * whose <B STYLE='color: red;'>value</B> is hereby being requested.
     * 
     * @return {@code String}-<B STYLE='color: red;'>value</B> of this inner-tag / attribute.
     * 
     * @see StringParse#ifQuotesStripQuotes(String)
     * @see #str
     */
    public String AVOPT(String innerTagAttribute)
    {
        // COPIED DIRECTLY FROM class TagNode, leaves off initial tests.

        // Matches "Attribute / Inner-Tag Key-Value" Pairs.
        Matcher m = AttrRegEx.KEY_VALUE_REGEX.matcher(this.str);

        // This loop iterates the KEY_VALUE PAIRS THAT HAVE BEEN FOUND.
        /// NOTE: The REGEX Matches on Key-Value Pairs.

        while (m.find())

            // m.group(2) is the "KEY" of the Attribute KEY-VALUE Pair
            // m.group(3) is the "VALUE" of the Attribute.

            if (m.group(2).equalsIgnoreCase(innerTagAttribute))
                return StringParse.ifQuotesStripQuotes(m.group(3));

        // This means the attribute name provided to parameter 'innerTagAttribute' was not found.
        return null;
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // Attribute Modify-Value methods
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_AV_DESC>
     * @param attribute <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_AV_ATTR>
     * 
     * @param value Any valid attribute-<B STYLE='color: red;'>value</B>.  This parameter may not
     * be null, or a {@code NullPointerException} will throw.
     * 
     * @param quote                     <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_AV_QUOTE>
     * @throws InnerTagKeyException     <EMBED CLASS='external-html' DATA-FILE-ID=IT_KEY_EX_TN>
     * @throws QuotesException          <EMBED CLASS='external-html' DATA-FILE-ID=QEX>
     * @throws ClosingTagNodeException  <EMBED CLASS='external-html' DATA-FILE-ID=CTNEX>
     * 
     * @throws HTMLTokException If an invalid HTML 4 or 5 token is not present 
     * (<B>{@code CASE_INSENSITIVE}</B>).
     * 
     * @return <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_AV_RET>
     * @see ClosingTagNodeException#check(TagNode)
     * @see #setAV(Properties, SD)
     * @see #str
     * @see #isClosing
     */
    public TagNode setAV(String attribute, String value, SD quote)
    { return GetSetAttr.setAV(this, attribute, value, quote); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_AV2_DESC>
     * @param attributes These are the new attribute <B STYLE='color: red;'>key-value</B> pairs to
     * be inserted.
     * 
     * @param defaultQuote <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_AV2_DQ_PARAM>
     * @throws InnerTagKeyException <EMBED CLASS='external-html' DATA-FILE-ID=IT_KEY_EX_PROP_TN>
     * 
     * @throws QuotesException if there are "quotes within quotes" problems, due to the
     * <B STYLE='color: red;'>values</B> of the <B STYLE='color: red;'>key-value</B> pairs.
     * 
     * @throws HTMLTokException if an invalid HTML 4 or 5 token is not present 
     * <B>({@code CASE_INSENSITIVE})</B>
     * 
     * @throws ClosingTagNodeException <EMBED CLASS='external-html' DATA-FILE-ID=CTNEX>
     *
     * @return <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_AV2_RET>
     * @see ClosingTagNodeException#check(TagNode)
     * @see #setAV(String, String, SD)
     * @see #isClosing
     */
    public TagNode setAV(Properties attributes, SD defaultQuote)
    { return GetSetAttr.setAV(this, attributes, defaultQuote); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_APD_AV_DESC>
     * @param attribute                 <EMBED CLASS=external-html DATA-FILE-ID=TN_APD_AV_P_ATTR>
     * @param appendStr                 <EMBED CLASS=external-html DATA-FILE-ID=TN_APD_AV_P_APDSTR>
     * @param startOrEnd                <EMBED CLASS=external-html DATA-FILE-ID=TN_APD_AV_P_S_OR_E>
     * @param quote                     <EMBED CLASS=external-html DATA-FILE-ID=TGND_QUOTE_EXPL>
     *                                  <EMBED CLASS=external-html DATA-FILE-ID=TN_APD_AV_P_QXTRA>
     * @return                          <EMBED CLASS=external-html DATA-FILE-ID=TN_APD_AV_RET>
     * @see                             #AV(String)
     * @see                             #setAV(String, String, SD)
     * @see                             ClosingTagNodeException#check(TagNode)
     * @throws ClosingTagNodeException  <EMBED CLASS='external-html' DATA-FILE-ID=CTNEX>
     * 
     * @throws QuotesException The <B><A HREF=#QUOTEEX>rules</A></B> for quotation usage apply
     * here too, and see that explanation for how how this exception could be thrown.
     */
    public TagNode appendToAV(String attribute, String appendStr, boolean startOrEnd, SD quote)
    { return GetSetAttr.appendToAV(this, attribute, appendStr, startOrEnd, quote); }   


    // ********************************************************************************************
    // ********************************************************************************************
    // Attribute Removal Operations
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Invokes: {@link #removeAttributes(String[])}
     */
    public TagNode remove(String attributeName)
    {
        return RemoveAttributes.removeAttributes
            (this, (String attr) -> ! attr.equalsIgnoreCase(attributeName));
    }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_REM_ATTR_DESC>
     * @param attributes                <EMBED CLASS='external-html' DATA-FILE-ID=TN_REM_ATTR_ATTR>
     * @return                          <EMBED CLASS='external-html' DATA-FILE-ID=TN_REM_ATTR_RET>
     * @throws ClosingTagNodeException  <EMBED CLASS='external-html' DATA-FILE-ID=CTNEX>
     * @see                             ClosingTagNodeException#check(TagNode)
     */
    public TagNode removeAttributes(String... attributes)
    {
        return RemoveAttributes.removeAttributes
            (this, (String attr) -> StrCmpr.equalsNAND_CI(attr, attributes));
    }

    /**
     * Filter's attributes using an Attribute-<B STYLE='color:red'>Name</B>
     * {@code String-Predicate}
     * 
     * @param attrNameTest Any Java {@code String-Predicate}.  It will be used to test whether or
     * not to keep or filter/reject an attribute from {@code 'this' TagNode}.
     * 
     * <BR /><BR /><B STYLE='color: red;'>NOTE:</B> Like all filter-{@code Predicate's}, this
     * test's expected behavior is such that it should return {@code TRUE} when it would like to 
     * keep an attribute having a particular <B STYLE='color: red;'>name</B>, and return
     * {@code FALSE} when it would like to see the attribute removed from the HTML Tag.
     * 
     * @return Removes any Attributes whoe <B STYLE='color: red;'>name</B> as per the rules of the
     * User-Provided {@code String-Predicate} parameter {@code 'attrNameTest'}.  As with all 
     * {@code TagNode} modification operations, if any changes are, indeed, made to a new instance 
     * of {@code TagNode} will be created and returned.
     */
    public TagNode removeAttributes(Predicate<String> attrNameTest)
    { return RemoveAttributes.removeAttributes(this, attrNameTest); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_REM_ALL_AV_DESC>
     * @return                          <EMBED CLASS=external-html DATA-FILE-ID=TN_REM_ALL_AV_RET>
     * @throws ClosingTagNodeException  <EMBED CLASS=external-html DATA-FILE-ID=CTNEX>
     * @see                             ClosingTagNodeException#check(TagNode)
     * @see                             #getInstance(String, TC)
     * @see                             TC#OpeningTags
     */
    public TagNode removeAllAV()
    {
        ClosingTagNodeException.check(this);

        // NOTE: We *CANNOT* use the 'tok' field to instantiate the TagNode here, because the 'tok'
        // String-field is *ALWAYS* guaranteed to be in a lower-case format.  The 'str'
        // String-field, however uses the original case that was found on the HTML Document by the
        // parser (or in the Constructor-Parameters that were passed to construct 'this' instance
        // of TagNode.

        return getInstance(this.str.substring(1, 1 + tok.length()), TC.OpeningTags);
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // Retrieve all attributes
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Invokes: {@link #allAV(boolean, boolean)}
     * <BR />Attribute-<B STYLE='color: red;'>names</B> will be in lower-case.
     */
    public Properties allAV()
    { return RetrieveAllAttr.allAV(this, false, false);  }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_ALL_AV_DESC>
     * @param keepQuotes        <EMBED CLASS='external-html' DATA-FILE-ID=TN_ALL_AV_KQ_PARAM>
     * @param preserveKeysCase  <EMBED CLASS='external-html' DATA-FILE-ID=TN_ALL_AV_PKC_PARAM>
     *                          <EMBED CLASS='external-html' DATA-FILE-ID=TAGNODE_PRESERVE_C>
     * @return                  <EMBED CLASS='external-html' DATA-FILE-ID=TN_ALL_AV_RET>
     * @see                     StringParse#ifQuotesStripQuotes(String)
     */
    public Properties allAV(boolean keepQuotes, boolean preserveKeysCase)
    { return RetrieveAllAttr.allAV(this, keepQuotes, preserveKeysCase); }

    /**
     * Convenience Method.
     * <BR />Invokes: {@link #allAN(boolean, boolean)}
     * <BR />Attribute-<B STYLE='color: red;'>names</B> will be in lower-case
     */
    public Stream<String> allAN()
    { return RetrieveAllAttr.allAN(this, false, false); }

    /**
     * This method will only return a list of attribute-<B STYLE='color: red;'>names</B>.  The
     * attribute-<B STYLE="color: red">values</B> shall <B>NOT</B> be included in the result.  The
     * {@code String's} returned can have their "case-preserved" by passing {@code TRUE} to the
     * input boolean parameter {@code 'preserveKeysCase'}.
     *
     * @param preserveKeysCase If this is parameter receives {@code TRUE} then the case of the
     * attribute-<B STYLE='color: red;'>names</B> shall be preserved.
     *
     * <EMBED CLASS='external-html' DATA-FILE-ID=TAGNODE_PRESERVE_C>
     *
     * @param includeKeyOnlyAttributes When this parameter receives {@code TRUE}, then any
     * "Boolean Attributes" or "Key-Only, No-Value-Assignment" Inner-Tags will <B>ALSO</B> be
     * included in the {@code Stream<String>} returned by this method.
     *
     * @return an instance of {@code Stream<String>} containing all
     * attribute-<B STYLE='color: red;'>names</B> identified in {@code 'this'} instance of
     * {@code TagNode}.  A {@code java.util.stream.Stream} is used because it's contents can easily
     * be converted to just about any data-type.  
     *
     * <EMBED CLASS='external-html' DATA-FILE-ID=STRMCNVT>
     *
     * <BR /><B>NOTE:</B> This method shall never return {@code 'null'} - even if there are no 
     * attribute <B STYLE='color: red;'>key-value</B> pairs contained by {@code 'this' TagNode}.
     * If there are strictly zero attributes, an empty {@code Stream} shall be returned, instead.
     * 
     * @see #allKeyOnlyAttributes(boolean)
     * @see #allAN()
     */
    public Stream<String> allAN(boolean preserveKeysCase, boolean includeKeyOnlyAttributes)
    { return RetrieveAllAttr.allAN(this, preserveKeysCase, includeKeyOnlyAttributes); }


    // ********************************************************************************************
    // ********************************************************************************************
    // Key only attributes
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_ALL_KOA_DESC>
     * @param preserveKeysCase  <EMBED CLASS='external-html' DATA-FILE-ID=TN_ALL_KOA_PKC>
     *                          <EMBED CLASS='external-html' DATA-FILE-ID=TAGNODE_PRESERVE_C>
     * @return                  <EMBED CLASS='external-html' DATA-FILE-ID=TN_ALL_KOA_RET>
     *                          <EMBED CLASS='external-html' DATA-FILE-ID=STRMCNVT>
     */
    public Stream<String> allKeyOnlyAttributes(boolean preserveKeysCase)
    { return KeyOnlyAttributes.allKeyOnlyAttributes(this, preserveKeysCase); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_HAS_KOA_DESC>
     * @param keyOnlyAttribute          <EMBED CLASS='external-html' DATA-FILE-ID=TN_HAS_KOA_KOA>
     * @return                          <EMBED CLASS='external-html' DATA-FILE-ID=TN_HAS_KOA_RET>
     * @throws IllegalArgumentException <EMBED CLASS='external-html' DATA-FILE-ID=TN_HAS_KOA_IAEX>
     */
    public boolean hasKeyOnlyAttribute(String keyOnlyAttribute)
    { return KeyOnlyAttributes.hasKeyOnlyAttribute(this, keyOnlyAttribute); }


    // ********************************************************************************************
    // ********************************************************************************************
    // testAV
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Passes: {@code String.equalsIgnoreCase(attributeValue)} to the Test-{@code Predicate}
     * @see #testAV(String, Predicate)
     */
    public boolean testAV(String attributeName, String attributeValue)
    {
        return HasAndTest.testAV
            (this, attributeName, (String s) -> s.equalsIgnoreCase(attributeValue));
    }

    /**
     * Convenience Method.
     * <BR />Passes: {@code attributeValueTest.asPredicate()}
     * @see #testAV(String, Predicate)
     */
    public boolean testAV(String attributeName, Pattern attributeValueTest)
    { return HasAndTest.testAV(this, attributeName, attributeValueTest.asPredicate()); }

    /**
     * Convenience Method.
     * <BR />Passes: {@link TextComparitor#test(String, String[])} to the Test-{@code Predicate}
     * @see #testAV(String, Predicate)
     */
    public boolean testAV
        (String attributeName, TextComparitor attributeValueTester, String... compareStrs)
    {
        return HasAndTest.testAV
            (this, attributeName, (String s) -> attributeValueTester.test(s, compareStrs));
    }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_TEST_AV_DESC>
     * @param attributeName         <EMBED CLASS='external-html' DATA-FILE-ID=TN_TEST_AV_PARAM>
     * @param attributeValueTest    Any {@code java.util.function.Predicate<String>}
     * @return                      <EMBED CLASS='external-html' DATA-FILE-ID=TN_TEST_AV_RET>
     * @see                         StringParse#ifQuotesStripQuotes(String)
     */
    public boolean testAV(String attributeName, Predicate<String> attributeValueTest)
    { return HasAndTest.testAV(this, attributeName, attributeValueTest); }


    // ********************************************************************************************
    // ********************************************************************************************
    // has-attribute boolean-logic methods
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Passes: AND Boolean Logic
     * <BR />Checks that <B STYLE='color: red;'><I>all</I></B> Attributes are found
     * @see #hasXOR(boolean, String...)
     */
    public boolean hasAND(boolean checkAttributeStringsForErrors, String... attributes)
    {
        // First-Function:  Tells the logic to *IGNORE* intermediate matches (returns NULL)
        //                  (This is *AND*, so wait until all attributes have been found, or at
        //                  the very least all tags in the element tested, and failed.
        //
        // Second-Function: At the End of the Loops, all Attributes have either been found, or
        //                  at least all attributes in 'this' tag have been tested.  Note that the
        //                  first-function is only called on a MATCH, and that 'AND' requires to
        //                  defer a response until all attributes have been tested..  Here, simply
        //                  RETURN WHETHER OR NOT the MATCH-COUNT equals the number of matches in
        //                  the user-provided String-array.

        return HasAndTest.hasLogicOp(
            this,
            checkAttributeStringsForErrors,
            (int matchCount) -> null,
            (int matchCount) -> (matchCount == attributes.length),
            attributes
        );
    }

    /**
     * Convenience Method.
     * <BR />Passes: OR Boolean Logic
     * <BR />Checks that <B STYLE='color: red;'><I>at least one</I></B> of the Attributes match
     * @see #hasXOR(boolean, String...)
     */
    public boolean hasOR(boolean checkAttributeStringsForErrors, String... attributes)
    {
        // First-Function:  Tells the logic to return TRUE on any match IMMEDIATELY
        //
        // Second-Function: At the End of the Loops, all Attributes have been tested.  SINCE the
        //                  previous function returns on match immediately, AND SINCE this is an
        //                  OR, therefore FALSE must be returned (since there were no matches!)

        return HasAndTest.hasLogicOp(
            this,
            checkAttributeStringsForErrors,
            (int matchCount) -> true,
            (int matchCount) -> false,
            attributes
        );
    }

    /**
     * Convenience Method.
     * <BR />Passes: NAND Boolean Logic
     * <R />Checks that <B STYLE='color: red;'><I>none</I></B> of the Attributes match
     * @see #hasXOR(boolean, String...)
     */
    public boolean hasNAND(boolean checkAttributeStringsForErrors, String... attributes)
    {
        // First-Function: Tells the logic to return FALSE on any match IMMEDIATELY
        //
        // Second-Function: At the End of the Loops, all Attributes have been tested.  SINCE
        //                  the previous function returns on match immediately, AND SINCE this is
        //                  a NAND, therefore TRUE must be returned (since there were no matches!)

        return HasAndTest.hasLogicOp(
            this,
            checkAttributeStringsForErrors,
            (int matchCount) -> false,
            (int matchCount) -> true,
            attributes
        );
    }

    /**
     * Convenience Method.
     * <BR />Passes: XOR Boolean Logic
     * <BR />Checks that <B STYLE='color: red;'><I>precisely-one</I></B> Attribute is found
     * <BR /><IMG SRC='doc-files/img/hasAND.png' CLASS=JDIMG ALT=Example>
     * 
     * @param checkAttributeStringsForErrors
     * <EMBED CLASS='external-html' DATA-FILE-ID=TAGNODE_HAS_BOOL>
     * 
     * <BR /><BR /><B>NOTE:</B> If this method is passed a zero-length {@code String}-array to the
     * {@code 'attributes'} parameter, this method shall exit immediately and return {@code FALSE}.
     * 
     * @throws InnerTagKeyException If any of the {@code 'attributes'} are not valid HTML
     * attributes, <I><B>and</B></I> the user has passed {@code TRUE} to parameter
     * {@code checkAttributeStringsForErrors}.
     * 
     * @throws NullPointerException     If any of the {@code 'attributes'} are null.
     * @throws ClosingTagNodeException  <EMBED CLASS='external-html' DATA-FILE-ID=CTNEX>
     * @throws IllegalArgumentException If the {@code 'attributes'} parameter has length zero.
     * @see                             InnerTagKeyException#check(String[])
     */
    public boolean hasXOR(boolean checkAttributeStringsForErrors, String... attributes)
    {
        // First-Function: Tells the logic to IGNORE the FIRST MATCH, and any matches afterwards
        //                 should produce a FALSE result immediately
        //                 (XOR means ==> one-and-only-one)
        //
        // Second-Function: At the End of the Loops, all Attributes have been tested.  Just
        //                  return whether or not the match-count is PRECISELY ONE.

        return HasAndTest.hasLogicOp(
            this,
            checkAttributeStringsForErrors,
            (int matchCount) -> (matchCount == 1) ? null : false,
            (int matchCount) -> (matchCount == 1),
            attributes
        );
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // has methods - extended, variable attribute-names
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Passes: {@code String.equalsIgnoreCase(attributeName)} as the test-{@code Predicate}
     * @see #has(Predicate)
     */
    public boolean has(String attributeName)
    { return HasAndTest.has(this, (String s) -> s.equalsIgnoreCase(attributeName)); }

    /**
     * Convenience Method.
     * <BR />Passes: {@code Pattern.asPredicate()}
     * @see #has(Predicate)
     */
    public boolean has(Pattern attributeNameRegExTest)
    { return HasAndTest.has(this, attributeNameRegExTest.asPredicate()); }

    /**
     * Convenience Method.
     * <BR />Passes: {@link TextComparitor#test(String, String[])} as the test-{@code Predicate}
     * @see #has(Predicate)
     */
    public boolean has(TextComparitor tc, String... compareStrs)
    { return HasAndTest.has(this, (String s) -> tc.test(s, compareStrs)); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_HAS_DESC2>
     * <EMBED CLASS='external-html' DATA-FILE-ID=TAGNODE_HAS_NOTE>
     * @param attributeNameTest <EMBED CLASS='external-html' DATA-FILE-ID=TN_HAS_ANT>
     * @return                  <EMBED CLASS='external-html' DATA-FILE-ID=TN_HAS_RET2>
     * @see                     StrFilter
     */
    public boolean has(Predicate<String> attributeNameTest)
    { return HasAndTest.has(this, attributeNameTest); }


    // ********************************************************************************************
    // ********************************************************************************************
    // hasValue(...) methods
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Passes: {@code String.equals(attributeValue)} as the test-{@code Predicate}
     * @see #hasValue(Predicate, boolean, boolean)
     */
    public Map.Entry<String, String> hasValue
        (String attributeValue, boolean retainQuotes, boolean preserveKeysCase)
    {
        return HasAndTest.hasValue
            (this, (String s) -> attributeValue.equals(s), retainQuotes, preserveKeysCase);
    }

    /**
     * Convenience Method.
     * <BR />Passes: {@code attributeValueRegExTest.asPredicate()}
     * @see #hasValue(Predicate, boolean, boolean)
     */
    public Map.Entry<String, String> hasValue
        (Pattern attributeValueRegExTest, boolean retainQuotes, boolean preserveKeysCase)
    {
        return HasAndTest.hasValue
            (this, attributeValueRegExTest.asPredicate(), retainQuotes, preserveKeysCase);
    }

    /**
     * Convenience Method.
     * <BR />Passes: {@link TextComparitor#test(String, String[])} as the test-{@code Predicate}
     * @see #hasValue(Predicate, boolean, boolean)
     */
    public Map.Entry<String, String> hasValue(
            boolean retainQuotes, boolean preserveKeysCase, TextComparitor attributeValueTester,
            String... compareStrs
        )
    {
        return HasAndTest.hasValue(
            this,
            (String s) -> attributeValueTester.test(s, compareStrs),
            retainQuotes,
            preserveKeysCase
        );
    }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_HASVAL_DESC2>
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_HASVAL_DNOTE>
     * @param attributeValueTest    <EMBED CLASS='external-html' DATA-FILE-ID=TN_HASVAL_AVT>
     * @param retainQuotes          <EMBED CLASS='external-html' DATA-FILE-ID=TN_HASVAL_RQ>
     * @param preserveKeysCase      <EMBED CLASS='external-html' DATA-FILE-ID=TN_HASVAL_PKC>
     *                              <EMBED CLASS='external-html' DATA-FILE-ID=TAGNODE_PRESERVE_C>
     * @return                      <EMBED CLASS='external-html' DATA-FILE-ID=TN_HASVAL_RET2>
     * @see                         StrFilter
     */
    public Map.Entry<String, String> hasValue
        (Predicate<String> attributeValueTest, boolean retainQuotes, boolean preserveKeysCase)
    { return HasAndTest.hasValue(this, attributeValueTest, retainQuotes, preserveKeysCase); }


    // ********************************************************************************************
    // ********************************************************************************************
    // getInstance()
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_GETINST_DESC>
     * @param tok Any valid HTML tag.
     * @param openOrClosed <EMBED CLASS='external-html' DATA-FILE-ID=TN_GETINST_OOC>
     * @return An instance of this class
     * 
     * @throws IllegalArgumentException If parameter {@code TC openOrClose} is {@code null} or
     * {@code TC.Both}
     * 
     * @throws HTMLTokException If the parameter {@code String tok} is not a valid HTML-tag
     * 
     * @throws SingletonException If the token requested is a {@code singleton} (self-closing) tag,
     * but the Tag-Criteria {@code 'TC'} parameter is requesting a closing-version of the tag.
     * 
     * @see HTMLTags#hasTag(String, TC)
     * @see HTMLTags#isSingleton(String)
     */
    public static TagNode getInstance(String tok, TC openOrClosed)
    {
        if (openOrClosed == null)
            throw new NullPointerException("The value of openOrClosed cannot be null.");

        if (openOrClosed == TC.Both)
            throw new IllegalArgumentException("The value of openOrClosed cannot be TC.Both.");

        if (HTMLTags.isSingleton(tok) && (openOrClosed == TC.ClosingTags))

            throw new SingletonException(
                "The value of openOrClosed is TC.ClosingTags, but unfortunately you have asked " +
                "for a [" + tok + "] HTML element, which is a singleton element, and therefore " +
                "cannot have a closing-tag instance."
            );

        TagNode ret = HTMLTags.hasTag(tok, openOrClosed);

        if (ret == null)
            throw new HTMLTokException
                ("The HTML-Tag provided isn't valid!\ntok: " + tok + "\nTC: " + openOrClosed);

        return ret;
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // Methods for "CSS Classes"
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Invokes: {@link #cssClasses()}
     * <BR />Catches-Exception
     */
    public Stream<String> cssClassesNOCSE()
    { try { return cssClasses(); } catch (CSSStrException e) { return Stream.empty(); } }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_CSS_CL_DESC>
     * @return                  <EMBED CLASS='external-html' DATA-FILE-ID=TN_CSS_CL_RET>
     *                          <EMBED CLASS='external-html' DATA-FILE-ID=STRMCNVT>
     * @throws CSSStrException  <EMBED CLASS='external-html' DATA-FILE-ID=TN_CSS_CL_CSSSE>
     * @see                     #cssClasses()
     * @see                     #AV(String)
     * @see                     StringParse#WHITE_SPACE_REGEX
     * @see                     CSSStrException#check(Stream)
     */
    public Stream<String> cssClasses()
    { return ClassIDStyle.cssClasses(this); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_CSS_CL_DESC>
     * @param quote             <EMBED CLASS='external-html' DATA-FILE-ID=TGND_QUOTE_EXPL>
     * @param appendOrClobber   <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_CSS_CL_AOC>
     * @param cssClasses        <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_CSS_CL_CCL>
     * @return                  <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_CSS_CL_RET>
     * 
     * @throws CSSStrException This exception shall throw if any of the {@code 'cssClasses'} in the
     * var-args {@code String...} parameter do not meet the HTML 5 CSS {@code Class} naming rules.
     * 
     * @throws ClosingTagNodeException  <EMBED CLASS=external-html DATA-FILE-ID=CTNEX>
     * @throws QuotesException          <EMBED CLASS=external-html DATA-FILE-ID=TN_SET_CSS_CL_QEX>
     * @see                             CSSStrException#check(String[])
     * @see                             CSSStrException#VALID_CSS_CLASS_OR_NAME_TOKEN
     * @see                             #appendToAV(String, String, boolean, SD)
     * @see                             #setAV(String, String, SD)
     */
    public TagNode setCSSClasses(SD quote, boolean appendOrClobber, String... cssClasses)
    { return ClassIDStyle.setCSSClasses(this, quote, appendOrClobber, cssClasses); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_APD_CSS_CL_DESC>
     * @param cssClass This is the CSS-{@code Class} name that is being inserted into
     * {@code 'this'} instance of {@code TagNode}
     * 
     * @param quote                     <EMBED CLASS=external-html DATA-FILE-ID=TGND_QUOTE_EXPL>
     * @return                          A new {@code TagNode} with updated CSS {@code Class} Name(s)
     * @throws CSSStrException          <EMBED CLASS=external-html DATA-FILE-ID=TN_APD_CSS_CL_CSSSE>
     * @throws ClosingTagNodeException  <EMBED CLASS=external-html DATA-FILE-ID=CTNEX>
     * @throws QuotesException          <EMBED CLASS=external-html DATA-FILE-ID=TN_APD_CSS_CL_QEX>
     * @see                             CSSStrException#check(String[])
     * @see                             #setAV(String, String, SD)
     * @see                             #appendToAV(String, String, boolean, SD)
     */
    public TagNode appendCSSClass(String cssClass, SD quote)
    { return ClassIDStyle.appendCSSClass(this, cssClass, quote); }


    // ********************************************************************************************
    // ********************************************************************************************
    // Methods for "CSS Style"
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_CSS_STYLE_DESC>
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_CSS_STYLE_DESCEX>
     * @return <EMBED CLASS='external-html' DATA-FILE-ID=TN_CSS_STYLE_RET>
     */
    public Properties cssStyle()
    { return ClassIDStyle.cssStyle(this); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_CSS_STY_DESC>
     * @param p                         <EMBED CLASS=external-html DATA-FILE-ID=TN_SET_CSS_STY_P>
     * @param quote                     <EMBED CLASS=external-html DATA-FILE-ID=TGND_QUOTE_EXPL>
     * @param appendOrClobber           <EMBED CLASS=external-html DATA-FILE-ID=TN_SET_CSS_STY_AOC>
     * @return                          <EMBED CLASS=external-html DATA-FILE-ID=TN_SET_CSS_STY_RET>
     * @throws ClosingTagNodeException  <EMBED CLASS=external-html DATA-FILE-ID=CTNEX>
     * @throws CSSStrException          If there is an invalid CSS Style Property Name.
     * 
     * @throws QuotesException If the style-element's quotation marks are incompatible with any
     * and all quotation marks employed by the style-element definitions.
     * 
     * @see CSSStrException#VALID_CSS_CLASS_OR_NAME_TOKEN
     * @see #appendToAV(String, String, boolean, SD)
     * @see #setAV(String, String, SD)
     */
    public TagNode setCSSStyle(Properties p, SD quote, boolean appendOrClobber)
    { return ClassIDStyle.setCSSStyle(this, p, quote, appendOrClobber); }


    // ********************************************************************************************
    // ********************************************************************************************
    // Methods for "CSS ID"
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Invokes: {@link #AV(String)}
     * <BR />Passes: {@code String "id"}, the CSS-ID attribute-<B STYLE='color: red;'>name</B>
     */
    public String getID()
    {
        String id = AV("ID");
        return (id == null) ? null : id.trim();
    }

    /**
     * This merely sets the current CSS {@code 'ID'} Attribute <B STYLE='color: red;'>Value</B>.
     *
     * @param id This is the new CSS {@code 'ID'} attribute-<B STYLE='color: red;'>value</B> that
     * the user would like applied to {@code 'this'} instance of {@code TagNode}.
     * 
     * @param quote <EMBED CLASS='external-html' DATA-FILE-ID=TGND_QUOTE_EXPL>
     *
     * @return Returns a new instance of {@code TagNode} that has an updated {@code 'ID'} 
     * attribute-<B STYLE='color: red;'>value</B>.
     * 
     * @throws IllegalArgumentException This exception shall throw if an invalid
     * {@code String}-token has been passed to parameter {@code 'id'}.
     *
     * <BR /><BR /><B>BYPASS NOTE:</B> If the user would like to bypass this exception-check, for
     * instance because he / she is using a CSS Pre-Processor, then applying the general-purpose
     * method {@code TagNode.setAV("id", "some-new-id")} ought to suffice.  This other method will
     * not apply validity checking, beyond scanning for the usual "quotes-within-quotes" problems,
     * which is always disallowed.
     *
     * @throws ClosingTagNodeException <EMBED CLASS='external-html' DATA-FILE-ID=CTNEX>
     * 
     * @see CSSStrException#VALID_CSS_CLASS_OR_NAME_TOKEN
     * @see #setAV(String, String, SD)
     */
    public TagNode setID(String id, SD quote)
    {
        if (! CSSStrException.VALID_CSS_CLASS_OR_NAME_TOKEN_PRED.test(id))

            throw new IllegalArgumentException(
                "The id parameter provide: [" + id + "], does not conform to the standard CSS " +
                "Names.\nEither try using the generic TagNode.setAV(\"id\", yourNewId, quote); " +
                "method to bypass this check, or change the value passed to the 'id' parameter " +
                "here."
            );

        return setAV("id", id.trim(), quote);
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // Attributes that begin with "data-..."
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Invokes: {@link #AV(String)}
     * <BR />Passes: {@code "data-"} prepended to parameter {@code 'dataName'} for the
     * attribute-<B STYLE='color:red'>name</B>
     */
    public String dataAV(String dataName)
    { return GetSetAttr.AV(this, "data-" + dataName, false); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_REM_DATTR_DESC>
     * @return                          <EMBED CLASS=external-html DATA-FILE-ID=TN_REM_DATTR_RET>
     * @throws ClosingTagNodeException  <EMBED CLASS=external-html DATA-FILE-ID=TN_REM_DATTR_CTNEX>
     */
    public TagNode removeDataAttributes() 
    {
        return RemoveAttributes.removeAttributes
            (this, (String attr) -> ! StrCmpr.startsWithIgnoreCase(attr, "data-") );
    }

    /**
     * Convenience Method.
     * <BR />Invokes: {@link #getDataAV(boolean)}
     * <BR />Attribute-<B STYLE='color: red;'>names</B> will be in lower-case
     */
    public Properties getDataAV() { return getDataAV(false); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_GET_DATA_AV_DESC>
     * @param preserveKeysCase  <EMBED CLASS='external-html' DATA-FILE-ID=TN_GET_DATA_AV_PAR>
     *                          <EMBED CLASS='external-html' DATA-FILE-ID=TAGNODE_PRESERVE_C>
     * @return                  <EMBED CLASS='external-html' DATA-FILE-ID=TN_GET_DATA_AV_RET>
     */
    public Properties getDataAV(boolean preserveKeysCase) 
    { return DataAttributes.getDataAV(this, preserveKeysCase); }

    /**
     * Convenience Method.
     * <BR />Invokes: {@link #getDataAN(boolean)}
     * <BR />Attribute-<B STYLE='color: red;'>names</B> will be in lower-case
     */
    public Stream<String> getDataAN() { return getDataAN(false); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_GET_DATA_AN_DESC>
     * @param preserveKeysCase  <EMBED CLASS='external-html' DATA-FILE-ID=TN_GET_DATA_AN_PAR>
     *                          <EMBED CLASS='external-html' DATA-FILE-ID=TAGNODE_PRESERVE_C>
     * @return                  <EMBED CLASS='external-html' DATA-FILE-ID=TN_GET_DATA_AN_RET>
     *                          <EMBED CLASS='external-html' DATA-FILE-ID=STRMCNVT>
     */
    public Stream<String> getDataAN(boolean preserveKeysCase) 
    { return DataAttributes.getDataAN(this, preserveKeysCase); }


    // ********************************************************************************************
    // ********************************************************************************************
    // Java Methods
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_TOSTR_AV_DESC>
     * @return <EMBED CLASS='external-html' DATA-FILE-ID=TN_TOSTR_AV_RET>
     * @see HTMLNode#toString()
     */
    public String toStringAV()
    { return GeneralPurpose.toStringAV(this); }

    /**
     * Java's {@code interface Cloneable} requirements.  This instantiates a new {@code TagNode}
     * with identical <SPAN STYLE='color: red;'>{@code String str}</SPAN> fields, and also
     * identical <SPAN STYLE='color: red;'>{@code boolean isClosing}</SPAN> and
     * <SPAN STYLE='color: red;'>{@code String tok}</SPAN> fields.
     * 
     * @return A new {@code TagNode} whose internal fields are identical to this one.
     */
    public TagNode clone() { return new TagNode(str); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_COMPARETO_DESC>
     * @param n Any other {@code TagNode} to be compared to {@code 'this' TagNode}
     * @return An integer that fulfils Java's {@code Comparable} interface-method requirements.
     */
    public int compareTo(TagNode n)
    {
        // Utilize the standard "String.compare(String)" method with the '.tok' string field.
        // All 'tok' fields are stored as lower-case strings.
        int compare1 = this.tok.compareTo(n.tok);

        // Comparison #1 will be non-zero if the two TagNode's being compared had different
        // .tok fields
        if (compare1 != 0) return compare1;

        // If the '.tok' fields were the same, use the 'isClosing' field for comparison instead.
        // This comparison will only be used if they are different.
        if (this.isClosing != n.isClosing) return (this.isClosing == false) ? -1 : 1;
    
        // Finally try using the entire element '.str' String field, instead.  
        return this.str.length() - n.str.length();
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // toUpperCase 
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * <EMBED CLASS=defs DATA-CASE=Upper DATA-CAPITAL="">
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_1_DESC>
     * @param justTag_Or_TagAndAttributeNames 
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_1_PARAM>
     * @return <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_1_RET>
     */
    public TagNode toUpperCase(boolean justTag_Or_TagAndAttributeNames)
    {
        return CaseChange.toCaseInternal
            (this, justTag_Or_TagAndAttributeNames, String::toUpperCase);
    }

    /**
     * Convenience Method.
     * <BR />Passes: {@code StrCmpr.equalsXOR_CI(attrName, attributeNames)}
     * @see #toUpperCase(boolean, Predicate)
     * @see StrCmpr#equalsXOR_CI(String, String...)
     */
    public TagNode toUpperCase(boolean tag, String... attributeNames)
    {
        return CaseChange.toCaseInternal(
            this, tag,
            (String attrName) -> StrCmpr.equalsXOR_CI(attrName, attributeNames),
            String::toUpperCase
        );
    }

    /**
     * <EMBED CLASS=defs DATA-CASE=Upper DATA-CAPITAL="">
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_2_DESC>
     * @param tag           Indicates whether or not the Tag-Name should be capitalized
     * @param attrNameTest  <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_2_PARAM>
     * @return              <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_2_RET>
     */
    public TagNode toUpperCase(boolean tag, Predicate<String> attrNameTest)
    { return CaseChange.toCaseInternal(this, tag, attrNameTest, String::toUpperCase); }


    // ********************************************************************************************
    // ********************************************************************************************
    // toLowerCase 
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * <EMBED CLASS=defs DATA-CASE=Lower DATA-CAPITAL="de-">
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_1_DESC>
     * @param justTag_Or_TagAndAttributeNames 
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_1_PARAM>
     * @return <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_1_RET>
     */
    public TagNode toLowerCase(boolean justTag_Or_TagAndAttributeNames)
    {
        return CaseChange.toCaseInternal
            (this, justTag_Or_TagAndAttributeNames, String::toLowerCase);
    }

    /**
     * Convenience Method.
     * <BR />Passes: {@code StrCmpr.equalsXOR_CI(attrName, attributeNames)}
     * @see #toLowerCase(boolean, Predicate)
     * @see StrCmpr#equalsXOR_CI(String, String...)
     */
    public TagNode toLowerCase(boolean tag, String... attributeNames)
    {
        return CaseChange.toCaseInternal(
            this, tag,
            (String attrName) -> StrCmpr.equalsXOR_CI(attrName, attributeNames),
            String::toLowerCase
        );
    }

    /**
     * <EMBED CLASS=defs DATA-CASE=Lower DATA-CAPITAL="de-">
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_2_DESC>
     * @param tag           Indicates whether or not the Tag-Name should be decapitalized
     * @param attrNameTest  <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_2_PARAM>
     * @return              <EMBED CLASS='external-html' DATA-FILE-ID=TN_TO_UPLOW_2_RET>
     */
    public TagNode toLowerCase(boolean tag, Predicate<String> attrNameTest)
    { return CaseChange.toCaseInternal(this, tag, attrNameTest, String::toLowerCase); }


    // ********************************************************************************************
    // ********************************************************************************************
    // Attribute-Value Quotation-Marks - REMOVE
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Removes Quotation-Marks from <B STYLE='color: red;'>Value</B> whose Inner-Tag 
     * <B STYLE='color: red;'>Name</B> matches {@code 'attributeName'}
     * @see removeAVQuotes(Predicate)
     */
    public TagNode removeAVQuotes(String attributeName)
    {
        return QuotationMarks.removeAVQuotes
            (this, (String attr) -> attr.equalsIgnoreCase(attributeName));
    }

    /**
     * Convenience Method.
     * <BR />Removes Quotation-Marks from all Inner-Tag <B STYLE='color: red;'>Values</B>
     * @see removeAVQuotes(Predicate)
     */
    public TagNode removeAllAVQuotes()
    { return QuotationMarks.removeAVQuotes(this, (String attr) -> true); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_REM_QUOTES_DESC>
     * @param attrNameTest      <EMBED CLASS='external-html' DATA-FILE-ID=TN_REM_QUOTES_PARAM>
     * @return                  <EMBED CLASS='external-html' DATA-FILE-ID=TN_REM_QUOTES_RET>
     * @throws QuotesException  If the resulting <CODE>TagNode</CODE> contains Quotation-Errors
     */
    public TagNode removeAVQuotes(Predicate<String> attrNameTest)
    { return QuotationMarks.removeAVQuotes(this, attrNameTest); }


    // ********************************************************************************************
    // ********************************************************************************************
    // Attribute-Value Quotation-Marks - SET
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Convenience Method.
     * <BR />Set Quotation-Marks from <B STYLE='color: red;'>Value</B> whose Inner-Tag 
     * <B STYLE='color: red;'>Name</B> matches {@code 'attributeName'}
     * @see setAVQuotes(Predicate, SD)
     */
    public TagNode setAVQuotes(String attributeName, SD quote)
    {
        return QuotationMarks.setAVQuotes
            (this, (String attr) -> attr.equalsIgnoreCase(attributeName), quote);
    }

    /**
     * Convenience Method.
     * <BR />Set the Quotation-Marks for all Inner-Tag <B STYLE='color: red;'>Values</B>
     * @see setAVQuotes(Predicate, SD)
     */
    public TagNode setAllAVQuotes(SD quote)
    { return QuotationMarks.setAVQuotes(this, (String attr) -> true, quote); }

    /**
     * <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_QUOTES_DESC>
     * @param attrNameTest          <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_QUOTES_PARAM>
     * @param quote                 The new Quotation-Mark to apply
     * @return                      <EMBED CLASS='external-html' DATA-FILE-ID=TN_SET_QUOTES_RET>
     * @throws QuotesException      If the resulting <CODE>TagNode</CODE> contains Quotation-Errors
     * @throws NullPointerException If either parameter is passed null.
     */
    public TagNode setAVQuotes(Predicate<String> attrNameTest, SD quote)
    { return QuotationMarks.setAVQuotes(this, attrNameTest, quote); }


    // ********************************************************************************************
    // ********************************************************************************************
    // Attribute-Value Quotation-Marks - GET
    // ********************************************************************************************
    // ********************************************************************************************


    // TO-DO: First, I am going to "Modernize" the get/set AV methods
    // Then this will work
}