Skip to content

Commit

Permalink
[photon-core] [NFC] Code Cleanup, spelling, and grammar (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
srimanachanta authored Oct 15, 2023
1 parent 9991f86 commit 760de0f
Show file tree
Hide file tree
Showing 81 changed files with 261 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.Date;
import java.util.List;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.file.FileUtils;
Expand All @@ -47,13 +48,13 @@ public class ConfigManager {

private final ConfigProvider m_provider;

private Thread settingsSaveThread;
private final Thread settingsSaveThread;
private long saveRequestTimestamp = -1;

enum ConfigSaveStrategy {
SQL,
LEGACY,
ATOMIC_ZIP;
ATOMIC_ZIP
}

// This logic decides which kind of ConfigManager we load as the default. If we want
Expand Down Expand Up @@ -115,9 +116,8 @@ private void translateLegacyIfPresent(Path folderPath) {
e1.printStackTrace();
}

// So we can't save the old config, and we couldn't copy the folder
// But we've loaded the config. So just try to delete the directory so we don't try to load
// form it next time. That does mean we have no backup recourse, tho
// Delete the directory because we were successfully able to load the config but were unable
// to save or copy the folder.
if (maybeCams.exists()) FileUtils.deleteDirectory(maybeCams.toPath());
}

Expand Down Expand Up @@ -225,7 +225,7 @@ public String taToLogFname(TemporalAccessor date) {
}

public Date logFnameToDate(String fname) throws ParseException {
// Strip away known unneded portions of the log file name
// Strip away known unneeded portions of the log file name
fname = fname.replace(LOG_PREFIX, "").replace(LOG_EXT, "");
DateFormat format = new SimpleDateFormat(LOG_DATE_TIME_FORMAT);
return format.parse(fname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LegacyConfigProvider extends ConfigProvider {
final File configDirectoryFile;

private long saveRequestTimestamp = -1;
private Thread settingsSaveThread;
private final Thread settingsSaveThread;

public static void saveUploadedSettingsZip(File uploadPath) {
var folderPath = Path.of(System.getProperty("java.io.tmpdir"), "photonvision").toFile();
Expand All @@ -67,7 +67,6 @@ public static void saveUploadedSettingsZip(File uploadPath) {
logger.info("Copied settings successfully!");
} catch (IOException e) {
logger.error("Exception copying uploaded settings!", e);
return;
}
}

Expand Down Expand Up @@ -371,7 +370,7 @@ public String taToLogFname(TemporalAccessor date) {
}

public Date logFnameToDate(String fname) throws ParseException {
// Strip away known unneded portions of the log file name
// Strip away known unneeded portions of the log file name
fname = fname.replace(LOG_PREFIX, "").replace(LOG_EXT, "");
DateFormat format = new SimpleDateFormat(LOG_DATE_TIME_FORMAT);
return format.parse(fname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.photonvision.common.util.file.JacksonUtils;

public class NetworkConfig {
// Can be a integer team number, or a IP address
// Can be an integer team number, or an IP address
public String ntServerAddress = "0";
public NetworkMode connectionType = NetworkMode.DHCP;
public String staticIp = "";
Expand Down Expand Up @@ -58,7 +58,7 @@ public NetworkConfig() {
.orElse("Wired connection 1");
}

// We can (usually) manage networking on Linux devices, and if we can we should try to. Command
// We can (usually) manage networking on Linux devices, and if we can, we should try to. Command
// line inhibitions happen at a level above this class
setShouldManage(deviceCanManageNetwork());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@

// TODO rename this class
public class PhotonConfiguration {
private HardwareConfig hardwareConfig;
private HardwareSettings hardwareSettings;
private final HardwareConfig hardwareConfig;
private final HardwareSettings hardwareSettings;
private NetworkConfig networkConfig;
private HashMap<String, CameraConfiguration> cameraConfigurations;
private final HashMap<String, CameraConfiguration> cameraConfigurations;

public PhotonConfiguration(
HardwareConfig hardwareConfig,
Expand Down Expand Up @@ -113,7 +113,7 @@ public Map<String, Object> toHashMap() {

var lightingConfig = new UILightingConfig();
lightingConfig.brightness = hardwareSettings.ledBrightnessPercentage;
lightingConfig.supported = (hardwareConfig.ledPins.size() != 0);
lightingConfig.supported = !hardwareConfig.ledPins.isEmpty();
settingsSubmap.put("lighting", SerializationUtils.objectToHashMap(lightingConfig));

var generalSubmap = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -255,8 +251,7 @@ private String getOneConfigFile(Connection conn, String filename) {
var result = query.executeQuery();

while (result.next()) {
var contents = result.getString("contents");
return contents;
return result.getString("contents");
}
} catch (SQLException e) {
logger.error("SQL Err getting file " + filename, e);
Expand Down Expand Up @@ -286,7 +281,7 @@ private void saveCameras(Connection conn) {
statement.setString(2, JacksonUtils.serializeToString(config));
statement.setString(3, JacksonUtils.serializeToString(config.driveModeSettings));

// Serializing a list of abstract classes sucks. Instead, make it into a array
// Serializing a list of abstract classes sucks. Instead, make it into an array
// of strings, which we can later unpack back into individual settings
List<String> settings =
config.pipelineSettings.stream()
Expand Down Expand Up @@ -424,7 +419,7 @@ public boolean saveUploadedNetworkConfig(Path uploadPath) {
private HashMap<String, CameraConfiguration> loadCameraConfigs(Connection conn) {
HashMap<String, CameraConfiguration> loadedConfigurations = new HashMap<>();

// Querry every single row of the cameras db
// Query every single row of the cameras db
PreparedStatement query = null;
try {
query =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Objects;
import org.photonvision.common.dataflow.events.DataChangeEvent;

@SuppressWarnings("rawtypes")
public abstract class DataChangeSubscriber {
public final List<DataChangeSource> wantedSources;
public final List<DataChangeDestination> wantedDestinations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class NTDataPublisher implements CVPipelineResultConsumer {

private final NetworkTable rootTable = NetworkTablesManager.getInstance().kRootTable;

private NTTopicSet ts = new NTTopicSet();
private final NTTopicSet ts = new NTTopicSet();

NTDataChangeListener pipelineIndexListener;
private final Supplier<Integer> pipelineIndexSupplier;
Expand Down Expand Up @@ -181,15 +181,12 @@ 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[] {});
Expand All @@ -215,8 +212,8 @@ public static List<PhotonTrackedTarget> simpleFromTrackedTargets(List<TrackedTar
}
{
var points = t.getTargetCorners();
for (int i = 0; i < points.size(); i++) {
detectedCorners.add(new TargetCorner(points.get(i).x, points.get(i).y));
for (Point point : points) {
detectedCorners.add(new TargetCorner(point.x, point.y));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void setClientMode(String ntServerAddress) {
ntInstance.stopServer();
ntInstance.startClient4("photonvision");
try {
Integer t = Integer.parseInt(ntServerAddress);
int t = Integer.parseInt(ntServerAddress);
if (!isRetryingConnection) logger.info("Starting NT Client, server team is " + t);
ntInstance.setServerTeam(t);
} catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.photonvision.common.hardware.GPIO.pi;

import static org.photonvision.common.hardware.GPIO.pi.PigpioException.*;

import org.photonvision.common.hardware.GPIO.GPIOBase;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.photonvision.common.hardware.GPIO.pi;

import static org.photonvision.common.hardware.GPIO.pi.PigpioException.*;
import static org.photonvision.common.hardware.GPIO.pi.PigpioException.PI_NO_WAVEFORM_ID;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -149,7 +148,7 @@ private int waveAddGeneric(ArrayList<PigpioPulse> pulses) throws PigpioException
// ## extension ##
// III on/off/delay * pulses

if (pulses == null || pulses.size() == 0) return 0;
if (pulses == null || pulses.isEmpty()) return 0;

try {
ByteBuffer bb = ByteBuffer.allocate(pulses.size() * 12);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public class HardwareManager {
private final StatusLED statusLED;

@SuppressWarnings("FieldCanBeLocal")
private IntegerSubscriber ledModeRequest;
private final IntegerSubscriber ledModeRequest;

private IntegerPublisher ledModeState;
private final IntegerPublisher ledModeState;

@SuppressWarnings({"FieldCanBeLocal", "unused"})
private final NTDataChangeListener ledModeListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum PiVersion {
private static final ShellExec shell = new ShellExec(true, false);
private static final PiVersion currentPiVersion = calcPiVersion();

private PiVersion(String s) {
PiVersion(String s) {
this.identifier = s.toLowerCase();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.photonvision.common.hardware;

import com.jogamp.common.os.Platform.OSType;
import edu.wpi.first.util.RuntimeDetector;
import java.io.BufferedReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class VisionLED {

private int mappedBrightnessPercentage;

private Consumer<Integer> modeConsumer;
private final Consumer<Integer> modeConsumer;

public VisionLED(
List<Integer> ledPins,
Expand Down Expand Up @@ -179,11 +179,7 @@ private void setInternal(VisionLEDMode newLedMode, boolean fromNT) {
}
currentLedMode = newLedMode;
logger.info(
"Changing LED mode from \""
+ lastLedMode.toString()
+ "\" to \""
+ newLedMode.toString()
+ "\"");
"Changing LED mode from \"" + lastLedMode.toString() + "\" to \"" + newLedMode + "\"");
} else {
if (currentLedMode == VisionLEDMode.kDefault) {
switch (newLedMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MetricsManager {

CmdBase cmds;

private ShellExec runCommand = new ShellExec(true, true);
private final ShellExec runCommand = new ShellExec(true, true);

public void setConfig(HardwareConfig config) {
if (config.hasCommandsConfigured()) {
Expand Down Expand Up @@ -153,8 +153,8 @@ public synchronized String execute(String command) {
+ "\nExit code: "
+ runCommand.getExitCode()
+ "\n Exception: "
+ e.toString()
+ sw.toString());
+ e
+ sw);
return "";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public class CmdBase {
public String diskUsageCommand = "";

public void initCmds(HardwareConfig config) {
return; // default - do nothing
// default - do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@
import java.nio.file.Path;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.function.Supplier;
import org.apache.commons.lang3.tuple.Pair;
import org.photonvision.common.configuration.ConfigManager;
Expand Down Expand Up @@ -54,7 +49,7 @@ public class Logger {
private static final List<Pair<String, LogLevel>> uiBacklog = new ArrayList<>();
private static boolean connected = false;

private static UILogAppender uiLogAppender = new UILogAppender();
private static final UILogAppender uiLogAppender = new UILogAppender();

private final String className;
private final LogGroup group;
Expand Down Expand Up @@ -133,7 +128,7 @@ public static void cleanLogs(Path folderToClean) {
HashMap<File, Date> logFileStartDateMap = new HashMap<>();

// Remove any files from the list for which we can't parse a start date from their name.
// Simultaneously populate our HashMap with Date objects repeseting the file-name
// Simultaneously populate our HashMap with Date objects representing the file-name
// indicated log start time.
logFileList.removeIf(
(File arg0) -> {
Expand All @@ -160,7 +155,6 @@ public static void cleanLogs(Path folderToClean) {
if (logCounter < MAX_LOGS_TO_KEEP) {
// Skip over the first MAX_LOGS_TO_KEEP files
logCounter++;
continue;
} else {
// Delete this file.
file.delete();
Expand Down Expand Up @@ -332,7 +326,7 @@ public FileLogAppender(Path logFilePath) {
3000L);
} catch (FileNotFoundException e) {
out = null;
System.err.println("Unable to log to file " + logFilePath.toString());
System.err.println("Unable to log to file " + logFilePath);
}
}

Expand Down
Loading

0 comments on commit 760de0f

Please sign in to comment.