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 | package Torello.HTML;
import Torello.Java.LV;
import java.util.Vector;
import java.util.stream.IntStream;
class Remove
{
static int[] remove(
final Vector<? super TagNode> html,
final int sPos,
final int ePos,
final String... innerTags
)
{
InnerTagKeyException.check(innerTags);
// Use Java Stream to keep a list of Vector-Locations that were updated / modified.
IntStream.Builder b = IntStream.builder();
// Loop Counter & Temporary Variables
LV l = new LV(sPos, ePos, html);
TagNode tn;
for (int i=l.start; i < l.end; i++)
// Only instances of Opening-TagNodes, possibly with attributes
if ((tn = ((HTMLNode) html.elementAt(i)).openTagPWA()) != null)
// If this TagNode has the attributes that have been requested for removal, then...
if (tn.hasOR(false, innerTags))
{
// Build a new TagNode, and then replace the old one with the newly built one
// on the page or sub-page, and at the same location.
tn = tn.removeAttributes(innerTags);
html.setElementAt(tn, i);
// Java's IntStream-Builder is just a way to "build" a short list of integer's.
// At the end of this method, the list will be built and returned to the user.
// It shall contain all Vector locations where a "TagNode swap" (replaced
// TagNode, with attributes filtered) has occurred.
b.accept(i);
}
// Build the IntStream, Convert the IntStream -> int[], Return it.
return b.build().toArray();
}
static int[] remove(
final Vector<? super TagNode> html,
final int[] posArr,
final String... innerTags
)
{
InnerTagKeyException.check(innerTags);
// Use Java Stream to keep a list of Vector-Locations that were updated / modified.
IntStream.Builder b = IntStream.builder();
// Compute the "minimum length" of a TagNode.str field
int MIN = 1000;
// Minimum-Length of TagNode.str would have to be 3 + smallest inner-tag passed
for (String attrib : innerTags) if (attrib.length() < MIN) MIN = attrib.length();
MIN += 3;
for (int i : posArr)
{
HTMLNode n = (HTMLNode) html.elementAt(i);
if (! n.isTagNode()) throw new TagNodeExpectedException(i);
TagNode tn = (TagNode) n;
if (tn.isClosing) throw new OpeningTagNodeExpectedException(i);
// If element-length <= MIN, none of the attributes could possibly be present.
if (tn.str.length() < (tn.tok.length() + MIN)) continue;
// If this TagNode has the attributes that have been requested for removal, then...
if (tn.hasOR(false, innerTags))
{
// Build a new TagNode, and then replace the old one with the newly built one
// on the page or sub-page, and at the same location.
tn = tn.removeAttributes(innerTags);
html.setElementAt(tn, i);
// Java's IntStream-Builder is just a way to "build" a short list of integer's.
// At the end of this method, the list will be built and returned to the user.
// It shall contain all Vector locations where a "TagNode swap" (replaced
// TagNode, with attributes filtered) has occurred.
b.accept(i);
}
}
// Build the IntStream, Convert the IntStream -> int[], Return it.
return b.build().toArray();
}
}
|