Skip to content

Commit

Permalink
Migrate to Java 8 language level (#42)
Browse files Browse the repository at this point in the history
* Lift language level to Java 8

* Migrate Java 8 language features

* General code cleanup

* Bump dependency versions compatible with Java 8
  • Loading branch information
gregorbg authored Nov 16, 2022
1 parent 996caf4 commit ac66e33
Show file tree
Hide file tree
Showing 30 changed files with 273 additions and 311 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/configurations/Languages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object Languages {

fun Project.configureJava() {
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_6
sourceCompatibility = JavaVersion.VERSION_1_8

withJavadocJar()
withSourcesJar()
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[versions]
junit-jupiter = "5.5.2"
junit-jupiter = "5.9.1"

[libraries]
logback-classic = { module = "ch.qos.logback:logback-classic", version = "1.2.10" }
logback-classic = { module = "ch.qos.logback:logback-classic", version = "1.4.4" }
gwt-exporter = { module = "org.timepedia.exporter:gwtexporter", version = "2.5.1" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter" }
apache-commons-math3 = { module = "org.apache.commons:commons-math3", version = "3.6.1" }

[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version = "7.1.2" }
dependency-versions = { id = "com.github.ben-manes.versions", version = "0.42.0" }
dependency-versions = { id = "com.github.ben-manes.versions", version = "0.44.0" }
nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version = "1.1.0" }
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class ScrambleProvider {

public static List<String> getScrambles(String fileName) throws IOException {
List<String> scrambles = new ArrayList<String>();
List<String> scrambles = new ArrayList<>();

// Read scrambles
File file = new File(fileName);
Expand All @@ -37,7 +37,7 @@ public static List<String> getScrambles(String fileName) throws IOException {

// This is the main test
public static List<String> generateWcaScrambles(CubePuzzle cube, int N) {
List<String> scrambles = new ArrayList<String>(N);
List<String> scrambles = new ArrayList<>(N);

for (int i = 0; i < N; i++) {
// Give some status to the user
Expand All @@ -59,7 +59,7 @@ public static List<String> generateWcaScrambles(int N) {
}

public static List<CubePuzzle.CubeState> convertToCubeStates(List<String> scrambles) throws InvalidScrambleException {
List<CubePuzzle.CubeState> cubeStates = new ArrayList<CubePuzzle.CubeState>(scrambles.size());
List<CubePuzzle.CubeState> cubeStates = new ArrayList<>(scrambles.size());
CubePuzzle puzzle = new CubePuzzle(3);

for (String scramble : scrambles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void test() throws Exception {
}

private List<String> randomMovesScrambles(int N) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
for (int i = 0; i < N; i++) {
result.add(randomMovesScramble());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import org.worldcubeassociation.tnoodle.svglite.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Random;
import java.util.*;
import java.util.logging.Logger;

import org.worldcubeassociation.tnoodle.scrambles.InvalidScrambleException;
Expand Down Expand Up @@ -55,7 +52,7 @@ public String getShortName() {
{1,1,1,1,1,1,1,1,1, -1, 0,-1, 0, 0, 0,-1, 0,-1},// A
};

private static HashMap<String, Color> defaultColorScheme = new HashMap<String, Color>();
private static final Map<String, Color> defaultColorScheme = new HashMap<>();
static {
defaultColorScheme.put("Front", new Color(0x3375b2));
defaultColorScheme.put("Back", new Color(0x55ccff));
Expand All @@ -67,8 +64,8 @@ public String getShortName() {
defaultColorScheme.put("PinDown", new Color(0x885500));
}
@Override
public HashMap<String, Color> getDefaultColorScheme() {
return new HashMap<String, Color>(defaultColorScheme);
public Map<String, Color> getDefaultColorScheme() {
return new HashMap<>(defaultColorScheme);
}

@Override
Expand All @@ -94,20 +91,20 @@ public PuzzleStateAndGenerator generateRandomMoves(Random r) {
int turn = r.nextInt(12)-5;
boolean clockwise = ( turn >= 0 );
turn = Math.abs(turn);
scramble.append( turns[x] + turn + (clockwise?"+":"-") + " ");
scramble.append(turns[x]).append(turn).append(clockwise ? "+" : "-").append(" ");
}
scramble.append( "y2 ");
for(int x=4; x<9; x++) {
int turn = r.nextInt(12)-5;
boolean clockwise = ( turn >= 0 );
turn = Math.abs(turn);
scramble.append( turns[x] + turn + (clockwise?"+":"-") + " ");
scramble.append(turns[x]).append(turn).append(clockwise ? "+" : "-").append(" ");
}

boolean isFirst = true;
for(int x=0;x<4;x++) {
if (r.nextInt(2) == 1) {
scramble.append((isFirst?"":" ")+turns[x]);
scramble.append(isFirst ? "" : " ").append(turns[x]);
isFirst = false;
}
}
Expand All @@ -125,9 +122,9 @@ public PuzzleStateAndGenerator generateRandomMoves(Random r) {

public class ClockState extends PuzzleState {

private boolean[] pins;
private int[] posit;
private boolean rightSideUp;
private final boolean[] pins;
private final int[] posit;
private final boolean rightSideUp;
public ClockState() {
pins = new boolean[] {false, false, false, false};
posit = new int[] {0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0};
Expand All @@ -141,8 +138,8 @@ public ClockState(boolean[] pins, int[] posit, boolean rightSideUp) {
}

@Override
public LinkedHashMap<String, PuzzleState> getSuccessorsByName() {
LinkedHashMap<String, PuzzleState> successors = new LinkedHashMap<String, PuzzleState>();
public Map<String, PuzzleState> getSuccessorsByName() {
Map<String, PuzzleState> successors = new LinkedHashMap<>();

for(int turn = 0; turn < turns.length; turn++) {
for(int rot = 0; rot < 12; rot++) {
Expand Down Expand Up @@ -197,7 +194,7 @@ public int hashCode() {
}

@Override
protected Svg drawScramble(HashMap<String, Color> colorScheme) {
protected Svg drawScramble(Map<String, Color> colorScheme) {
Svg svg = new Svg(getPreferredSize());
svg.setStroke(STROKE_WIDTH, 10, "round");
drawBackground(svg, colorScheme);
Expand All @@ -210,7 +207,7 @@ protected Svg drawScramble(HashMap<String, Color> colorScheme) {
return svg;
}

protected void drawBackground(Svg g, HashMap<String, Color> colorScheme) {
protected void drawBackground(Svg g, Map<String, Color> colorScheme) {
String[] colorString;
if(rightSideUp) {
colorString = new String[]{"Front", "Back"};
Expand Down Expand Up @@ -274,7 +271,7 @@ protected void drawBackground(Svg g, HashMap<String, Color> colorScheme) {
}
}

protected void drawClock(Svg g, int clock, int position, HashMap<String, Color> colorScheme) {
protected void drawClock(Svg g, int clock, int position, Map<String, Color> colorScheme) {
Transform t = new Transform();
t.rotate(Math.toRadians(position*30));
int netX = 0;
Expand Down Expand Up @@ -329,7 +326,7 @@ protected void drawClock(Svg g, int clock, int position, HashMap<String, Color>
g.appendChild(handBase);
}

protected void drawPins(Svg g, boolean[] pins, HashMap<String, Color> colorScheme) {
protected void drawPins(Svg g, boolean[] pins, Map<String, Color> colorScheme) {
Transform t = new Transform();
t.translate(radius + gap, radius + gap);
int k = 0;
Expand All @@ -353,7 +350,7 @@ protected void drawPins(Svg g, boolean[] pins, HashMap<String, Color> colorSchem
}
}

protected void drawPin(Svg g, Transform t, boolean pinUp, HashMap<String, Color> colorScheme) {
protected void drawPin(Svg g, Transform t, boolean pinUp, Map<String, Color> colorScheme) {
Circle pin = new Circle(0, 0, pinRadius);
pin.setTransform(t);
pin.setStroke(Color.BLACK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Export
public class CubePuzzle extends Puzzle {

public static enum Face {
public enum Face {
R, U, F, L, D, B;

public Face oppositeFace() {
Expand All @@ -23,7 +23,7 @@ public Face oppositeFace() {
}

private static final String[] DIR_TO_STR = new String[] { null, "", "2", "'" };
private static HashMap<Face, String> faceRotationsByName = new HashMap<Face, String>();
private static final Map<Face, String> faceRotationsByName = new HashMap<>();
static {
faceRotationsByName.put(Face.R, "x");
faceRotationsByName.put(Face.U, "y");
Expand Down Expand Up @@ -96,7 +96,7 @@ protected CubeMove[][] getRandomOrientationMoves(int thickness) {
int i = 0;
for(CubeMove randomUFaceMove : randomUFaceMoves) {
for(CubeMove randomFFaceMove : randomFFaceMoves) {
ArrayList<CubeMove> moves = new ArrayList<CubeMove>();
List<CubeMove> moves = new ArrayList<>();
if(randomUFaceMove != null) {
moves.add(randomUFaceMove);
}
Expand Down Expand Up @@ -219,7 +219,7 @@ private static void slice(Face face, int slice, int dir, int[][][] image) {
}
}

private static HashMap<String, Color> defaultColorScheme = new HashMap<String, Color>();
private static final Map<String, Color> defaultColorScheme = new HashMap<>();
static {
defaultColorScheme.put("B", Color.BLUE);
defaultColorScheme.put("D", Color.YELLOW);
Expand All @@ -229,8 +229,8 @@ private static void slice(Face face, int slice, int dir, int[][][] image) {
defaultColorScheme.put("U", Color.WHITE);
}
@Override
public HashMap<String, Color> getDefaultColorScheme() {
return new HashMap<String, Color>(defaultColorScheme);
public Map<String, Color> getDefaultColorScheme() {
return new HashMap<>(defaultColorScheme);
}

@Override
Expand All @@ -249,7 +249,7 @@ private static Dimension getImageSize(int gap, int unitSize, int size) {
return new Dimension(getCubeViewWidth(unitSize, gap, size), getCubeViewHeight(unitSize, gap, size));
}

private void drawCube(Svg g, int[][][] state, int gap, int cubieSize, HashMap<String, Color> colorScheme) {
private void drawCube(Svg g, int[][][] state, int gap, int cubieSize, Map<String, Color> colorScheme) {
paintCubeFace(g, gap, 2*gap+size*cubieSize, size, cubieSize, state[Face.L.ordinal()], colorScheme);
paintCubeFace(g, 2*gap+size*cubieSize, 3*gap+2*size*cubieSize, size, cubieSize, state[Face.D.ordinal()], colorScheme);
paintCubeFace(g, 4*gap+3*size*cubieSize, 2*gap+size*cubieSize, size, cubieSize, state[Face.B.ordinal()], colorScheme);
Expand All @@ -258,7 +258,7 @@ private void drawCube(Svg g, int[][][] state, int gap, int cubieSize, HashMap<St
paintCubeFace(g, 2*gap+size*cubieSize, 2*gap+size*cubieSize, size, cubieSize, state[Face.F.ordinal()], colorScheme);
}

private void paintCubeFace(Svg g, int x, int y, int size, int cubieSize, int[][] faceColors, HashMap<String, Color> colorScheme) {
private void paintCubeFace(Svg g, int x, int y, int size, int cubieSize, int[][] faceColors, Map<String, Color> colorScheme) {
for(int row = 0; row < size; row++) {
for(int col = 0; col < size; col++) {
int tempx = x + col*cubieSize;
Expand Down Expand Up @@ -495,32 +495,32 @@ public TwoByTwoState toTwoByTwoState() {
*/
public String toFaceCube() {
assert size == 3;
String state = "";
StringBuilder state = new StringBuilder();
for(char f : "URFDLB".toCharArray()) {
Face face = Face.valueOf("" + f);
int[][] faceArr = image[face.ordinal()];
for(int i = 0; i < faceArr.length; i++) {
for(int j = 0; j < faceArr[i].length; j++) {
state += Face.values()[faceArr[i][j]].toString();
for (int[] faceState : faceArr) {
for (int piece : faceState) {
state.append(Face.values()[piece].toString());
}
}
}
return state;
return state.toString();
}

@Override
public LinkedHashMap<String, CubeState> getSuccessorsByName() {
public Map<String, CubeState> getSuccessorsByName() {
return getSuccessorsWithinSlice(size - 1, true);
}

@Override
public HashMap<String, CubeState> getScrambleSuccessors() {
return getSuccessorsWithinSlice((int) (size / 2) - 1, false);
public Map<String, CubeState> getScrambleSuccessors() {
return getSuccessorsWithinSlice((size / 2) - 1, false);
}

@Override
public HashMap<? extends PuzzleState, String> getCanonicalMovesByState() {
HashMap<PuzzleState, String> reversed = new HashMap<PuzzleState, String>();
public Map<? extends PuzzleState, String> getCanonicalMovesByState() {
Map<PuzzleState, String> reversed = new HashMap<>();

for (Map.Entry<String, ? extends PuzzleState> entry : getScrambleSuccessors().entrySet()) {
reversed.put(entry.getValue(), entry.getKey());
Expand All @@ -529,8 +529,8 @@ public HashMap<? extends PuzzleState, String> getCanonicalMovesByState() {
return reversed;
}

private LinkedHashMap<String, CubeState> getSuccessorsWithinSlice(int maxSlice, boolean includeRedundant) {
LinkedHashMap<String, CubeState> successors = new LinkedHashMap<String, CubeState>();
private Map<String, CubeState> getSuccessorsWithinSlice(int maxSlice, boolean includeRedundant) {
Map<String, CubeState> successors = new LinkedHashMap<>();
for(int innerSlice = 0; innerSlice <= maxSlice; innerSlice++) {
for(Face face : Face.values()) {
boolean halfOfEvenCube = size % 2 == 0 && (innerSlice == (size / 2) - 1);
Expand Down Expand Up @@ -569,7 +569,7 @@ public int hashCode() {
return Arrays.deepHashCode(image);
}

protected Svg drawScramble(HashMap<String, Color> colorScheme) {
protected Svg drawScramble(Map<String, Color> colorScheme) {
Svg svg = new Svg(getPreferredSize());
drawCube(svg, image, gap, cubieSize, colorScheme);
return svg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.Random;

import cs.threephase.Edge3;
import cs.threephase.Search;
import org.worldcubeassociation.tnoodle.scrambles.AlgorithmBuilder;
import org.worldcubeassociation.tnoodle.scrambles.AlgorithmBuilder.MergingMode;
import org.worldcubeassociation.tnoodle.scrambles.InvalidMoveException;
Expand All @@ -11,19 +13,15 @@

@Export
public class FourByFourCubePuzzle extends CubePuzzle {
private ThreadLocal<cs.threephase.Search> threePhaseSearcher = null;
private final ThreadLocal<Search> threePhaseSearcher;

public FourByFourCubePuzzle() {
super(4);
threePhaseSearcher = new ThreadLocal<cs.threephase.Search>() {
protected cs.threephase.Search initialValue() {
return new cs.threephase.Search();
};
};
threePhaseSearcher = ThreadLocal.withInitial(Search::new);
}

public double getInitializationStatus() {
return cs.threephase.Edge3.initStatus();
return Edge3.initStatus();
}

@Override
Expand Down
Loading

0 comments on commit ac66e33

Please sign in to comment.