mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-27 02:01:40 +00:00
Use toList instead of collect(Collectors.toList()) when the list is definitely never modified
This commit is contained in:
@@ -32,7 +32,6 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
import org.photonvision.common.logging.Logger;
|
||||
import org.photonvision.common.util.file.FileUtils;
|
||||
@@ -280,9 +279,7 @@ class LegacyConfigProvider extends ConfigProvider {
|
||||
HashMap<String, CameraConfiguration> loadedConfigurations = new HashMap<>();
|
||||
try {
|
||||
var subdirectories =
|
||||
Files.list(camerasFolder.toPath())
|
||||
.filter(f -> f.toFile().isDirectory())
|
||||
.collect(Collectors.toList());
|
||||
Files.list(camerasFolder.toPath()).filter(f -> f.toFile().isDirectory()).toList();
|
||||
|
||||
for (var subdir : subdirectories) {
|
||||
var cameraConfigPath = Path.of(subdir.toString(), "config.json");
|
||||
@@ -348,7 +345,7 @@ class LegacyConfigProvider extends ConfigProvider {
|
||||
return null;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList())
|
||||
.toList()
|
||||
: Collections.emptyList();
|
||||
|
||||
loadedConfig.driveModeSettings = driverMode;
|
||||
|
||||
@@ -398,7 +398,7 @@ public class SqlConfigProvider extends ConfigProvider {
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
statement.setString(4, JacksonUtils.serializeToString(settings));
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.photonvision.common.dataflow.websocket;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.photonvision.PhotonVersion;
|
||||
import org.photonvision.common.configuration.NeuralNetworkModelManager;
|
||||
import org.photonvision.common.configuration.PhotonConfiguration;
|
||||
@@ -64,6 +63,6 @@ public class UIPhotonConfiguration {
|
||||
c.getApriltagFieldLayout()),
|
||||
VisionSourceManager.getInstance().getVisionModules().stream()
|
||||
.map(VisionModule::toUICameraConfig)
|
||||
.collect(Collectors.toList()));
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import org.photonvision.common.hardware.Platform;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
import org.photonvision.common.logging.Logger;
|
||||
@@ -108,24 +107,35 @@ public class NetworkUtils {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an immutable list of active network interfaces.
|
||||
*
|
||||
* @return The list.
|
||||
*/
|
||||
public static List<NMDeviceInfo> getAllActiveInterfaces() {
|
||||
// Seems like if an interface exists but isn't actually connected, the connection name will be
|
||||
// an empty string. Check here and only return connections with non-empty names
|
||||
return getAllInterfaces().stream()
|
||||
.filter(it -> !it.connName.trim().isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
return getAllInterfaces().stream().filter(it -> !it.connName.trim().isEmpty()).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an immutable list of all wired network interfaces.
|
||||
*
|
||||
* @return The list.
|
||||
*/
|
||||
public static List<NMDeviceInfo> getAllWiredInterfaces() {
|
||||
return getAllInterfaces().stream()
|
||||
.filter(it -> it.nmType.equals(NMType.NMTYPE_ETHERNET))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an immutable list of all wired and active network interfaces.
|
||||
*
|
||||
* @return The list.
|
||||
*/
|
||||
public static List<NMDeviceInfo> getAllActiveWiredInterfaces() {
|
||||
return getAllWiredInterfaces().stream()
|
||||
.filter(it -> !it.connName.isBlank())
|
||||
.collect(Collectors.toList());
|
||||
return getAllWiredInterfaces().stream().filter(it -> !it.connName.isBlank()).toList();
|
||||
}
|
||||
|
||||
public static NMDeviceInfo getNMinfoForConnName(String connName) {
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.awt.HeadlessException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Collectors;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.highgui.HighGui;
|
||||
import org.photonvision.jni.WpilibLoader;
|
||||
@@ -386,9 +385,7 @@ public class TestUtils {
|
||||
printTestResults(pipelineResult);
|
||||
System.out.println(
|
||||
"Found targets at "
|
||||
+ pipelineResult.targets.stream()
|
||||
.map(TrackedTarget::getBestCameraToTarget3d)
|
||||
.collect(Collectors.toList()));
|
||||
+ pipelineResult.targets.stream().map(TrackedTarget::getBestCameraToTarget3d).toList());
|
||||
}
|
||||
|
||||
public static Path getTestMode2023ImagePath() {
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
package org.photonvision.vision.calibration;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.opencv.core.Size;
|
||||
|
||||
public class UICameraCalibrationCoefficients extends CameraCalibrationCoefficients {
|
||||
public int numSnapshots;
|
||||
|
||||
/** Immutable list of mean errors. */
|
||||
public List<Double> meanErrors;
|
||||
|
||||
public UICameraCalibrationCoefficients(
|
||||
@@ -54,6 +55,6 @@ public class UICameraCalibrationCoefficients extends CameraCalibrationCoefficien
|
||||
.mapToDouble(it -> Math.sqrt(it.x * it.x + it.y * it.y))
|
||||
.average()
|
||||
.orElse(0))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,9 @@ import edu.wpi.first.math.MathUtil;
|
||||
import edu.wpi.first.util.PixelFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import org.photonvision.common.configuration.CameraConfiguration;
|
||||
import org.photonvision.vision.camera.CameraQuirk;
|
||||
import org.photonvision.vision.processes.VisionSourceSettables;
|
||||
@@ -301,9 +299,8 @@ public class GenericUSBCameraSettables extends VisionSourceSettables {
|
||||
var sortedList =
|
||||
videoModesList.stream()
|
||||
.distinct() // remove redundant video mode entries
|
||||
.sorted(((a, b) -> (b.width + b.height) - (a.width + a.height)))
|
||||
.collect(Collectors.toList());
|
||||
Collections.reverse(sortedList);
|
||||
.sorted(((a, b) -> (a.width + a.height) - (b.width + b.height)))
|
||||
.toList();
|
||||
|
||||
for (VideoMode videoMode : sortedList) {
|
||||
videoModes.put(sortedList.indexOf(videoMode), videoMode);
|
||||
|
||||
@@ -89,7 +89,7 @@ public class Calibrate3dPipe
|
||||
&& it.imagePoints != null
|
||||
&& it.objectPoints != null
|
||||
&& it.size != null)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
CameraCalibrationCoefficients ret;
|
||||
var start = System.nanoTime();
|
||||
@@ -134,11 +134,9 @@ public class Calibrate3dPipe
|
||||
double fxGuess,
|
||||
double fyGuess,
|
||||
Path imageSavePath) {
|
||||
List<MatOfPoint3f> objPointsIn =
|
||||
in.stream().map(it -> it.objectPoints).collect(Collectors.toList());
|
||||
List<MatOfPoint2f> imgPointsIn =
|
||||
in.stream().map(it -> it.imagePoints).collect(Collectors.toList());
|
||||
List<MatOfFloat> levelsArr = in.stream().map(it -> it.levels).collect(Collectors.toList());
|
||||
List<MatOfPoint3f> objPointsIn = in.stream().map(it -> it.objectPoints).toList();
|
||||
List<MatOfPoint2f> imgPointsIn = in.stream().map(it -> it.imagePoints).toList();
|
||||
List<MatOfFloat> levelsArr = in.stream().map(it -> it.levels).toList();
|
||||
|
||||
if (objPointsIn.size() != imgPointsIn.size() || objPointsIn.size() != levelsArr.size()) {
|
||||
logger.error("objpts.size != imgpts.size");
|
||||
@@ -223,10 +221,9 @@ public class Calibrate3dPipe
|
||||
double fyGuess,
|
||||
Path imageSavePath) {
|
||||
List<MatOfPoint2f> corner_locations =
|
||||
in.stream().map(it -> it.imagePoints).map(MatOfPoint2f::new).collect(Collectors.toList());
|
||||
in.stream().map(it -> it.imagePoints).map(MatOfPoint2f::new).toList();
|
||||
|
||||
List<MatOfFloat> levels =
|
||||
in.stream().map(it -> it.levels).map(MatOfFloat::new).collect(Collectors.toList());
|
||||
List<MatOfFloat> levels = in.stream().map(it -> it.levels).map(MatOfFloat::new).toList();
|
||||
|
||||
int imageWidth = (int) in.get(0).size.width;
|
||||
int imageHeight = (int) in.get(0).size.height;
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.photonvision.vision.pipe.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfPoint;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
@@ -40,7 +39,7 @@ public class FindContoursPipe
|
||||
Imgproc.findContours(
|
||||
in, m_foundContours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_TC89_KCOS);
|
||||
|
||||
return m_foundContours.stream().map(Contour::new).collect(Collectors.toList());
|
||||
return m_foundContours.stream().map(Contour::new).toList();
|
||||
}
|
||||
|
||||
public static class FindContoursParams {}
|
||||
|
||||
@@ -22,7 +22,6 @@ import edu.wpi.first.math.util.Units;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.photonvision.common.dataflow.DataChangeService;
|
||||
@@ -166,9 +165,7 @@ public class Calibrate3dPipeline
|
||||
}
|
||||
|
||||
List<List<Point>> getCornersList() {
|
||||
return foundCornersList.stream()
|
||||
.map(it -> it.imagePoints.toList())
|
||||
.collect(Collectors.toList());
|
||||
return foundCornersList.stream().map(it -> it.imagePoints.toList()).toList();
|
||||
}
|
||||
|
||||
public boolean hasEnough() {
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.photonvision.vision.pipeline;
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.opencv.core.Point;
|
||||
import org.photonvision.vision.frame.Frame;
|
||||
import org.photonvision.vision.frame.FrameThresholdType;
|
||||
@@ -199,7 +198,7 @@ public class ColoredShapePipeline
|
||||
sortContoursPipe.run(
|
||||
filterShapeResult.output.stream()
|
||||
.map(shape -> new PotentialTarget(shape.getContour(), shape))
|
||||
.collect(Collectors.toList()));
|
||||
.toList());
|
||||
sumPipeNanosElapsed += sortContoursResult.nanosElapsed;
|
||||
|
||||
CVPipeResult<List<TrackedTarget>> collect2dTargetsResult =
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.photonvision.vision.pipeline;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import org.photonvision.common.configuration.NeuralNetworkModelManager;
|
||||
import org.photonvision.vision.frame.Frame;
|
||||
import org.photonvision.vision.frame.FrameThresholdType;
|
||||
@@ -127,9 +126,7 @@ public class ObjectDetectionPipeline
|
||||
|
||||
CVPipeResult<List<PotentialTarget>> sortContoursResult =
|
||||
sortContoursPipe.run(
|
||||
filterContoursResult.output.stream()
|
||||
.map(shape -> new PotentialTarget(shape))
|
||||
.collect(Collectors.toList()));
|
||||
filterContoursResult.output.stream().map(shape -> new PotentialTarget(shape)).toList());
|
||||
sumPipeNanosElapsed += sortContoursResult.nanosElapsed;
|
||||
|
||||
CVPipeResult<List<TrackedTarget>> collect2dTargetsResult =
|
||||
|
||||
@@ -18,14 +18,13 @@
|
||||
package org.photonvision.vision.pipeline.result;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.opencv.core.Point;
|
||||
import org.photonvision.vision.frame.Frame;
|
||||
import org.photonvision.vision.target.TrackedTarget;
|
||||
|
||||
public class CalibrationPipelineResult extends CVPipelineResult {
|
||||
private static List<TrackedTarget> cornersToTarget(List<List<Point>> corners) {
|
||||
return corners.stream().map(TrackedTarget::new).collect(Collectors.toList());
|
||||
return corners.stream().map(TrackedTarget::new).toList();
|
||||
}
|
||||
|
||||
public CalibrationPipelineResult(
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.photonvision.vision.processes;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
import org.photonvision.common.logging.Logger;
|
||||
|
||||
@@ -67,9 +66,7 @@ public class VisionModuleManager {
|
||||
// Big list, which should contain every vision source (currently loaded plus the new ones being
|
||||
// added)
|
||||
List<Integer> bigList =
|
||||
this.getModules().stream()
|
||||
.map(it -> it.getCameraConfiguration().streamIndex)
|
||||
.collect(Collectors.toList());
|
||||
this.getModules().stream().map(it -> it.getCameraConfiguration().streamIndex).toList();
|
||||
|
||||
int idx = 0;
|
||||
while (bigList.contains(idx)) {
|
||||
|
||||
@@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -151,13 +150,13 @@ public class CalibrationRotationPipeTest {
|
||||
var rotatedDistortedPoints =
|
||||
distortedOriginalPoints.stream()
|
||||
.map(it -> rot.rotatePoint(it, frameProps.imageWidth, frameProps.imageHeight))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
// Now let's instead rotate then distort
|
||||
var rotatedOriginalPoints =
|
||||
Arrays.stream(originalPoints)
|
||||
.map(it -> rot.rotatePoint(it, frameProps.imageWidth, frameProps.imageHeight))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
var distortedRotatedPoints =
|
||||
OpenCVHelp.distortPoints(
|
||||
@@ -310,9 +309,7 @@ public class CalibrationRotationPipeTest {
|
||||
// rotate and try again
|
||||
var rotAngle = ImageRotationMode.DEG_90_CCW;
|
||||
var rotatedDistortedPoints =
|
||||
distortedCorners.stream()
|
||||
.map(it -> rotAngle.rotatePoint(it, 1280, 720))
|
||||
.collect(Collectors.toList());
|
||||
distortedCorners.stream().map(it -> rotAngle.rotatePoint(it, 1280, 720)).toList();
|
||||
pipe.setParams(
|
||||
new SolvePNPPipeParams(
|
||||
coeffs.rotateCoefficients(rotAngle), TargetModel.kAprilTag6p5in_36h11));
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -233,15 +232,12 @@ public class VisionModuleManagerTest {
|
||||
var modules =
|
||||
List.of(testSource, testSource2, testSource3, usbSimulation, usbSimulation2).stream()
|
||||
.map(vmm::addSource)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
System.out.println(
|
||||
Arrays.toString(
|
||||
modules.stream().map(it -> it.getCameraConfiguration().streamIndex).toArray()));
|
||||
var idxs =
|
||||
modules.stream()
|
||||
.map(it -> it.getCameraConfiguration().streamIndex)
|
||||
.collect(Collectors.toList());
|
||||
var idxs = modules.stream().map(it -> it.getCameraConfiguration().streamIndex).toList();
|
||||
|
||||
assertTrue(usbSimulation.equals(usbSimulation));
|
||||
assertTrue(!usbSimulation.equals(usbSimulation2));
|
||||
|
||||
@@ -50,7 +50,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import org.opencv.core.Core;
|
||||
import org.photonvision.common.hardware.VisionLEDMode;
|
||||
import org.photonvision.common.networktables.PacketSubscriber;
|
||||
@@ -594,6 +593,6 @@ public class PhotonCamera implements AutoCloseable {
|
||||
it -> {
|
||||
return rootPhotonTable.getSubTable(it).getEntry("rawBytes").exists();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.photonvision.PhotonCamera;
|
||||
import org.photonvision.estimation.TargetModel;
|
||||
|
||||
@@ -357,10 +356,7 @@ public class VisionSystemSim {
|
||||
entry ->
|
||||
dbgField
|
||||
.getObject(entry.getKey())
|
||||
.setPoses(
|
||||
entry.getValue().stream()
|
||||
.map(t -> t.getPose().toPose2d())
|
||||
.collect(Collectors.toList())));
|
||||
.setPoses(entry.getValue().stream().map(t -> t.getPose().toPose2d()).toList()));
|
||||
|
||||
if (robotPoseMeters == null) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user