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