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 | package Torello.HTML;
import Torello.HTML.TagNode;
import Torello.HTML.HTMLTags;
import Torello.HTML.NodeSearch.ARGCHECK;
import java.util.*;
import java.util.function.Predicate;
// HELPER FOR CLASS "SURROUNDING"
final class HTMLTagCounter
{
// This will store the "HTML Tag Count" This is a positive / negative count which is decremented
// by the surrounding "search for-loop" in class "Surrounding." It keeps a list of html-tags that
// are requested an encountered, and decrements the counter as the for-loop scans (backwards, towards
// the beginning of the vector) and find "closing-tags."
private final TreeMap<String, Integer> countTable = new TreeMap<String, Integer>();
private final boolean firstOrAll;
static final boolean EXCEPT = true;
static final boolean NORMAL = false;
static final boolean FIRST = false;
static final boolean ALL = true;
HTMLTagCounter(String[] htmlTags, boolean exceptOrNormal, boolean firstOrAll)
{
this.firstOrAll = firstOrAll;
if (htmlTags.length > 0) htmlTags = ARGCHECK.htmlTags(htmlTags);
if ((htmlTags.length > 0) && (exceptOrNormal == NORMAL))
for (String htmlTag : htmlTags)
countTable.put(htmlTag, 0);
else
for ( Iterator<String> iter = HTMLTags.iterator(); iter.hasNext(); )
countTable.put(iter.next(), 0);
if (exceptOrNormal == EXCEPT)
for (String htmlTag : htmlTags) countTable.remove(htmlTag);
}
boolean allBanned() { return countTable.size() == 0; }
void reportFailed(String tok) { countTable.remove(tok); }
boolean check(TagNode tn)
{
Integer curValI = countTable.get(tn.tok);
// System.out.print
// ("curValI = [" + ((curValI == null) ? "null" : curValI.toString()) + "]");
if (curValI == null) return false;
int curVal = curValI.intValue() + (tn.isClosing ? -1 : 1);
// System.out.print(", curVal = [" + curVal + "]");
boolean ret = (curVal >= 1);
// System.out.print(", ret = [" + ret + "]");
if (ret && (firstOrAll == FIRST)) countTable.remove(tn.tok);
else countTable.put(tn.tok, Integer.valueOf(curVal));
return ret;
}
}
|