feat: support and target Java 11
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -4,7 +4,7 @@
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -43,7 +43,7 @@ public class ScoreMenu extends AbstractMenu {
|
||||
}
|
||||
|
||||
public void updateScore(int score) {
|
||||
this.currentScoreLabel.setText("Score: %s".formatted(score));
|
||||
this.currentScoreLabel.setText(String.format("Score: %s", score));
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ScoreMenu extends AbstractMenu {
|
||||
LocalTime timeElapsed = LocalTime.ofNanoOfDay(LocalTime.now().toNanoOfDay() - startingTime.toNanoOfDay());
|
||||
|
||||
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern(timeElapsed.getHour() > 0 ? "HH:mm:ss" : "mm:ss");
|
||||
this.currentTimeLabel.setText("Zeit: %s".formatted(timeFormatter.format(timeElapsed)));
|
||||
this.currentTimeLabel.setText(String.format("Zeit: %s", timeFormatter.format(timeElapsed)));
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,15 +17,8 @@ public class NightJson {
|
||||
Class<?> jsonClass;
|
||||
String fileLocation;
|
||||
|
||||
public NightJson(Class<?> jsonClass) {
|
||||
this.jsonClass = jsonClass;
|
||||
}
|
||||
public NightJson(Class<?> jsonClass, String fileLocation) {
|
||||
this(jsonClass);
|
||||
this.fileLocation = fileLocation;
|
||||
}
|
||||
|
||||
public void setFileLocation(String fileLocation) {
|
||||
this.jsonClass = jsonClass;
|
||||
this.fileLocation = fileLocation;
|
||||
}
|
||||
|
||||
@@ -40,10 +33,10 @@ public class NightJson {
|
||||
Field field = it.next();
|
||||
jsonFile.write("\t");
|
||||
if (field.getType() == Comment.class) {
|
||||
jsonFile.write("// %s\n".formatted(((Comment) field.get(null)).commentString));
|
||||
jsonFile.write(String.format("// %s\n", ((Comment) field.get(null)).commentString));
|
||||
continue;
|
||||
}
|
||||
jsonFile.write((field.getType() == String.class || field.getType().isEnum() ? "\"%s\": \"%s\"" : "\"%s\": %s").formatted(field.getName(), field.get(null)));
|
||||
jsonFile.write(String.format(field.getType() == String.class || field.getType().isEnum() ? "\"%s\": \"%s\"" : "\"%s\": %s", field.getName(), field.get(null)));
|
||||
jsonFile.write(it.hasNext() ? ",\n" : "\n");
|
||||
}
|
||||
jsonFile.write("}");
|
||||
@@ -85,17 +78,7 @@ public class NightJson {
|
||||
try { field = jsonClass.getField(key);
|
||||
} catch (NoSuchFieldException e) {continue;}
|
||||
|
||||
Object value = switch (field.getType().getName()) {
|
||||
case "byte" -> Byte.parseByte(currentString);
|
||||
case "int" -> Integer.parseInt(currentString);
|
||||
case "long" -> Long.parseLong(currentString);
|
||||
case "float" -> Float.parseFloat(currentString);
|
||||
case "double" -> Double.parseDouble(currentString);
|
||||
default -> currentString;
|
||||
};
|
||||
if (field.getType().isEnum()) value = Arrays.stream(field.getType().getEnumConstants())
|
||||
.filter(enumConstant -> Objects.equals(enumConstant.toString(), currentString)).findFirst().orElseThrow();
|
||||
field.set(field, value);
|
||||
field.set(field, stringToObj(field, currentString));
|
||||
}
|
||||
jsonFile.close();
|
||||
} catch (IOException | IllegalAccessException | NoSuchElementException e) {
|
||||
@@ -104,6 +87,19 @@ public class NightJson {
|
||||
}
|
||||
}
|
||||
|
||||
private Object stringToObj(Field field, String currentString) {
|
||||
switch (field.getType().getName()) {
|
||||
case "byte": return Byte.parseByte(currentString);
|
||||
case "int": return Integer.parseInt(currentString);
|
||||
case "long": return Long.parseLong(currentString);
|
||||
case "float": return Float.parseFloat(currentString);
|
||||
case "double": return Double.parseDouble(currentString);
|
||||
}
|
||||
if (field.getType().isEnum()) return Arrays.stream(field.getType().getEnumConstants())
|
||||
.filter(enumConstant -> Objects.equals(enumConstant.toString(), currentString)).findFirst().orElseThrow();
|
||||
else return currentString;
|
||||
}
|
||||
|
||||
public static class Comment {
|
||||
final String commentString;
|
||||
public Comment(String commentString) {
|
||||
|
||||
Reference in New Issue
Block a user