Settings: use class constants for properties, create custom writer

- Create Property class for defining config properties
  - Create logic for typed retrival of properties from YAML file
- Add custom save method
  - Retain comments from Comment annotations in the classes
  - Write in a sorted order: first discovered properties are first written to config.yml
- Adjust properties to reflect the current config.yml
- Add sample tests for the retrieval and writing of properties with the new setup
This commit is contained in:
ljacqu
2016-01-03 15:22:32 +01:00
parent c2deb9d0b5
commit 7d41ccbc9c
23 changed files with 1225 additions and 518 deletions
@@ -3,6 +3,7 @@ package fr.xephi.authme.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
/**
* Utils class for collections.
@@ -58,4 +59,17 @@ public final class CollectionUtils {
public static <T> boolean isEmpty(Collection<T> coll) {
return coll == null || coll.isEmpty();
}
public static <T> List<T> filterCommonStart(List<T> coll1, List<T> coll2) {
List<T> commonStart = new ArrayList<>();
int minSize = Math.min(coll1.size(), coll2.size());
for (int i = 0; i < minSize; ++i) {
if (Objects.equals(coll1.get(i), coll2.get(i))) {
commonStart.add(coll1.get(i));
} else {
break;
}
}
return commonStart;
}
}
@@ -117,4 +117,12 @@ public final class StringUtils {
return "[" + th.getClass().getSimpleName() + "]: " + th.getMessage();
}
public static String repeat(String str, int times) {
StringBuilder sb = new StringBuilder(str.length() * times);
for (int i = 0; i < times; ++i) {
sb.append(str);
}
return sb.toString();
}
}