BrightSide Workbench Full Report + Source Code
CrawlerLists.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.servlet.crawler;
20 
21 import java.util.HashSet;
22 import java.util.Map;
23 import java.util.Set;
24 import org.turro.http.activity.ActivityAction;
25 import org.turro.json.IJSONizable;
26 
31 public class CrawlerLists implements IJSONizable {
32 
33  private final Set<ActivityAction> whiteList = new HashSet<>();
34  private final Set<ActivityAction> blackList = new HashSet<>();
35 
36  public Set<ActivityAction> getWhiteList() {
37  return whiteList;
38  }
39 
40  public Set<ActivityAction> getBlackList() {
41  return blackList;
42  }
43 
44  public boolean isBlackListed(String ip) {
45  return blackList.stream().anyMatch(aa -> ip.equals(aa.getIp()));
46  }
47 
48  public boolean isWhiteListed(String ip) {
49  return whiteList.stream().anyMatch(aa -> ip.equals(aa.getIp()));
50  }
51 
53  return AllowedSet.from(this);
54  }
55 
56  @Override
57  public String toJson() {
58  return toJson(this);
59  }
60 
61  @Override
62  public String toJson(Map<String, Object> properties) {
63  return toJson(this, properties);
64  }
65 
66 }
static AllowedSet from(CrawlerLists crawlerLists)
Definition: AllowedSet.java:55
String toJson(Map< String, Object > properties)