|
1
|
|
|
/* |
|
2
|
|
|
* This file is part of Araknemu. |
|
3
|
|
|
* |
|
4
|
|
|
* Araknemu is free software: you can redistribute it and/or modify |
|
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
7
|
|
|
* (at your option) any later version. |
|
8
|
|
|
* |
|
9
|
|
|
* Araknemu is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
* GNU Lesser General Public License for more details. |
|
13
|
|
|
* |
|
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
15
|
|
|
* along with Araknemu. If not, see <https://www.gnu.org/licenses/>. |
|
16
|
|
|
* |
|
17
|
|
|
* Copyright (c) 2017-2019 Vincent Quatrevieux |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
package fr.quatrevieux.araknemu.core.config; |
|
21
|
|
|
|
|
22
|
|
|
import org.apache.commons.lang3.tuple.Pair; |
|
23
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable; |
|
24
|
|
|
import org.ini4j.Profile; |
|
25
|
|
|
|
|
26
|
|
|
import java.util.Collections; |
|
27
|
|
|
import java.util.Iterator; |
|
28
|
|
|
import java.util.List; |
|
29
|
|
|
import java.util.Map; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Configuration Pool for ini |
|
33
|
|
|
*/ |
|
34
|
|
|
public final class IniPool implements Pool { |
|
35
|
|
|
private final Profile.Section section; |
|
36
|
|
|
|
|
37
|
1 |
|
public IniPool(Profile.Section section) { |
|
38
|
1 |
|
this.section = section; |
|
39
|
1 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
@Override |
|
42
|
|
|
public boolean has(String key) { |
|
43
|
1 |
|
return section.containsKey(key); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
@Override |
|
47
|
|
|
public @Nullable String get(String key) { |
|
48
|
1 |
|
return section.get(key); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
@Override |
|
52
|
|
|
public List<String> getAll(String key) { |
|
53
|
1 |
|
final List<String> values = section.getAll(key); |
|
54
|
|
|
|
|
55
|
1 |
|
return values != null ? values : Collections.emptyList(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
@Override |
|
59
|
|
|
public Iterator<Map.Entry<String, String>> iterator() { |
|
60
|
1 |
|
return section.keySet().stream() |
|
61
|
1 |
|
.flatMap(name -> section.getAll(name) |
|
62
|
1 |
|
.stream() |
|
63
|
1 |
|
.map(value -> (Map.Entry<String, String>) Pair.of(name, value)) |
|
64
|
|
|
) |
|
65
|
1 |
|
.iterator() |
|
66
|
|
|
; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|