Applying Java migration aids through Java 14.

This commit is contained in:
Rob Greene
2025-10-18 18:02:10 -07:00
parent 824f03f855
commit 9c55467c09
9 changed files with 50 additions and 76 deletions
@@ -14,16 +14,16 @@ public class Directives {
private Directives() { /* Prevent construction. */ }
private static final Map<String,Class<? extends Directive>> DIRECTIVES =
new TreeMap<String,Class<? extends Directive>>(String.CASE_INSENSITIVE_ORDER) {
@Serial
new TreeMap<>(String.CASE_INSENSITIVE_ORDER) {
@Serial
private static final long serialVersionUID = -8111460701487331592L;
{
put(EmbeddedBinaryDirective.NAME, EmbeddedBinaryDirective.class);
put(HexDirective.NAME, HexDirective.class);
put(EmbeddedShapeTable.NAME, EmbeddedShapeTable.class);
}
};
{
put(EmbeddedBinaryDirective.NAME, EmbeddedBinaryDirective.class);
put(HexDirective.NAME, HexDirective.class);
put(EmbeddedShapeTable.NAME, EmbeddedShapeTable.class);
}
};
public static Directive find(String text, Configuration config, OutputStream outputStream) {
if (DIRECTIVES.containsKey(text)) {
@@ -48,8 +48,6 @@ public class CodeBuilder {
}
/** Add a {@code byte[]} to this stream. */
public CodeBuilder addBinary(byte[] data) {
return add(state -> {
state.write(data);
});
return add(state -> state.write(data));
}
}
@@ -32,7 +32,7 @@ public class CodeMark {
*/
public boolean update(GeneratorState state) {
int currentAddress = state.currentAddress();
loopCounter.merge(currentAddress, 1, (a,b) -> a+b);
loopCounter.merge(currentAddress, 1, Integer::sum);
if (loopCounter.get(currentAddress) > LOOP_MAX) {
StringBuilder sb = new StringBuilder();
sb.append("A circular pattern in a dynamic address was discovered!\n");
@@ -28,28 +28,20 @@ public class Token {
}
@Override
public String toString() {
switch (type) {
case EOL:
return type.toString();
case KEYWORD:
return keyword.toString();
case NUMBER:
return String.format("%s(%f)", type, number);
default:
return String.format("%s(%s)", type, text);
}
return switch (type) {
case EOL -> type.toString();
case KEYWORD -> keyword.toString();
case NUMBER -> String.format("%s(%f)", type, number);
default -> String.format("%s(%s)", type, text);
};
}
public String asString() {
switch (type) {
case EOL:
return "\n";
case KEYWORD:
return keyword.toString();
case NUMBER:
return number.toString();
default:
return text;
}
return switch (type) {
case EOL -> "\n";
case KEYWORD -> keyword.toString();
case NUMBER -> number.toString();
default -> text;
};
}
public static Token eol(int line) {
@@ -90,7 +90,7 @@ public class ExtractConstantValues extends BaseVisitor {
program.lines.stream()
.map(Line::getLineNumber)
.filter(super.reassignments::containsValue)
.forEach(n -> { super.reassignments.put(n, n+1); });
.forEach(n -> super.reassignments.put(n, n+1));
}
program.lines.add(0, line);
}
@@ -245,22 +245,13 @@ public class BitmapShape implements Shape {
public boolean onOrAtEdge(VectorCommand vector) {
// No clever way to do this?
switch (vector) {
case MOVE_DOWN:
case PLOT_DOWN:
return point.y >= height;
case MOVE_UP:
case PLOT_UP:
return point.y < 0;
case MOVE_LEFT:
case PLOT_LEFT:
return point.x < 0;
case MOVE_RIGHT:
case PLOT_RIGHT:
return point.x >= width;
default:
throw new RuntimeException("Unexpected vector: " + vector);
}
return switch (vector) {
case MOVE_DOWN, PLOT_DOWN -> point.y >= height;
case MOVE_UP, PLOT_UP -> point.y < 0;
case MOVE_LEFT, PLOT_LEFT -> point.x < 0;
case MOVE_RIGHT, PLOT_RIGHT -> point.x >= width;
default -> throw new RuntimeException("Unexpected vector: " + vector);
};
}
}
@@ -119,7 +119,7 @@ public class VectorShape implements Shape {
@Override
public String apply(String shortCommands) {
Matcher matcher = pattern.matcher(shortCommands);
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
while (matcher.find()) {
matcher.appendReplacement(sb, fn.apply(matcher.group(1)));
}