Skip to content

Commit 71a6052

Browse files
committed
Make ConfigLib Java 8 compatible
1 parent f4795ca commit 71a6052

File tree

19 files changed

+239
-118
lines changed

19 files changed

+239
-118
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
language: java
22
jdk:
3-
oraclejdk10
3+
- oraclejdk8
4+
- oraclejdk9
5+
- oraclejdk10
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: ConfigLib
22
author: Exlll
33

4-
version: 2.0.0
4+
version: 2.0.1
55
main: de.exlll.configlib.ConfigLib
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: ConfigLib
22
author: Exlll
33

4-
version: 2.0.0
4+
version: 2.0.1
55
main: de.exlll.configlib.ConfigLib

ConfigLib-Core/src/main/java/de/exlll/configlib/Comments.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static boolean isCommented(AnnotatedElement element) {
4141
private static List<String> getComments(AnnotatedElement element) {
4242
Comment comment = element.getAnnotation(Comment.class);
4343
return (comment != null)
44-
? List.of(comment.value())
44+
? Arrays.asList(comment.value())
4545
: Collections.emptyList();
4646
}
4747

ConfigLib-Core/src/main/java/de/exlll/configlib/Reflect.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
import java.lang.reflect.Constructor;
88
import java.lang.reflect.Field;
99
import java.lang.reflect.InvocationTargetException;
10-
import java.util.Arrays;
11-
import java.util.List;
12-
import java.util.Map;
13-
import java.util.Set;
10+
import java.util.*;
1411

1512
enum Reflect {
1613
;
17-
private static final Set<Class<?>> SIMPLE_TYPES = Set.of(
14+
private static final Set<Class<?>> SIMPLE_TYPES = new HashSet<>(Arrays.asList(
1815
Boolean.class,
1916
Byte.class,
2017
Character.class,
@@ -24,8 +21,8 @@ enum Reflect {
2421
Float.class,
2522
Double.class,
2623
String.class
27-
);
28-
24+
));
25+
2926
static boolean isSimpleType(Class<?> cls) {
3027
return cls.isPrimitive() || SIMPLE_TYPES.contains(cls);
3128
}

ConfigLib-Core/src/main/java/de/exlll/configlib/configs/yaml/YamlComments.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private Map.Entry<String, String> toStringCommentEntry(
3131
Map.Entry<String, List<String>> entry
3232
) {
3333
String fieldComments = commentListToString(entry.getValue());
34-
return Map.entry(entry.getKey(), fieldComments);
34+
return new MapEntry<>(entry.getKey(), fieldComments);
3535
}
3636

3737
private String commentListToString(List<String> comments) {
@@ -43,4 +43,32 @@ private String commentListToString(List<String> comments) {
4343
private String toCommentLine(String comment) {
4444
return comment.isEmpty() ? "" : "# " + comment;
4545
}
46+
47+
private static final class MapEntry<K, V> implements Map.Entry<K, V> {
48+
private final K key;
49+
private V value;
50+
51+
public MapEntry(K key, V value) {
52+
this.key = key;
53+
this.value = value;
54+
}
55+
56+
@Override
57+
public K getKey() {
58+
return key;
59+
}
60+
61+
@Override
62+
public V getValue() {
63+
return value;
64+
}
65+
66+
@Override
67+
public V setValue(V value) {
68+
V old = this.value;
69+
this.value = value;
70+
return old;
71+
}
72+
}
73+
4674
}

ConfigLib-Core/src/main/java/de/exlll/configlib/configs/yaml/YamlSource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.IOException;
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
11+
import java.util.Arrays;
1112
import java.util.List;
1213
import java.util.Map;
1314
import java.util.Objects;
@@ -103,7 +104,7 @@ private void addClassComments() {
103104

104105
private void addFieldComments() {
105106
if (comments.hasFieldComments()) {
106-
List<String> dumpLines = List.of(dump.split("\n"));
107+
List<String> dumpLines = Arrays.asList(dump.split("\n"));
107108
addDumpLines(dumpLines);
108109
} else {
109110
builder.append(dump);

ConfigLib-Core/src/test/java/de/exlll/configlib/CommentsTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import de.exlll.configlib.annotation.Comment;
44
import org.junit.jupiter.api.Test;
55

6-
import java.util.List;
7-
import java.util.Map;
8-
6+
import static de.exlll.configlib.util.CollectionFactory.listOf;
7+
import static de.exlll.configlib.util.CollectionFactory.mapOf;
98
import static org.hamcrest.Matchers.empty;
109
import static org.hamcrest.Matchers.is;
1110
import static org.junit.Assert.assertThat;
@@ -27,11 +26,11 @@ class C {}
2726
assertThat(comments.getFieldComments().entrySet(), empty());
2827

2928
comments = Comments.ofClass(B.class);
30-
assertThat(comments.getClassComments(), is(List.of("B")));
29+
assertThat(comments.getClassComments(), is(listOf("B")));
3130
assertThat(comments.getFieldComments().entrySet(), empty());
3231

3332
comments = Comments.ofClass(C.class);
34-
assertThat(comments.getClassComments(), is(List.of("C", "D")));
33+
assertThat(comments.getClassComments(), is(listOf("C", "D")));
3534
assertThat(comments.getFieldComments().entrySet(), empty());
3635
}
3736

@@ -47,9 +46,9 @@ class A {
4746

4847
Comments comments = Comments.ofClass(A.class);
4948
assertThat(comments.getClassComments(), empty());
50-
assertThat(comments.getFieldComments(), is(Map.of(
51-
"b", List.of("b"),
52-
"c", List.of("c", "d")
49+
assertThat(comments.getFieldComments(), is(mapOf(
50+
"b", listOf("b"),
51+
"c", listOf("c", "d")
5352
)));
5453
}
5554
}

ConfigLib-Core/src/test/java/de/exlll/configlib/FieldMapperConverterTest.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import java.util.Set;
1313

1414
import static de.exlll.configlib.FieldMapperHelpers.*;
15+
import static de.exlll.configlib.util.CollectionFactory.listOf;
16+
import static de.exlll.configlib.util.CollectionFactory.mapOf;
17+
import static de.exlll.configlib.util.CollectionFactory.setOf;
1518
import static org.hamcrest.Matchers.is;
1619
import static org.junit.Assert.assertThat;
1720

@@ -39,7 +42,7 @@ private static final class PointToListConverter
3942
implements Converter<Point2D, List<Integer>> {
4043
@Override
4144
public List<Integer> convertTo(Point2D element, ConversionInfo info) {
42-
return List.of(element.x, element.y);
45+
return listOf(element.x, element.y);
4346
}
4447

4548
@Override
@@ -57,7 +60,7 @@ private static final class PointToMapConverter
5760
public Map<String, String> convertTo(Point2D element, ConversionInfo info) {
5861
int x = element.x;
5962
int y = element.y;
60-
return Map.of("p", x + ":" + y);
63+
return mapOf("p", x + ":" + y);
6164
}
6265

6366
@Override
@@ -153,7 +156,7 @@ class A {
153156
@Convert(NullConverter.class)
154157
String s = "string";
155158
}
156-
Map<String, Object> map = Map.of("s", "value");
159+
Map<String, Object> map = mapOf("s", "value");
157160
A a = instanceFromMap(new A(), map);
158161
assertThat(a.s, is("string"));
159162
}
@@ -190,7 +193,7 @@ class A {
190193
@Convert(IntToStringConverter.class)
191194
int i = 1;
192195
}
193-
A i = instanceFromMap(new A(), Map.of("i", "10"));
196+
A i = instanceFromMap(new A(), mapOf("i", "10"));
194197
assertThat(i.i, is(10));
195198
}
196199

@@ -203,8 +206,8 @@ class A {
203206
Point2D p2 = new Point2D();
204207
}
205208
Map<String, Object> map = instanceToMap(new A());
206-
assertThat(map.get("p1"), is(List.of(1, 2)));
207-
assertThat(map.get("p2"), is(Map.of("p", "1:2")));
209+
assertThat(map.get("p1"), is(listOf(1, 2)));
210+
assertThat(map.get("p2"), is(mapOf("p", "1:2")));
208211
}
209212

210213
@Test
@@ -215,9 +218,9 @@ class A {
215218
@Convert(PointToMapConverter.class)
216219
Point2D p2 = new Point2D();
217220
}
218-
Map<String, Object> map = Map.of(
219-
"p1", List.of(10, 11),
220-
"p2", Map.of("p", "11:12")
221+
Map<String, Object> map = mapOf(
222+
"p1", listOf(10, 11),
223+
"p2", mapOf("p", "11:12")
221224
);
222225
A i = instanceFromMap(new A(), map);
223226
assertThat(i.p1.x, is(10));
@@ -277,7 +280,7 @@ class A {
277280
@Convert(TestSubClassConverter.class)
278281
TestSubClass a = new TestSubClass();
279282
}
280-
Map<String, Object> map = Map.of(
283+
Map<String, Object> map = mapOf(
281284
"a", 1
282285
);
283286
String msg = "The value for field 'a' with type 'TestSubClass' " +
@@ -294,7 +297,7 @@ class C {
294297
class D {
295298
char d;
296299
}
297-
Map<String, Object> map = Map.of(
300+
Map<String, Object> map = mapOf(
298301
"c", "", "d", "12"
299302
);
300303
String msg = "The value for field 'c' with type 'char' " +
@@ -313,7 +316,7 @@ void instanceFromMapCatchesClassCastExceptionOfStrings() {
313316
class B {
314317
String b = "string";
315318
}
316-
Map<String, Object> map = Map.of(
319+
Map<String, Object> map = mapOf(
317320
"b", 2
318321
);
319322
String msg = "The value for field 'b' with type 'String' " +
@@ -327,7 +330,7 @@ void instanceFromMapCatchesClassCastExceptionOfUnknownEnumConstants() {
327330
class A {
328331
LocalTestEnum e = LocalTestEnum.T;
329332
}
330-
Map<String, Object> map = Map.of(
333+
Map<String, Object> map = mapOf(
331334
"e", "V"
332335
);
333336
String msg = "The value for field 'e' with type 'LocalTestEnum' " +
@@ -340,10 +343,10 @@ class A {
340343
void instanceFromMapCatchesClassCastExceptionOfUnknownEnumConstantsInLists() {
341344
class A {
342345
@ElementType(LocalTestEnum.class)
343-
List<List<LocalTestEnum>> l = List.of();
346+
List<List<LocalTestEnum>> l = listOf();
344347
}
345-
Map<String, Object> map = Map.of(
346-
"l", List.of(List.of("Q", "V"))
348+
Map<String, Object> map = mapOf(
349+
"l", listOf(listOf("Q", "V"))
347350
);
348351
ConfigurationException ex = assertIfmThrowsCfgException(new A(), map);
349352
Throwable cause = ex.getCause();
@@ -357,10 +360,10 @@ class A {
357360
void instanceFromMapCatchesClassCastExceptionOfUnknownEnumConstantsInSets() {
358361
class A {
359362
@ElementType(LocalTestEnum.class)
360-
Set<List<LocalTestEnum>> s = Set.of();
363+
Set<List<LocalTestEnum>> s = setOf();
361364
}
362-
Map<String, Object> map = Map.of(
363-
"s", Set.of(List.of("Q", "V"))
365+
Map<String, Object> map = mapOf(
366+
"s", setOf(listOf("Q", "V"))
364367
);
365368
ConfigurationException ex = assertIfmThrowsCfgException(new A(), map);
366369
Throwable cause = ex.getCause();
@@ -374,10 +377,10 @@ class A {
374377
void instanceFromMapCatchesClassCastExceptionOfUnknownEnumConstantsInMaps() {
375378
class A {
376379
@ElementType(LocalTestEnum.class)
377-
Map<Integer, List<LocalTestEnum>> m = Map.of();
380+
Map<Integer, List<LocalTestEnum>> m = mapOf();
378381
}
379-
Map<String, Object> map = Map.of(
380-
"m", Map.of(1, List.of("Q", "V"))
382+
Map<String, Object> map = mapOf(
383+
"m", mapOf(1, listOf("Q", "V"))
381384
);
382385
ConfigurationException ex = assertIfmThrowsCfgException(new A(), map);
383386
Throwable cause = ex.getCause();

0 commit comments

Comments
 (0)