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">
|
<component name="FrameworkDetectionExcludesConfiguration">
|
||||||
<file type="web" url="file://$PROJECT_DIR$" />
|
<file type="web" url="file://$PROJECT_DIR$" />
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -43,7 +43,7 @@ public class ScoreMenu extends AbstractMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateScore(int score) {
|
public void updateScore(int score) {
|
||||||
this.currentScoreLabel.setText("Score: %s".formatted(score));
|
this.currentScoreLabel.setText(String.format("Score: %s", score));
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class ScoreMenu extends AbstractMenu {
|
|||||||
LocalTime timeElapsed = LocalTime.ofNanoOfDay(LocalTime.now().toNanoOfDay() - startingTime.toNanoOfDay());
|
LocalTime timeElapsed = LocalTime.ofNanoOfDay(LocalTime.now().toNanoOfDay() - startingTime.toNanoOfDay());
|
||||||
|
|
||||||
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern(timeElapsed.getHour() > 0 ? "HH:mm:ss" : "mm:ss");
|
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();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,15 +17,8 @@ public class NightJson {
|
|||||||
Class<?> jsonClass;
|
Class<?> jsonClass;
|
||||||
String fileLocation;
|
String fileLocation;
|
||||||
|
|
||||||
public NightJson(Class<?> jsonClass) {
|
|
||||||
this.jsonClass = jsonClass;
|
|
||||||
}
|
|
||||||
public NightJson(Class<?> jsonClass, String fileLocation) {
|
public NightJson(Class<?> jsonClass, String fileLocation) {
|
||||||
this(jsonClass);
|
this.jsonClass = jsonClass;
|
||||||
this.fileLocation = fileLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFileLocation(String fileLocation) {
|
|
||||||
this.fileLocation = fileLocation;
|
this.fileLocation = fileLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,10 +33,10 @@ public class NightJson {
|
|||||||
Field field = it.next();
|
Field field = it.next();
|
||||||
jsonFile.write("\t");
|
jsonFile.write("\t");
|
||||||
if (field.getType() == Comment.class) {
|
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;
|
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(it.hasNext() ? ",\n" : "\n");
|
||||||
}
|
}
|
||||||
jsonFile.write("}");
|
jsonFile.write("}");
|
||||||
@@ -85,17 +78,7 @@ public class NightJson {
|
|||||||
try { field = jsonClass.getField(key);
|
try { field = jsonClass.getField(key);
|
||||||
} catch (NoSuchFieldException e) {continue;}
|
} catch (NoSuchFieldException e) {continue;}
|
||||||
|
|
||||||
Object value = switch (field.getType().getName()) {
|
field.set(field, stringToObj(field, currentString));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
jsonFile.close();
|
jsonFile.close();
|
||||||
} catch (IOException | IllegalAccessException | NoSuchElementException e) {
|
} 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 {
|
public static class Comment {
|
||||||
final String commentString;
|
final String commentString;
|
||||||
public Comment(String commentString) {
|
public Comment(String commentString) {
|
||||||
|
|||||||
Reference in New Issue
Block a user