Skip to content

Commit 83b182a

Browse files
committed
1
1
1 parent a8b297e commit 83b182a

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.xenoamess</groupId>
77
<artifactId>x8l</artifactId>
8-
<version>0.27</version>
8+
<version>0.28</version>
99
</project>

src/main/java/com/xenoamess/x8l/ContentNode.java

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.Writer;
77
import java.util.ArrayList;
88
import java.util.HashMap;
9+
import java.util.List;
910
import java.util.Map;
1011

1112
public class ContentNode extends TreeNode {
@@ -24,8 +25,10 @@ public void addAttribute(String key, String value) {
2425
if (value == null) {
2526
value = "";
2627
}
28+
if (!this.attributes.containsKey(key)) {
29+
attributesKeyList.add(key);
30+
}
2731
attributes.put(key, value);
28-
attributesKeyList.add(key);
2932
}
3033

3134

@@ -114,4 +117,58 @@ public void output(Writer writer) {
114117
e.printStackTrace();
115118
}
116119
}
120+
121+
public List<TextNode> getTextNodesFromChildren() {
122+
return this.getTextNodesFromChildren(0);
123+
}
124+
125+
public List<TextNode> getTextNodesFromChildren(int maxSize) {
126+
List<TextNode> res = new ArrayList<TextNode>();
127+
for (TreeNode au : this.children) {
128+
if (au instanceof TextNode) {
129+
res.add((TextNode) au);
130+
if (res.size() == maxSize) {
131+
return res;
132+
}
133+
}
134+
}
135+
return res;
136+
}
137+
138+
public List<ContentNode> getContentNodesFromChildren() {
139+
return this.getContentNodesFromChildren(0);
140+
}
141+
142+
public List<ContentNode> getContentNodesFromChildren(int maxSize) {
143+
List<ContentNode> res = new ArrayList<ContentNode>();
144+
for (TreeNode au : this.children) {
145+
if (au instanceof ContentNode) {
146+
res.add((ContentNode) au);
147+
if (res.size() == maxSize) {
148+
return res;
149+
}
150+
}
151+
}
152+
return res;
153+
}
154+
155+
156+
public List<CommentNode> getCommentNodesFromChildren() {
157+
return this.getCommentNodesFromChildren(0);
158+
}
159+
160+
public List<CommentNode> getCommentNodesFromChildren(int maxSize) {
161+
List<CommentNode> res = new ArrayList<CommentNode>();
162+
for (TreeNode au : this.children) {
163+
if (au instanceof CommentNode) {
164+
res.add((CommentNode) au);
165+
if (res.size() == maxSize) {
166+
return res;
167+
}
168+
}
169+
}
170+
return res;
171+
}
172+
173+
117174
}

0 commit comments

Comments
 (0)