mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[build] Apply spotless for java formatting (#1768)
Update checkstyle config to be compatible with spotless. Co-authored-by: Austin Shalit <austinshalit@gmail.com>
This commit is contained in:
@@ -4,9 +4,7 @@
|
||||
|
||||
package edu.wpi.first.wpiutil;
|
||||
|
||||
/**
|
||||
* This is a simple circular buffer so we don't need to "bucket brigade" copy old values.
|
||||
*/
|
||||
/** This is a simple circular buffer so we don't need to "bucket brigade" copy old values. */
|
||||
public class CircularBuffer {
|
||||
private double[] m_data;
|
||||
|
||||
@@ -114,10 +112,7 @@ public class CircularBuffer {
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pop value at back of buffer.
|
||||
*/
|
||||
/** Pop value at back of buffer. */
|
||||
public double removeLast() {
|
||||
// If there are no elements in the buffer, do nothing
|
||||
if (m_length == 0) {
|
||||
@@ -143,9 +138,7 @@ public class CircularBuffer {
|
||||
m_front = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets internal buffer contents to zero.
|
||||
*/
|
||||
/** Sets internal buffer contents to zero. */
|
||||
public void clear() {
|
||||
for (int i = 0; i < m_data.length; i++) {
|
||||
m_data[i] = 0.0;
|
||||
@@ -163,16 +156,12 @@ public class CircularBuffer {
|
||||
return m_data[(m_front + index) % m_data.length];
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment an index modulo the length of the m_data buffer.
|
||||
*/
|
||||
/** Increment an index modulo the length of the m_data buffer. */
|
||||
private int moduloInc(int index) {
|
||||
return (index + 1) % m_data.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement an index modulo the length of the m_data buffer.
|
||||
*/
|
||||
/** Decrement an index modulo the length of the m_data buffer. */
|
||||
private int moduloDec(int index) {
|
||||
if (index == 0) {
|
||||
return m_data.length - 1;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
package edu.wpi.first.wpiutil;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -14,12 +16,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public final class CombinedRuntimeLoader {
|
||||
private CombinedRuntimeLoader() {
|
||||
}
|
||||
private CombinedRuntimeLoader() {}
|
||||
|
||||
private static String extractionDirectory;
|
||||
|
||||
@@ -35,32 +33,34 @@ public final class CombinedRuntimeLoader {
|
||||
|
||||
private static String getLoadErrorMessage(String libraryName, UnsatisfiedLinkError ule) {
|
||||
StringBuilder msg = new StringBuilder(512);
|
||||
msg.append(libraryName).append(" could not be loaded from path\n"
|
||||
+ "\tattempted to load for platform ")
|
||||
msg.append(libraryName)
|
||||
.append(" could not be loaded from path\n" + "\tattempted to load for platform ")
|
||||
.append(RuntimeDetector.getPlatformPath())
|
||||
.append("\nLast Load Error: \n")
|
||||
.append(ule.getMessage())
|
||||
.append('\n');
|
||||
if (RuntimeDetector.isWindows()) {
|
||||
msg.append("A common cause of this error is missing the C++ runtime.\n"
|
||||
+ "Download the latest at https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads\n");
|
||||
msg.append(
|
||||
"A common cause of this error is missing the C++ runtime.\n"
|
||||
+ "Download the latest at https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads\n");
|
||||
}
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a list of native libraries.
|
||||
* @param <T> The class where the resources would be located
|
||||
* @param clazz The actual class object
|
||||
* @param resourceName The resource name on the classpath to use for file lookup
|
||||
* @return List of all libraries that were extracted
|
||||
* @throws IOException Thrown if resource not found or file could not be extracted
|
||||
*
|
||||
* @param <T> The class where the resources would be located
|
||||
* @param clazz The actual class object
|
||||
* @param resourceName The resource name on the classpath to use for file lookup
|
||||
* @return List of all libraries that were extracted
|
||||
* @throws IOException Thrown if resource not found or file could not be extracted
|
||||
*/
|
||||
@SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.UnnecessaryCastRule"})
|
||||
public static <T> List<String> extractLibraries(Class<T> clazz, String resourceName)
|
||||
throws IOException {
|
||||
TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
|
||||
};
|
||||
TypeReference<HashMap<String, Object>> typeRef =
|
||||
new TypeReference<HashMap<String, Object>>() {};
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, Object> map;
|
||||
try (var stream = clazz.getResourceAsStream(resourceName)) {
|
||||
@@ -116,6 +116,7 @@ public final class CombinedRuntimeLoader {
|
||||
|
||||
/**
|
||||
* Load a single library from a list of extracted files.
|
||||
*
|
||||
* @param libraryName The library name to load
|
||||
* @param extractedFiles The extracted files to search
|
||||
* @throws IOException If library was not found
|
||||
@@ -150,8 +151,8 @@ public final class CombinedRuntimeLoader {
|
||||
/**
|
||||
* Load a list of native libraries out of a single directory.
|
||||
*
|
||||
* @param <T> The class where the resources would be located
|
||||
* @param clazz The actual class object
|
||||
* @param <T> The class where the resources would be located
|
||||
* @param clazz The actual class object
|
||||
* @param librariesToLoad List of libraries to load
|
||||
* @throws IOException Throws an IOException if not found
|
||||
*/
|
||||
|
||||
@@ -6,28 +6,29 @@ package edu.wpi.first.wpiutil;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Utility class for common WPILib error messages.
|
||||
*/
|
||||
/** Utility class for common WPILib error messages. */
|
||||
public final class ErrorMessages {
|
||||
/**
|
||||
* Utility class, so constructor is private.
|
||||
*/
|
||||
/** Utility class, so constructor is private. */
|
||||
private ErrorMessages() {
|
||||
throw new UnsupportedOperationException("This is a utility class!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires that a parameter of a method not be null; prints an error message with
|
||||
* helpful debugging instructions if the parameter is null.
|
||||
* Requires that a parameter of a method not be null; prints an error message with helpful
|
||||
* debugging instructions if the parameter is null.
|
||||
*
|
||||
* @param obj The parameter that must not be null.
|
||||
* @param paramName The name of the parameter.
|
||||
* @param methodName The name of the method.
|
||||
*/
|
||||
public static <T> T requireNonNullParam(T obj, String paramName, String methodName) {
|
||||
return requireNonNull(obj,
|
||||
"Parameter " + paramName + " in method " + methodName + " was null when it"
|
||||
return requireNonNull(
|
||||
obj,
|
||||
"Parameter "
|
||||
+ paramName
|
||||
+ " in method "
|
||||
+ methodName
|
||||
+ " was null when it"
|
||||
+ " should not have been! Check the stacktrace to find the responsible line of code - "
|
||||
+ "usually, it is the first line of user-written code indicated in the stacktrace. "
|
||||
+ "Make sure all objects passed to the method in question were properly initialized -"
|
||||
|
||||
@@ -21,7 +21,6 @@ public final class RuntimeDetector {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
boolean intel32 = is32BitIntel();
|
||||
boolean intel64 = is64BitIntel();
|
||||
|
||||
@@ -62,45 +61,35 @@ public final class RuntimeDetector {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file prefix for the current system.
|
||||
*/
|
||||
/** Get the file prefix for the current system. */
|
||||
public static synchronized String getFilePrefix() {
|
||||
computePlatform();
|
||||
|
||||
return filePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file extension for the current system.
|
||||
*/
|
||||
/** Get the file extension for the current system. */
|
||||
public static synchronized String getFileExtension() {
|
||||
computePlatform();
|
||||
|
||||
return fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the platform path for the current system.
|
||||
*/
|
||||
/** Get the platform path for the current system. */
|
||||
public static synchronized String getPlatformPath() {
|
||||
computePlatform();
|
||||
|
||||
return filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the requested resource.
|
||||
*/
|
||||
/** Get the path to the requested resource. */
|
||||
public static synchronized String getLibraryResource(String libName) {
|
||||
computePlatform();
|
||||
|
||||
return filePath + filePrefix + libName + fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the hash to the requested resource.
|
||||
*/
|
||||
/** Get the path to the hash to the requested resource. */
|
||||
public static synchronized String getHashLibraryResource(String libName) {
|
||||
computePlatform();
|
||||
|
||||
@@ -112,7 +101,8 @@ public final class RuntimeDetector {
|
||||
return runRobotFile.exists();
|
||||
}
|
||||
|
||||
/** check if os is raspbian.
|
||||
/**
|
||||
* check if os is raspbian.
|
||||
*
|
||||
* @return if os is raspbian
|
||||
*/
|
||||
@@ -125,7 +115,8 @@ public final class RuntimeDetector {
|
||||
}
|
||||
}
|
||||
|
||||
/** check if architecture is aarch64.
|
||||
/**
|
||||
* check if architecture is aarch64.
|
||||
*
|
||||
* @return if architecture is aarch64
|
||||
*/
|
||||
@@ -155,7 +146,5 @@ public final class RuntimeDetector {
|
||||
return "amd64".equals(arch) || "x86_64".equals(arch);
|
||||
}
|
||||
|
||||
private RuntimeDetector() {
|
||||
|
||||
}
|
||||
private RuntimeDetector() {}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,7 @@ import java.util.Scanner;
|
||||
public final class RuntimeLoader<T> {
|
||||
private static String defaultExtractionRoot;
|
||||
|
||||
/**
|
||||
* Gets the default extration root location (~/.wpilib/nativecache).
|
||||
*/
|
||||
/** Gets the default extration root location (~/.wpilib/nativecache). */
|
||||
public static synchronized String getDefaultExtractionRoot() {
|
||||
if (defaultExtractionRoot != null) {
|
||||
return defaultExtractionRoot;
|
||||
@@ -39,8 +37,8 @@ public final class RuntimeLoader<T> {
|
||||
/**
|
||||
* Creates a new library loader.
|
||||
*
|
||||
* <p>Resources loaded on disk from extractionRoot, and from classpath from the
|
||||
* passed in class. Library name is the passed in name.
|
||||
* <p>Resources loaded on disk from extractionRoot, and from classpath from the passed in class.
|
||||
* Library name is the passed in name.
|
||||
*/
|
||||
public RuntimeLoader(String libraryName, String extractionRoot, Class<T> cls) {
|
||||
m_libraryName = libraryName;
|
||||
@@ -51,22 +49,22 @@ public final class RuntimeLoader<T> {
|
||||
private String getLoadErrorMessage(UnsatisfiedLinkError ule) {
|
||||
StringBuilder msg = new StringBuilder(512);
|
||||
msg.append(m_libraryName)
|
||||
.append(" could not be loaded from path or an embedded resource.\n"
|
||||
.append(
|
||||
" could not be loaded from path or an embedded resource.\n"
|
||||
+ "\tattempted to load for platform ")
|
||||
.append(RuntimeDetector.getPlatformPath())
|
||||
.append("\nLast Load Error: \n")
|
||||
.append(ule.getMessage())
|
||||
.append('\n');
|
||||
if (RuntimeDetector.isWindows()) {
|
||||
msg.append("A common cause of this error is missing the C++ runtime.\n"
|
||||
+ "Download the latest at https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads\n");
|
||||
msg.append(
|
||||
"A common cause of this error is missing the C++ runtime.\n"
|
||||
+ "Download the latest at https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads\n");
|
||||
}
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a native library.
|
||||
*/
|
||||
/** Loads a native library. */
|
||||
@SuppressWarnings("PMD.PreserveStackTrace")
|
||||
public void loadLibrary() throws IOException {
|
||||
try {
|
||||
@@ -108,11 +106,14 @@ public final class RuntimeLoader<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a native library by directly hashing the file.
|
||||
*/
|
||||
@SuppressWarnings({"PMD.NPathComplexity", "PMD.PreserveStackTrace", "PMD.EmptyWhileStmt",
|
||||
"PMD.AvoidThrowingRawExceptionTypes", "PMD.CyclomaticComplexity"})
|
||||
/** Load a native library by directly hashing the file. */
|
||||
@SuppressWarnings({
|
||||
"PMD.NPathComplexity",
|
||||
"PMD.PreserveStackTrace",
|
||||
"PMD.EmptyWhileStmt",
|
||||
"PMD.AvoidThrowingRawExceptionTypes",
|
||||
"PMD.CyclomaticComplexity"
|
||||
})
|
||||
public void loadLibraryHashed() throws IOException {
|
||||
try {
|
||||
// First, try loading path
|
||||
|
||||
@@ -26,7 +26,9 @@ public final class WPIUtilJNI {
|
||||
static {
|
||||
if (Helper.getExtractOnStaticLoad()) {
|
||||
try {
|
||||
loader = new RuntimeLoader<>("wpiutiljni", RuntimeLoader.getDefaultExtractionRoot(), WPIUtilJNI.class);
|
||||
loader =
|
||||
new RuntimeLoader<>(
|
||||
"wpiutiljni", RuntimeLoader.getDefaultExtractionRoot(), WPIUtilJNI.class);
|
||||
loader.loadLibrary();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -36,14 +38,14 @@ public final class WPIUtilJNI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force load the library.
|
||||
*/
|
||||
/** Force load the library. */
|
||||
public static synchronized void forceLoad() throws IOException {
|
||||
if (libraryLoaded) {
|
||||
return;
|
||||
}
|
||||
loader = new RuntimeLoader<>("wpiutiljni", RuntimeLoader.getDefaultExtractionRoot(), WPIUtilJNI.class);
|
||||
loader =
|
||||
new RuntimeLoader<>(
|
||||
"wpiutiljni", RuntimeLoader.getDefaultExtractionRoot(), WPIUtilJNI.class);
|
||||
loader.loadLibrary();
|
||||
libraryLoaded = true;
|
||||
}
|
||||
@@ -51,5 +53,6 @@ public final class WPIUtilJNI {
|
||||
public static native long now();
|
||||
|
||||
public static native void addPortForwarder(int port, String remoteHost, int remotePort);
|
||||
|
||||
public static native void removePortForwarder(int port);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ package edu.wpi.first.wpiutil.net;
|
||||
import edu.wpi.first.wpiutil.WPIUtilJNI;
|
||||
|
||||
/**
|
||||
* Forward ports to another host. This is primarily useful for accessing
|
||||
* Ethernet-connected devices from a computer tethered to the RoboRIO USB port.
|
||||
* Forward ports to another host. This is primarily useful for accessing Ethernet-connected devices
|
||||
* from a computer tethered to the RoboRIO USB port.
|
||||
*/
|
||||
public final class PortForwarder {
|
||||
private PortForwarder() {
|
||||
@@ -16,10 +16,10 @@ public final class PortForwarder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward a local TCP port to a remote host and port.
|
||||
* Note that local ports less than 1024 won't work as a normal user.
|
||||
* Forward a local TCP port to a remote host and port. Note that local ports less than 1024 won't
|
||||
* work as a normal user.
|
||||
*
|
||||
* @param port local port number
|
||||
* @param port local port number
|
||||
* @param remoteHost remote IP address / DNS name
|
||||
* @param remotePort remote port number
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user