1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 | package Torello.HTML.Tools.NewsSite;
import Torello.HTML.HTMLNode;
import Torello.HTML.URLFilter;
import Torello.Java.ParallelArrayException;
import java.util.Vector;
import java.net.URL;
class Branch
{
public static ArticleGet generate(URLFilter[] urlSelectors, ArticleGet[] getters)
{
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// FAIL-FAST: Check user-input for possible errors BEFORE building the Lambda-Function.
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
if (urlSelectors.length == 0) throw new IllegalArgumentException
("parameter 'urlSelectors' had zero-elements.");
if (getters.length == 0) throw new IllegalArgumentException
("parameter 'getters' had zero-elements.");
ParallelArrayException.check(urlSelectors, "urlSelectors", true, getters, "getters", true);
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Build the instance, using a lambda-expression
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
return (URL url, Vector<HTMLNode> page) ->
{
for (int i=0; i < urlSelectors.length; i++)
if (urlSelectors[i].test(url))
return getters[i].apply(url, page);
throw new ArticleGetException(
"None of the urlSelecctors you have provided matched the URL sent to this " +
"instance of ArticleGet."
);
};
}
}
|