001package Torello.HTML.NodeSearch;
002
003import java.util.*;
004import java.util.regex.Pattern;
005import java.util.function.Predicate;
006
007import Torello.HTML.*;
008import Torello.HTML.NodeSearch.searchLoops.TxNGet;
009import Torello.Java.LV;
010
011/**
012 * Retrieves HTML-Document Text from Vectorized-HTML, as instances of {@link TextNode}, using a
013 * search-criteria that may be specified with {@code String-Predicate's}, Regular-Expressions,
014 * or a {@link TextComparitor}.
015 * 
016 * <BR /><BR /><EMBED CLASS="external-html" DATA-FILE-ID=TextNodeGet>
017 */
018@Torello.HTML.Tools.JavaDoc.JDHeaderBackgroundImg
019@Torello.HTML.Tools.JavaDoc.StaticFunctional
020public class TextNodeGet
021{
022    private TextNodeGet() { }
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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.nthFromEnd (html, 1, new LV(html, sPos, ePos), p); }
059
060    // ********************************************************************************************
061    // NEW ADDITIONS: nth and nthFromEnd
062    // ********************************************************************************************
063
064    // **** First: no sPos, ePos 
065    public static TextNode nth (Vector<? extends HTMLNode> html, int nth, TextComparitor tc, String... compareStr)
066    { return TxNGet.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 TxNGet.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 TxNGet.nth (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), p); }
071
072    // **** First: 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 TxNGet.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 TxNGet.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 TxNGet.nth (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), p); }
079
080    // **** Last: no sPos, ePos
081    public static TextNode nthFromEnd (Vector<? extends HTMLNode> html, int nth, TextComparitor tc, String... compareStr)
082    { return TxNGet.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 TxNGet.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 TxNGet.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), p); }
087
088    // **** Last: 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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.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 TxNGet.all (html, new LV(html, 0, -1), p); }
107
108
109    // **** All: CRITERIA INCLUDES sPos, ePos
110    public static Vector<TextNode> all (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
111    { return TxNGet.all (html, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
112    public static Vector<TextNode> all (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
113    { return TxNGet.all (html, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
114    public static Vector<TextNode> all (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
115    { return TxNGet.all (html, new LV(html, sPos, ePos), p); }
116
117
118    // **** AllExcept: no sPos, ePos
119    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
120    { return TxNGet.allExcept (html, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
121    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, Pattern p)
122    { return TxNGet.allExcept (html, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
123    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, Predicate<String> p)
124    { return TxNGet.allExcept (html, new LV(html, 0, -1), p); }
125
126
127    // **** AllExcept: CRITERIA INCLUDES sPos, ePos
128    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
129    { return TxNGet.allExcept (html, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
130    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
131    { return TxNGet.allExcept (html, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
132    public static Vector<TextNode> allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
133    { return TxNGet.allExcept (html, new LV(html, sPos, ePos), p); }
134}