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.TextNodes.TxNPeek;
009import Torello.Java.LV;
010
011/**
012 * "Peeks" into Vectorized-HTML for text matching a search-criteria and returns the
013 * {@code Vector}-index where matches are found, <I><B>and</B></I> the {@link TextNode} at
014 * that {@code Vector}-location, as an instance of {@link TextNodeIndex}.
015 * 
016 * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=TextNodePeek>
017 */
018@Torello.JavaDoc.JDHeaderBackgroundImg
019@Torello.JavaDoc.StaticFunctional
020public class TextNodePeek
021{
022    private TextNodePeek() { }
023
024    // ********************************************************************************************
025    // FIRST, LAST
026    // ********************************************************************************************
027
028    // **** First: no sPos, ePos 
029    public static TextNodeIndex first (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
030    { return TxNPeek.nth (html, 1, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
031    public static TextNodeIndex first (Vector<? extends HTMLNode> html, Pattern p)
032    { return TxNPeek.nth (html, 1, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
033    public static TextNodeIndex first (Vector<? extends HTMLNode> html, Predicate<String> p)
034    { return TxNPeek.nth (html, 1, new LV(html, 0, -1), p); }
035
036    // **** First: CRITERIA INCLUDES sPos, ePos
037    public static TextNodeIndex first (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
038    { return TxNPeek.nth (html, 1, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
039    public static TextNodeIndex first (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
040    { return TxNPeek.nth (html, 1, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
041    public static TextNodeIndex first (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
042    { return TxNPeek.nth (html, 1, new LV(html, sPos, ePos), p); }
043
044    // **** Last: no sPos, ePos
045    public static TextNodeIndex last (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
046    { return TxNPeek.nthFromEnd (html, 1, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
047    public static TextNodeIndex last (Vector<? extends HTMLNode> html, Pattern p)
048    { return TxNPeek.nthFromEnd (html, 1, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
049    public static TextNodeIndex last (Vector<? extends HTMLNode> html, Predicate<String> p)
050    { return TxNPeek.nthFromEnd (html, 1, new LV(html, 0, -1), p); }
051
052    // **** Last: CRITERIA INCLUDES sPos, ePos
053    public static TextNodeIndex last (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
054    { return TxNPeek.nthFromEnd (html, 1, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
055    public static TextNodeIndex last (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
056    { return TxNPeek.nthFromEnd (html, 1, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
057    public static TextNodeIndex last (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
058    { return TxNPeek.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 TextNodeIndex nth (Vector<? extends HTMLNode> html, int nth, TextComparitor tc, String... compareStr)
066    { return TxNPeek.nth (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
067    public static TextNodeIndex nth (Vector<? extends HTMLNode> html, int nth, Pattern p)
068    { return TxNPeek.nth (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
069    public static TextNodeIndex nth (Vector<? extends HTMLNode> html, int nth, Predicate<String> p)
070    { return TxNPeek.nth (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), p); }
071
072    // **** First: CRITERIA INCLUDES sPos, ePos
073    public static TextNodeIndex nth (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, TextComparitor tc, String... compareStr)
074    { return TxNPeek.nth (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
075    public static TextNodeIndex nth (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Pattern p)
076    { return TxNPeek.nth (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
077    public static TextNodeIndex nth (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Predicate<String> p)
078    { return TxNPeek.nth (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), p); }
079
080    // **** Last: no sPos, ePos
081    public static TextNodeIndex nthFromEnd (Vector<? extends HTMLNode> html, int nth, TextComparitor tc, String... compareStr)
082    { return TxNPeek.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
083    public static TextNodeIndex nthFromEnd (Vector<? extends HTMLNode> html, int nth, Pattern p)
084    { return TxNPeek.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
085    public static TextNodeIndex nthFromEnd (Vector<? extends HTMLNode> html, int nth, Predicate<String> p)
086    { return TxNPeek.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, 0, -1), p); }
087
088    // **** Last: CRITERIA INCLUDES sPos, ePos
089    public static TextNodeIndex nthFromEnd (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, TextComparitor tc, String... compareStr)
090    { return TxNPeek.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
091    public static TextNodeIndex nthFromEnd (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Pattern p)
092    { return TxNPeek.nthFromEnd (html, ARGCHECK.n(nth, html), new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
093    public static TextNodeIndex nthFromEnd (Vector<? extends HTMLNode> html, int nth, int sPos, int ePos, Predicate<String> p)
094    { return TxNPeek.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<TextNodeIndex> all (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
102    { return TxNPeek.all (html, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
103    public static Vector<TextNodeIndex> all (Vector<? extends HTMLNode> html, Pattern p)
104    { return TxNPeek.all (html, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
105    public static Vector<TextNodeIndex> all (Vector<? extends HTMLNode> html, Predicate<String> p)
106    { return TxNPeek.all (html, new LV(html, 0, -1), p); }
107
108
109    // **** All: CRITERIA INCLUDES sPos, ePos
110    public static Vector<TextNodeIndex> all (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
111    { return TxNPeek.all (html, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
112    public static Vector<TextNodeIndex> all (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
113    { return TxNPeek.all (html, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
114    public static Vector<TextNodeIndex> all (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
115    { return TxNPeek.all (html, new LV(html, sPos, ePos), p); }
116
117
118    // **** AllExcept: no sPos, ePos
119    public static Vector<TextNodeIndex> allExcept (Vector<? extends HTMLNode> html, TextComparitor tc, String... compareStr)
120    { return TxNPeek.allExcept (html, new LV(html, 0, -1), ARGCHECK.TC(tc, compareStr)); }
121    public static Vector<TextNodeIndex> allExcept (Vector<? extends HTMLNode> html, Pattern p)
122    { return TxNPeek.allExcept (html, new LV(html, 0, -1), ARGCHECK.REGEX(p)); }
123    public static Vector<TextNodeIndex> allExcept (Vector<? extends HTMLNode> html, Predicate<String> p)
124    { return TxNPeek.allExcept (html, new LV(html, 0, -1), p); }
125
126
127    // **** AllExcept: CRITERIA INCLUDES sPos, ePos
128    public static Vector<TextNodeIndex> allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, TextComparitor tc, String... compareStr)
129    { return TxNPeek.allExcept (html, new LV(html, sPos, ePos), ARGCHECK.TC(tc, compareStr)); }
130    public static Vector<TextNodeIndex> allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, Pattern p)
131    { return TxNPeek.allExcept (html, new LV(html, sPos, ePos), ARGCHECK.REGEX(p)); }
132    public static Vector<TextNodeIndex> allExcept (Vector<? extends HTMLNode> html, int sPos, int ePos, Predicate<String> p)
133    { return TxNPeek.allExcept (html, new LV(html, sPos, ePos), p); }
134}