-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchEngine.java
55 lines (40 loc) · 1.14 KB
/
SearchEngine.java
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
46
47
48
49
50
51
52
53
54
55
package Lab11;
import java.util.TreeSet;
public class SearchEngine {
private String name;
private TreeSet<Shop> shops;
public SearchEngine(String name) {
this.name = name;
shops = new TreeSet<Shop>();
}
public void addInternetShop(Shop shop) throws Exception {
if (shop == null) {
throw new Exception("Shop object can`t be null");
}
if (shops.contains(shop)) {
throw new Exception("Shop is already exists");
}
shops.add(shop);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public TreeSet<Shop> getShops() {
return shops;
}
public Shop getShopByName(String findShop) throws Exception {
var foundShop = shops.stream().filter(f -> f.getName() == findShop).findFirst();
if (!foundShop.isPresent()) {
throw new Exception("Shop not found");
}
return foundShop.get();
}
@Override
public String toString() {
return "service:" + name +
"\ninternetShops:" + shops;
}
}