mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-13 15:08:35 +00:00
More deprecation removal
This commit is contained in:
@ -111,7 +111,7 @@ public class YAMLNode {
|
||||
*/
|
||||
private Object prepareSerialization(Object value) {
|
||||
if (value instanceof Vector) {
|
||||
Map<String, Double> out = new LinkedHashMap<String, Double>();
|
||||
Map<String, Double> out = new LinkedHashMap<>();
|
||||
Vector vec = (Vector) value;
|
||||
out.put("x", vec.getX());
|
||||
out.put("y", vec.getY());
|
||||
@ -169,7 +169,7 @@ public class YAMLNode {
|
||||
* @return a node for the path
|
||||
*/
|
||||
public YAMLNode addNode(String path) {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
YAMLNode node = new YAMLNode(map, writeDefaults);
|
||||
setProperty(path, map);
|
||||
return node;
|
||||
@ -398,12 +398,12 @@ public class YAMLNode {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> getKeys(String path) {
|
||||
if (path == null) return new ArrayList<String>(root.keySet());
|
||||
if (path == null) return new ArrayList<>(root.keySet());
|
||||
Object o = getProperty(path);
|
||||
if (o == null) {
|
||||
return null;
|
||||
} else if (o instanceof Map) {
|
||||
return new ArrayList<String>(((Map<String, Object>) o).keySet());
|
||||
return new ArrayList<>(((Map<String, Object>) o).keySet());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -444,10 +444,10 @@ public class YAMLNode {
|
||||
List<Object> raw = getList(path);
|
||||
if (raw == null) {
|
||||
if (writeDefaults && def != null) setProperty(path, def);
|
||||
return def != null ? def : new ArrayList<String>();
|
||||
return def != null ? def : new ArrayList<>();
|
||||
}
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Object o : raw) {
|
||||
if (o == null) {
|
||||
continue;
|
||||
@ -474,10 +474,10 @@ public class YAMLNode {
|
||||
List<Object> raw = getList(path);
|
||||
if (raw == null) {
|
||||
if (writeDefaults && def != null) setProperty(path, def);
|
||||
return def != null ? def : new ArrayList<Integer>();
|
||||
return def != null ? def : new ArrayList<>();
|
||||
}
|
||||
|
||||
List<Integer> list = new ArrayList<Integer>();
|
||||
List<Integer> list = new ArrayList<>();
|
||||
for (Object o : raw) {
|
||||
Integer i = castInt(o);
|
||||
if (i != null) {
|
||||
@ -503,10 +503,10 @@ public class YAMLNode {
|
||||
List<Object> raw = getList(path);
|
||||
if (raw == null) {
|
||||
if (writeDefaults && def != null) setProperty(path, def);
|
||||
return def != null ? def : new ArrayList<Double>();
|
||||
return def != null ? def : new ArrayList<>();
|
||||
}
|
||||
|
||||
List<Double> list = new ArrayList<Double>();
|
||||
List<Double> list = new ArrayList<>();
|
||||
for (Object o : raw) {
|
||||
Double i = castDouble(o);
|
||||
if (i != null) {
|
||||
@ -532,10 +532,10 @@ public class YAMLNode {
|
||||
List<Object> raw = getList(path);
|
||||
if (raw == null) {
|
||||
if (writeDefaults && def != null) setProperty(path, def);
|
||||
return def != null ? def : new ArrayList<Boolean>();
|
||||
return def != null ? def : new ArrayList<>();
|
||||
}
|
||||
|
||||
List<Boolean> list = new ArrayList<Boolean>();
|
||||
List<Boolean> list = new ArrayList<>();
|
||||
for (Object o : raw) {
|
||||
Boolean tetsu = castBoolean(o);
|
||||
if (tetsu != null) {
|
||||
@ -559,7 +559,7 @@ public class YAMLNode {
|
||||
*/
|
||||
public List<Vector> getVectorList(String path, List<Vector> def) {
|
||||
List<YAMLNode> raw = getNodeList(path, null);
|
||||
List<Vector> list = new ArrayList<Vector>();
|
||||
List<Vector> list = new ArrayList<>();
|
||||
|
||||
for (YAMLNode o : raw) {
|
||||
Double x = o.getDouble("x");
|
||||
@ -590,7 +590,7 @@ public class YAMLNode {
|
||||
public List<Vector2D> getVector2dList(String path, List<Vector2D> def) {
|
||||
|
||||
List<YAMLNode> raw = getNodeList(path, null);
|
||||
List<Vector2D> list = new ArrayList<Vector2D>();
|
||||
List<Vector2D> list = new ArrayList<>();
|
||||
|
||||
for (YAMLNode o : raw) {
|
||||
Double x = o.getDouble("x");
|
||||
@ -620,7 +620,7 @@ public class YAMLNode {
|
||||
public List<BlockVector2D> getBlockVector2dList(String path, List<BlockVector2D> def) {
|
||||
|
||||
List<YAMLNode> raw = getNodeList(path, null);
|
||||
List<BlockVector2D> list = new ArrayList<BlockVector2D>();
|
||||
List<BlockVector2D> list = new ArrayList<>();
|
||||
|
||||
for (YAMLNode o : raw) {
|
||||
Double x = o.getDouble("x");
|
||||
@ -652,10 +652,10 @@ public class YAMLNode {
|
||||
List<Object> raw = getList(path);
|
||||
if (raw == null) {
|
||||
if (writeDefaults && def != null) setProperty(path, def);
|
||||
return def != null ? def : new ArrayList<YAMLNode>();
|
||||
return def != null ? def : new ArrayList<>();
|
||||
}
|
||||
|
||||
List<YAMLNode> list = new ArrayList<YAMLNode>();
|
||||
List<YAMLNode> list = new ArrayList<>();
|
||||
for (Object o : raw) {
|
||||
if (o instanceof Map) {
|
||||
list.add(new YAMLNode((Map<String, Object>) o, writeDefaults));
|
||||
@ -698,7 +698,7 @@ public class YAMLNode {
|
||||
return null;
|
||||
} else if (o instanceof Map) {
|
||||
Map<String, YAMLNode> nodes =
|
||||
new LinkedHashMap<String, YAMLNode>();
|
||||
new LinkedHashMap<>();
|
||||
|
||||
for (Map.Entry<String, Object> entry : ((Map<String, Object>) o).entrySet()) {
|
||||
if (entry.getValue() instanceof Map) {
|
||||
|
@ -31,6 +31,7 @@ import org.yaml.snakeyaml.representer.Represent;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@ -76,10 +77,10 @@ public class YAMLProcessor extends YAMLNode {
|
||||
* Comments support based on ZerothAngel's AnnotatedYAMLConfiguration
|
||||
* Comments are only supported with YAMLFormat.EXTENDED
|
||||
*/
|
||||
private final Map<String, String> comments = new HashMap<String, String>();
|
||||
private final Map<String, String> comments = new HashMap<>();
|
||||
|
||||
public YAMLProcessor(File file, boolean writeDefaults, YAMLFormat format) {
|
||||
super(new LinkedHashMap<String, Object>(), writeDefaults);
|
||||
super(new LinkedHashMap<>(), writeDefaults);
|
||||
this.format = format;
|
||||
|
||||
DumperOptions options = new FancyDumperOptions();
|
||||
@ -103,21 +104,13 @@ public class YAMLProcessor extends YAMLNode {
|
||||
* @throws java.io.IOException on load error
|
||||
*/
|
||||
public void load() throws IOException {
|
||||
InputStream stream = null;
|
||||
|
||||
try {
|
||||
stream = getInputStream();
|
||||
if (stream == null) throw new IOException("Stream is null!");
|
||||
try (InputStream stream = getInputStream()) {
|
||||
if (stream == null)
|
||||
throw new IOException("Stream is null!");
|
||||
read(yaml.load(new UnicodeReader(stream)));
|
||||
} catch (YAMLProcessorException e) {
|
||||
root = new LinkedHashMap<String, Object>();
|
||||
} finally {
|
||||
try {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
root = new LinkedHashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,18 +160,15 @@ public class YAMLProcessor extends YAMLNode {
|
||||
* @return true if it was successful
|
||||
*/
|
||||
public boolean save() {
|
||||
OutputStream stream = null;
|
||||
|
||||
File parent = file.getParentFile();
|
||||
|
||||
if (parent != null) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
try {
|
||||
stream = getOutputStream();
|
||||
if (stream == null) return false;
|
||||
OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
|
||||
try (OutputStream stream = getOutputStream()) {
|
||||
if (stream == null)
|
||||
return false;
|
||||
OutputStreamWriter writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8);
|
||||
if (header != null) {
|
||||
writer.append(header);
|
||||
writer.append(LINE_BREAK);
|
||||
@ -187,7 +177,7 @@ public class YAMLProcessor extends YAMLNode {
|
||||
yaml.dump(root, writer);
|
||||
} else {
|
||||
// Iterate over each root-level property and dump
|
||||
for (Entry<String, Object> entry : root.entrySet()) {
|
||||
for (Entry<String, Object> entry: root.entrySet()) {
|
||||
// Output comment, if present
|
||||
String comment = comments.get(entry.getKey());
|
||||
if (comment != null) {
|
||||
@ -202,12 +192,6 @@ public class YAMLProcessor extends YAMLNode {
|
||||
}
|
||||
return true;
|
||||
} catch (IOException ignored) {
|
||||
} finally {
|
||||
try {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -217,9 +201,9 @@ public class YAMLProcessor extends YAMLNode {
|
||||
private void read(Object input) throws YAMLProcessorException {
|
||||
try {
|
||||
if (null == input) {
|
||||
root = new LinkedHashMap<String, Object>();
|
||||
root = new LinkedHashMap<>();
|
||||
} else {
|
||||
root = new LinkedHashMap<String, Object>((Map<String, Object>) input);
|
||||
root = new LinkedHashMap<>((Map<String, Object>) input);
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
throw new YAMLProcessorException("Root document must be an key-value structure");
|
||||
@ -302,7 +286,7 @@ public class YAMLProcessor extends YAMLNode {
|
||||
* @return a node
|
||||
*/
|
||||
public static YAMLNode getEmptyNode(boolean writeDefaults) {
|
||||
return new YAMLNode(new LinkedHashMap<String, Object>(), writeDefaults);
|
||||
return new YAMLNode(new LinkedHashMap<>(), writeDefaults);
|
||||
}
|
||||
|
||||
// This will be included in snakeyaml 1.10, but until then we have to do it manually.
|
||||
@ -321,12 +305,7 @@ public class YAMLProcessor extends YAMLNode {
|
||||
|
||||
private static class FancyRepresenter extends Representer {
|
||||
private FancyRepresenter() {
|
||||
this.nullRepresenter = new Represent() {
|
||||
@Override
|
||||
public Node representData(Object o) {
|
||||
return representScalar(Tag.NULL, "");
|
||||
}
|
||||
};
|
||||
this.nullRepresenter = o -> representScalar(Tag.NULL, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user