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
package Torello.HTML.NodeSearch;

import java.util.*;
import java.util.regex.Pattern;
import java.util.function.Predicate;

import Torello.HTML.*;
import Torello.Java.LV;

/**
 * {@code Static} methods for building an {@link HNLIInclusive} (which also extends the basic
 * {@code Iterator}) for retrieving sub HTML-Vector's using match-critera which specify
 * HTML Tag Attribute <B STYLE='color:red'>name</B> and <B STYLE='color:red'>value</B>
 * requirements.
 * 
 * <BR /><BR /><EMBED CLASS="external-html" DATA-FILE-ID=InnerTagInclusiveIterator>
 */
@Torello.HTML.Tools.JavaDoc.JDHeaderBackgroundImg
@Torello.HTML.Tools.JavaDoc.StaticFunctional
public class InnerTagInclusiveIterator
{
    private InnerTagInclusiveIterator() { }

    // **** CRITERIA: htmlTag
    public static HNLIInclusive get(Vector<? extends HTMLNode> html, String htmlTag, String innerTag)
    { return GET(html, ARGCHECK.htmlTag(htmlTag), ARGCHECK.innerTag(innerTag), ARGCHECK.TRUE); }

    public static HNLIInclusive get(Vector<? extends HTMLNode> html, String htmlTag, String innerTag, TextComparitor tc, String... compareStr)
    { return GET(html, ARGCHECK.htmlTag(htmlTag), ARGCHECK.innerTag(innerTag), ARGCHECK.TC(tc, compareStr)); }

    public static HNLIInclusive get(Vector<? extends HTMLNode> html, String htmlTag, String innerTag, Pattern p)
    { return GET(html, ARGCHECK.htmlTag(htmlTag), ARGCHECK.innerTag(innerTag), ARGCHECK.REGEX(p)); }

    public static HNLIInclusive get(Vector<? extends HTMLNode> html, String htmlTag, String innerTag, Predicate<String> attributeValuePred)
    { return GET(html, ARGCHECK.htmlTag(htmlTag), ARGCHECK.innerTag(innerTag), attributeValuePred); }

    public static HNLIInclusive get(Vector<? extends HTMLNode> html, Predicate<TagNode> p, String... htmlTags)
    { return GET(html, p, ARGCHECK.htmlTags(htmlTags)); }

    // **** CRITERIA: htmlTag null
    public static HNLIInclusive get(Vector<? extends HTMLNode> html, String innerTag)
    { return GET(html, null, ARGCHECK.innerTag(innerTag), ARGCHECK.TRUE); }

    public static HNLIInclusive get(Vector<? extends HTMLNode> html, String innerTag, TextComparitor tc, String... compareStr)
    { return GET(html, null, ARGCHECK.innerTag(innerTag), ARGCHECK.TC(tc, compareStr)); }

    public static HNLIInclusive get(Vector<? extends HTMLNode> html, String innerTag, Pattern p)
    { return GET(html, null, ARGCHECK.innerTag(innerTag), ARGCHECK.REGEX(p)); }

    public static HNLIInclusive get(Vector<? extends HTMLNode> html, String innerTag, Predicate<String> attributeValuePred)
    { return GET(html, null, ARGCHECK.innerTag(innerTag), attributeValuePred); }

    public static HNLIInclusive get(Vector<? extends HTMLNode> html, Predicate<TagNode> p)
    { return GET(html, p); }

    // **************************************************************************************
    // private builder methods
    // **************************************************************************************

    private static HNLIInclusive GET
        (Vector<? extends HTMLNode> html, String htmlTag, String innerTag, Predicate<String> compare)
    {
        InclusiveException.check(htmlTag);

        if (htmlTag == null)
            return new HNLIInclusive(
                html, (TagNode tn) ->
                {
                    String innerTagValue = tn.AVOPT(innerTag);
                    return (innerTagValue != null) && compare.test(innerTagValue);
                }
            );
        else
            return new HNLIInclusive(
                html, (TagNode tn) ->
                {
                    if (! htmlTag.equals(tn.tok)) return false;
                    String innerTagValue = tn.AVOPT(innerTag);
                    return (innerTagValue != null) && compare.test(innerTagValue);
                }
            );
    }

    private static HNLIInclusive GET
        (Vector<? extends HTMLNode> html, Predicate<TagNode> p, String... htmlTags)
    {
        InclusiveException.check(htmlTags);

        Predicate<TagNode> p2 = (htmlTags.length == 0)
            ? p
            : (TagNode tn) -> tn.isTag(TC.OpeningTags, htmlTags) && p.test(tn);

        return new HNLIInclusive(html, p2);
    }

}