66import java .io .Writer ;
77import java .util .ArrayList ;
88import java .util .HashMap ;
9+ import java .util .List ;
910import java .util .Map ;
1011
1112public 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