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.TextNodes.TxNPoll;
009import Torello.Java.LV;
010
011/**
012 * <B><I>Both</I></B> extracts (removes) <B><I>and</I></B> returns, from an HTML-{@code Vector},
013 * instances of {@link TextNode} that match a user provided {@code String-Predicate}, Regular
014 * Expression or {@link TextComparitor}.
015 * 
016 * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=TextNodePoll>
017 */
018@Torello.JavaDoc.JDHeaderBackgroundImg
019@Torello.JavaDoc.StaticFunctional
020public class TextNodePoll
021{
022    private TextNodePoll() { }
023
024    // ********************************************************************************************
025    // FIRST, LAST
026    // ********************************************************************************************
027
028    // **** first: no sPos, ePos 
029    public static TextNode first (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
030    { return TxNPoll.nth (html, 1, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
031    public static TextNode first (Vector<? extends HTMLNode> html, Pattern p)
032    { return TxNPoll.nth (html, 1, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
033    public static TextNode first (Vector<? extends HTMLNode> html, Predicate<String> p)
034    { return TxNPoll.nth (html, 1, new LV(html, 0, -1), p); }
035
036    // **** first: CRITERIA INCLUDES sPos, ePos
037    public static TextNode first (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
038    { return TxNPoll.nth (html, 1, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
039    public static TextNode first (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
040    { return TxNPoll.nth (html, 1, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
041    public static TextNode first (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
042    { return TxNPoll.nth (html, 1, new LV(html, sPos, ePos), p); }
043
044    // **** last: no sPos, ePos
045    public static TextNode last (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
046    { return TxNPoll.nthFromEnd (html, 1, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
047    public static TextNode last (Vector<? extends HTMLNode> html, Pattern p)
048    { return TxNPoll.nthFromEnd (html, 1, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
049    public static TextNode last (Vector<? extends HTMLNode> html, Predicate<String> p)
050    { return TxNPoll.nthFromEnd (html, 1, new LV(html, 0, -1), p); }
051
052    // **** last: CRITERIA INCLUDES sPos, ePos
053    public static TextNode last (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
054    { return TxNPoll.nthFromEnd (html, 1, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
055    public static TextNode last (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
056    { return TxNPoll.nthFromEnd (html, 1, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
057    public static TextNode last (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
058    { return TxNPoll.nthFromEnd (html, 1, new LV(html, sPos, ePos), p); }
059
060    // ********************************************************************************************
061    // NEW ADDITIONS: nth and nthFromEnd
062    // ********************************************************************************************
063
064    // **** nth: no sPos, ePos 
065    public static TextNode nth (Vector<? extends HTMLNode> html, int nth, TextComparitor tc, String... compareStr)
066    { return TxNPoll.nth (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
067    public static TextNode nth (Vector<? extends HTMLNode> html, int nth, Pattern p)
068    { return TxNPoll.nth (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
069    public static TextNode nth (Vector<? extends HTMLNode> html, int nth, Predicate<String> p)
070    { return TxNPoll.nth (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), p); }
071
072    // **** nth: CRITERIA INCLUDES sPos, ePos
073    public static TextNode nth (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, TextComparitor tc, String... compareStr)
074    { return TxNPoll.nth (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
075    public static TextNode nth (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Pattern p)
076    { return TxNPoll.nth (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
077    public static TextNode nth (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Predicate<String> p)
078    { return TxNPoll.nth (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), p); }
079
080    // **** nthFromEnd: no sPos, ePos
081    public static TextNode nthFromEnd (Vector<? extends HTMLNode> html, int nth, TextComparitor tc, String... compareStr)
082    { return TxNPoll.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
083    public static TextNode nthFromEnd (Vector<? extends HTMLNode> html, int nth, Pattern p)
084    { return TxNPoll.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
085    public static TextNode nthFromEnd (Vector<? extends HTMLNode> html, int nth, Predicate<String> p)
086    { return TxNPoll.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), p); }
087
088    // **** nthFromEnd: CRITERIA INCLUDES sPos, ePos
089    public static TextNode nthFromEnd (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, TextComparitor tc, String... compareStr)
090    { return TxNPoll.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
091    public static TextNode nthFromEnd (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Pattern p)
092    { return TxNPoll.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
093    public static TextNode nthFromEnd (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Predicate<String> p)
094    { return TxNPoll.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), p); }
095
096    // ********************************************************************************************
097    // ALL methods
098    // ********************************************************************************************
099
100    // **** all: no sPos, ePos
101    public static Vector<TextNode> all (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
102    { return TxNPoll.all (html, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
103    public static Vector<TextNode> all (Vector<? extends HTMLNode> html, Pattern p)
104    { return TxNPoll.all (html, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
105    public static Vector<TextNode> all (Vector<? extends HTMLNode> html, Predicate<String> p)
106    { return TxNPoll.all (html, new LV(html, 0, -1), p); }
107
108    // **** all: CRITERIA INCLUDES sPos, ePos
109    public static Vector<TextNode> all (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
110    { return TxNPoll.all (html, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
111    public static Vector<TextNode> all (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
112    { return TxNPoll.all (html, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
113    public static Vector<TextNode> all (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
114    { return TxNPoll.all (html, new LV(html, sPos, ePos), p); }
115
116
117    // **** allExcept: no sPos, ePos
118    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
119    { return TxNPoll.allExcept (html, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
120    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, Pattern p)
121    { return TxNPoll.allExcept (html, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
122    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, Predicate<String> p)
123    { return TxNPoll.allExcept (html, new LV(html, 0, -1), p); }
124
125    // **** allExcept: CRITERIA INCLUDES sPos, ePos
126    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
127    { return TxNPoll.allExcept (html, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
128    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
129    { return TxNPoll.allExcept (html, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
130    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
131    { return TxNPoll.allExcept (html, new LV(html, sPos, ePos), p); }
132}