diff --git a/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NTDataPublisher.java b/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NTDataPublisher.java index 0e3f43b075..8b67ae7cd9 100644 --- a/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NTDataPublisher.java +++ b/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NTDataPublisher.java @@ -181,15 +181,13 @@ public void accept(CVPipelineResult result) { } // Something in the result can sometimes be null -- so check probably too many things - if (result != null - && result.inputAndOutputFrame != null + if ( + result.inputAndOutputFrame != null && result.inputAndOutputFrame.frameStaticProperties != null && result.inputAndOutputFrame.frameStaticProperties.cameraCalibration != null) { var fsp = result.inputAndOutputFrame.frameStaticProperties; - if (fsp.cameraCalibration != null) { - ts.cameraIntrinsicsPublisher.accept(fsp.cameraCalibration.getIntrinsicsArr()); - ts.cameraDistortionPublisher.accept(fsp.cameraCalibration.getExtrinsicsArr()); - } + ts.cameraIntrinsicsPublisher.accept(fsp.cameraCalibration.getIntrinsicsArr()); + ts.cameraDistortionPublisher.accept(fsp.cameraCalibration.getExtrinsicsArr()); } else { ts.cameraIntrinsicsPublisher.accept(new double[] {}); ts.cameraDistortionPublisher.accept(new double[] {}); @@ -215,8 +213,11 @@ public static List simpleFromTrackedTargets(List { - logger.error("TimedTask threw uncaught exception!", e); - }); + (t, e) -> logger.error("TimedTask threw uncaught exception!", e)); return thread; } } diff --git a/photon-core/src/main/java/org/photonvision/vision/aruco/PhotonArucoDetector.java b/photon-core/src/main/java/org/photonvision/vision/aruco/PhotonArucoDetector.java index b04418059a..e4333d54e3 100644 --- a/photon-core/src/main/java/org/photonvision/vision/aruco/PhotonArucoDetector.java +++ b/photon-core/src/main/java/org/photonvision/vision/aruco/PhotonArucoDetector.java @@ -58,7 +58,7 @@ public PhotonArucoDetector() { ids = new Mat(); tvecs = new Mat(); rvecs = new Mat(); - corners = new ArrayList(); + corners = new ArrayList<>(); tagPose = new Pose3d(); translation = new Translation3d(); rotation = new Rotation3d(); diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/QuirkyCamera.java b/photon-core/src/main/java/org/photonvision/vision/camera/QuirkyCamera.java index 780a12786e..da2dc835cb 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/QuirkyCamera.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/QuirkyCamera.java @@ -105,7 +105,7 @@ public static QuirkyCamera getQuirkyCamera(int usbVid, int usbPid) { public static QuirkyCamera getQuirkyCamera(int usbVid, int usbPid, String baseName) { for (var qc : quirkyCameras) { - boolean hasBaseName = !qc.baseName.equals(""); + boolean hasBaseName = !qc.baseName.isEmpty(); boolean matchesBaseName = qc.baseName.equals(baseName) || !hasBaseName; if (qc.usbVid == usbVid && qc.usbPid == usbPid && matchesBaseName) { return qc; diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameraSource.java b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameraSource.java index 18d25390b1..b456985e0e 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameraSource.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameraSource.java @@ -266,12 +266,9 @@ public HashMap getAllVideoModes() { } else { modes = camera.enumerateVideoModes(); } - for (int i = 0; i < modes.length; i++) { - var videoMode = modes[i]; - + for (VideoMode videoMode : modes) { // Filter grey modes - if (videoMode.pixelFormat == VideoMode.PixelFormat.kGray - || videoMode.pixelFormat == VideoMode.PixelFormat.kUnknown) { + if (videoMode.pixelFormat == VideoMode.PixelFormat.kGray || videoMode.pixelFormat == VideoMode.PixelFormat.kUnknown) { continue; } diff --git a/photon-core/src/main/java/org/photonvision/vision/frame/provider/CpuImageProcessor.java b/photon-core/src/main/java/org/photonvision/vision/frame/provider/CpuImageProcessor.java index 9a88b82f2e..034ae6615e 100644 --- a/photon-core/src/main/java/org/photonvision/vision/frame/provider/CpuImageProcessor.java +++ b/photon-core/src/main/java/org/photonvision/vision/frame/provider/CpuImageProcessor.java @@ -30,7 +30,7 @@ import org.photonvision.vision.pipe.impl.RotateImagePipe; public abstract class CpuImageProcessor implements FrameProvider { - protected class CapturedFrame { + protected static class CapturedFrame { CVMat colorImage; FrameStaticProperties staticProps; long captureTimestamp; diff --git a/photon-core/src/main/java/org/photonvision/vision/frame/provider/FileFrameProvider.java b/photon-core/src/main/java/org/photonvision/vision/frame/provider/FileFrameProvider.java index 315e4e3de3..2514bbaabd 100644 --- a/photon-core/src/main/java/org/photonvision/vision/frame/provider/FileFrameProvider.java +++ b/photon-core/src/main/java/org/photonvision/vision/frame/provider/FileFrameProvider.java @@ -111,7 +111,11 @@ public CapturedFrame getInputMat() { } lastGetMillis = System.currentTimeMillis(); - return new CapturedFrame(out, properties, MathUtils.wpiNanoTime()); + return new CapturedFrame( + out, + properties, + MathUtils.wpiNanoTime() + ); } @Override diff --git a/photon-core/src/main/java/org/photonvision/vision/frame/provider/USBFrameProvider.java b/photon-core/src/main/java/org/photonvision/vision/frame/provider/USBFrameProvider.java index 03459c197d..20770fdd4f 100644 --- a/photon-core/src/main/java/org/photonvision/vision/frame/provider/USBFrameProvider.java +++ b/photon-core/src/main/java/org/photonvision/vision/frame/provider/USBFrameProvider.java @@ -48,7 +48,11 @@ public CapturedFrame getInputMat() { time = MathUtils.wpiNanoTime(); } - return new CapturedFrame(mat, settables.getFrameStaticProperties(), time); + return new CapturedFrame( + mat, + settables.getFrameStaticProperties(), + time + ); } @Override diff --git a/photon-core/src/main/java/org/photonvision/vision/processes/PipelineManager.java b/photon-core/src/main/java/org/photonvision/vision/processes/PipelineManager.java index 4ac70a14e3..fa3ce21c2f 100644 --- a/photon-core/src/main/java/org/photonvision/vision/processes/PipelineManager.java +++ b/photon-core/src/main/java/org/photonvision/vision/processes/PipelineManager.java @@ -375,31 +375,34 @@ public int duplicatePipeline(int index) { private static String createUniqueName( String nickname, List existingSettings) { - String uniqueName = nickname; + StringBuilder uniqueName = new StringBuilder(nickname); while (true) { - String finalUniqueName = uniqueName; // To get around lambda capture + String finalUniqueName = uniqueName.toString(); // To get around lambda capture var conflictingName = existingSettings.stream().anyMatch(it -> it.pipelineNickname.equals(finalUniqueName)); if (!conflictingName) { // If no conflict, we're done - return uniqueName; + return uniqueName.toString(); } else { // Otherwise, we need to add a suffix to the name // If the string doesn't already end in "([0-9]*)", we'll add it // If it does, we'll increment the number in the suffix - if (uniqueName.matches(".*\\([0-9]*\\)")) { + if (uniqueName.toString().matches(".*\\([0-9]*\\)")) { // Because java strings are immutable, we have to do this curstedness // This is like doing "New pipeline (" + 2 + ")" - var parenStart = uniqueName.lastIndexOf('('); + var parenStart = uniqueName.toString().lastIndexOf('('); var parenEnd = uniqueName.length() - 1; var number = Integer.parseInt(uniqueName.substring(parenStart + 1, parenEnd)) + 1; - uniqueName = uniqueName.substring(0, parenStart + 1) + number + ")"; + uniqueName = new StringBuilder(uniqueName.substring( + 0, + parenStart + 1 + ) + number + ")"); } else { - uniqueName += " (1)"; + uniqueName.append(" (1)"); } } } diff --git a/photon-core/src/main/java/org/photonvision/vision/videoStream/SocketVideoStreamManager.java b/photon-core/src/main/java/org/photonvision/vision/videoStream/SocketVideoStreamManager.java index 80aa9cef1f..463e13c13e 100644 --- a/photon-core/src/main/java/org/photonvision/vision/videoStream/SocketVideoStreamManager.java +++ b/photon-core/src/main/java/org/photonvision/vision/videoStream/SocketVideoStreamManager.java @@ -29,8 +29,8 @@ public class SocketVideoStreamManager { private final Logger logger = new Logger(SocketVideoStreamManager.class, LogGroup.Camera); - private final Map streams = new Hashtable(); - private final Map userSubscriptions = new Hashtable(); + private final Map streams = new Hashtable<>(); + private final Map userSubscriptions = new Hashtable<>(); private static class ThreadSafeSingleton { private static final SocketVideoStreamManager INSTANCE = new SocketVideoStreamManager(); diff --git a/photon-core/src/test/java/org/photonvision/common/util/LogFileManagementTest.java b/photon-core/src/test/java/org/photonvision/common/util/LogFileManagementTest.java index bcbb0a09c8..caa8edaa5c 100644 --- a/photon-core/src/test/java/org/photonvision/common/util/LogFileManagementTest.java +++ b/photon-core/src/test/java/org/photonvision/common/util/LogFileManagementTest.java @@ -66,8 +66,9 @@ public void fileCleanupTest() { Logger.cleanLogs(Path.of(testDir)); // Confirm we deleted log files - Assertions.assertTrue( - Logger.MAX_LOGS_TO_KEEP == countLogFiles(testDir), + Assertions.assertEquals( + Logger.MAX_LOGS_TO_KEEP, + countLogFiles(testDir), "Not enough log files deleted" );