001package Torello.HTML.NodeSearch;
002
003import java.util.Vector;
004import java.util.regex.Pattern;
005import java.util.function.Predicate;
006
007import Torello.HTML.*;
008import Torello.HTML.NodeSearch.SearchLoops.CommentNodes.CmtNRemove;
009import Torello.Java.LV;
010
011/**
012 * Finds and removes HTML Comments from an HTML-{@code Vector} that match a user-provided
013 * search-criteria specified with a {@code String-Predicate}, Regular-Expression or
014 * {@link TextComparitor}.  These methods in this class return a count (as an integer) stating
015 * how many nodes where removed.
016 * 
017 * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=CommentNodeRemove> 
018 */
019@Torello.JavaDoc.JDHeaderBackgroundImg
020@Torello.JavaDoc.StaticFunctional
021public class CommentNodeRemove
022{
023    private CommentNodeRemove() { }
024
025    // ********************************************************************************************
026    // FIRST, LAST
027    // ********************************************************************************************
028
029    // **** first: no sPos, ePos 
030    public static int first (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
031    { return CmtNRemove.nth (html, 1, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
032    public static int first (Vector<? extends HTMLNode> html, Pattern p)
033    { return CmtNRemove.nth (html, 1, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
034    public static int first (Vector<? extends HTMLNode> html, Predicate<String> p)
035    { return CmtNRemove.nth (html, 1, new LV(html, 0, -1), p); }
036
037    // **** first: CRITERIA INCLUDES sPos, ePos
038    public static int first (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
039    { return CmtNRemove.nth (html, 1, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
040    public static int first (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
041    { return CmtNRemove.nth (html, 1, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
042    public static int first (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
043    { return CmtNRemove.nth (html, 1, new LV(html, sPos, ePos), p); }
044
045    // **** last: no sPos, ePos
046    public static int last (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
047    { return CmtNRemove.nthFromEnd (html, 1, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
048    public static int last (Vector<? extends HTMLNode> html, Pattern p)
049    { return CmtNRemove.nthFromEnd (html, 1, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
050    public static int last (Vector<? extends HTMLNode> html, Predicate<String> p)
051    { return CmtNRemove.nthFromEnd (html, 1, new LV(html, 0, -1), p); }
052
053    // **** last: CRITERIA INCLUDES sPos, ePos
054    public static int last (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
055    { return CmtNRemove.nthFromEnd (html, 1, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
056    public static int last (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
057    { return CmtNRemove.nthFromEnd (html, 1, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
058    public static int last (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
059    { return CmtNRemove.nthFromEnd (html, 1, new LV(html, sPos, ePos), p); }
060
061    // ********************************************************************************************
062    // NEW ADDITIONS: nth and nthFromEnd
063    // ********************************************************************************************
064
065    // **** first: no sPos, ePos 
066    public static int nth (Vector<? extends HTMLNode> html, int nth, TextComparitor tc, String... compareStr)
067    { return CmtNRemove.nth (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
068    public static int nth (Vector<? extends HTMLNode> html, int nth, Pattern p)
069    { return CmtNRemove.nth (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
070    public static int nth (Vector<? extends HTMLNode> html, int nth, Predicate<String> p)
071    { return CmtNRemove.nth (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), p); }
072
073    // **** first: CRITERIA INCLUDES sPos, ePos
074    public static int nth (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, TextComparitor tc, String... compareStr)
075    { return CmtNRemove.nth (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
076    public static int nth (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Pattern p)
077    { return CmtNRemove.nth (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
078    public static int nth (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Predicate<String> p)
079    { return CmtNRemove.nth (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), p); }
080
081    // **** last: no sPos, ePos
082    public static int nthFromEnd (Vector<? extends HTMLNode> html, int nth, TextComparitor tc, String... compareStr)
083    { return CmtNRemove.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
084    public static int nthFromEnd (Vector<? extends HTMLNode> html, int nth, Pattern p)
085    { return CmtNRemove.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
086    public static int nthFromEnd (Vector<? extends HTMLNode> html, int nth, Predicate<String> p)
087    { return CmtNRemove.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), p); }
088
089    // **** last: CRITERIA INCLUDES sPos, ePos
090    public static int nthFromEnd (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, TextComparitor tc, String... compareStr)
091    { return CmtNRemove.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
092    public static int nthFromEnd (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Pattern p)
093    { return CmtNRemove.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
094    public static int nthFromEnd (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Predicate<String> p)
095    { return CmtNRemove.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), p); }
096
097    // ********************************************************************************************
098    // ALL Methods
099    // ********************************************************************************************
100
101    // **** all: no sPos, ePos
102    public static int all (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
103    { return CmtNRemove.all (html, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
104    public static int all (Vector<? extends HTMLNode> html, Pattern p)
105    { return CmtNRemove.all (html, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
106    public static int all (Vector<? extends HTMLNode> html, Predicate<String> p)
107    { return CmtNRemove.all (html, new LV(html, 0, -1), p); }
108
109    // **** all: CRITERIA INCLUDES sPos, ePos
110    public static int all (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
111    { return CmtNRemove.all (html, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
112    public static int all (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
113    { return CmtNRemove.all (html, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
114    public static int all (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
115    { return CmtNRemove.all (html, new LV(html, sPos, ePos), p); }
116
117
118    // **** allExcept: no sPos, ePos
119    public static int allExcept (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
120    { return CmtNRemove.allExcept (html, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
121    public static int allExcept (Vector<? extends HTMLNode> html, Pattern p)
122    { return CmtNRemove.allExcept (html, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
123    public static int allExcept (Vector<? extends HTMLNode> html, Predicate<String> p)
124    { return CmtNRemove.allExcept (html, new LV(html, 0, -1), p); }
125
126    // **** allExcept: CRITERIA INCLUDES sPos, ePos
127    public static int allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
128    { return CmtNRemove.allExcept (html, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
129    public static int allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
130    { return CmtNRemove.allExcept (html, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
131    public static int allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
132    { return CmtNRemove.allExcept (html, new LV(html, sPos, ePos), p); }
133}