Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
My current process is
* Import checkstyle into project configuration.
* Run Reformat Code on each module, with Optimize Imports and '*.java' file mask
  • Loading branch information
rbrott committed Nov 5, 2023
1 parent 0191cfd commit b129e90
Show file tree
Hide file tree
Showing 35 changed files with 355 additions and 282 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.acmerobotics.dashboard;

import com.acmerobotics.dashboard.canvas.Canvas;
import com.acmerobotics.dashboard.config.ValueProvider;
import com.acmerobotics.dashboard.config.variable.BasicVariable;
import com.acmerobotics.dashboard.config.variable.ConfigVariableDeserializer;
Expand All @@ -15,7 +14,6 @@
import com.acmerobotics.dashboard.telemetry.TelemetryPacket;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -44,13 +42,13 @@ public class DashboardCore {

// NOTE: Helps to have this here for testing
public static final Gson GSON = new GsonBuilder()
.registerTypeAdapter(Message.class, new MessageDeserializer())
.registerTypeAdapter(BasicVariable.class, new ConfigVariableSerializer())
.registerTypeAdapter(BasicVariable.class, new ConfigVariableDeserializer())
.registerTypeAdapter(CustomVariable.class, new ConfigVariableSerializer())
.registerTypeAdapter(CustomVariable.class, new ConfigVariableDeserializer())
.serializeNulls()
.create();
.registerTypeAdapter(Message.class, new MessageDeserializer())
.registerTypeAdapter(BasicVariable.class, new ConfigVariableSerializer())
.registerTypeAdapter(BasicVariable.class, new ConfigVariableDeserializer())
.registerTypeAdapter(CustomVariable.class, new ConfigVariableSerializer())
.registerTypeAdapter(CustomVariable.class, new ConfigVariableDeserializer())
.serializeNulls()
.create();

private class TelemetryUpdateRunnable implements Runnable {
@Override
Expand All @@ -70,7 +68,8 @@ public void run() {

// only the latest packet field overlay is used
// this helps save bandwidth, especially for more complex overlays
for (TelemetryPacket packet : telemetryToSend.subList(0, telemetryToSend.size() - 1)) {
for (TelemetryPacket packet : telemetryToSend.subList(0,
telemetryToSend.size() - 1)) {
packet.fieldOverlay().clear();
}

Expand All @@ -85,7 +84,8 @@ public void run() {
}

public DashboardCore() {
telemetryExecutorService = Executors.newSingleThreadExecutor(r -> new Thread(r, "dash telemetry"));
telemetryExecutorService =
Executors.newSingleThreadExecutor(r -> new Thread(r, "dash telemetry"));
telemetryExecutorService.submit(new TelemetryUpdateRunnable());
}

Expand Down Expand Up @@ -189,6 +189,7 @@ public int getTelemetryTransmissionInterval() {

/**
* Sets the telemetry transmission interval.
*
* @param newTransmissionInterval transmission interval in milliseconds
*/
public void setTelemetryTransmissionInterval(int newTransmissionInterval) {
Expand All @@ -207,7 +208,7 @@ public void updateConfig() {
/**
* Executes {@param function} in an exclusive context for thread-safe config tree modification
* and calls {@link #updateConfig()} to keep clients up to date.
*
* <p>
* Do not leak the config tree outside the function.
*
* @param function
Expand All @@ -220,10 +221,11 @@ public void withConfigRoot(CustomVariableConsumer function) {

/**
* Add config variable with custom provider.
*
* @param category top-level category
* @param name variable name
* @param name variable name
* @param provider getter/setter for the variable
* @param <T> variable type
* @param <T> variable type
*/
public <T> void addConfigVariable(String category, String name, ValueProvider<T> provider) {
configRoot.with(v -> {
Expand All @@ -241,8 +243,9 @@ public <T> void addConfigVariable(String category, String name, ValueProvider<T>

/**
* Remove a config variable.
*
* @param category top-level category
* @param name variable name
* @param name variable name
*/
public void removeConfigVariable(String category, String name) {
configRoot.with(v -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public enum OpModeStatus {
/**
* Creates a status object with the default values.
*/
public RobotStatus(boolean enabled, boolean available, String activeOpMode, OpModeStatus activeOpModeStatus, String warningMessage, String errorMessage) {
public RobotStatus(boolean enabled, boolean available, String activeOpMode,
OpModeStatus activeOpModeStatus, String warningMessage,
String errorMessage) {
this.enabled = enabled;
this.available = available;
this.activeOpMode = activeOpMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@ public Canvas setTranslation(double x, double y) {
return this;
}

public Canvas strokeText(String text, double x, double y, String font, double theta, boolean usePageFrame) {
public Canvas strokeText(String text, double x, double y, String font, double theta,
boolean usePageFrame) {
ops.add(new Text(text, x, y, font, theta, true, usePageFrame));
return this;
}

public Canvas strokeText(String text, double x, double y, String font, double theta) {
strokeText(text, x, y, font, theta, true);
return this;
}
public Canvas fillText(String text, double x, double y, String font, double theta, boolean usePageFrame) {

public Canvas fillText(String text, double x, double y, String font, double theta,
boolean usePageFrame) {
ops.add(new Text(text, x, y, font, theta, false, usePageFrame));
return this;
}

public Canvas fillText(String text, double x, double y, String font, double theta) {
fillText(text, x, y, font, theta, true);
return this;
Expand Down Expand Up @@ -68,19 +73,19 @@ public Canvas strokePolyline(double[] xPoints, double[] yPoints) {
}

public Canvas strokeLine(double x1, double y1, double x2, double y2) {
strokePolyline(new double[] { x1, x2 }, new double[] { y1, y2 });
strokePolyline(new double[] {x1, x2}, new double[] {y1, y2});
return this;
}

public Canvas fillRect(double x, double y, double width, double height) {
fillPolygon(new double[] { x, x + width, x + width, x },
new double[] { y, y, y + height, y + height });
fillPolygon(new double[] {x, x + width, x + width, x},
new double[] {y, y, y + height, y + height});
return this;
}

public Canvas strokeRect(double x, double y, double width, double height) {
strokePolygon(new double[] { x, x + width, x + width, x },
new double[] { y, y, y + height, y + height });
strokePolygon(new double[] {x, x + width, x + width, x},
new double[] {y, y, y + height, y + height});
return this;
}

Expand Down Expand Up @@ -115,17 +120,23 @@ public Canvas drawImage(String path, double x, double y, double width, double he
return this;
}

public Canvas drawImage(String path, double x, double y, double width, double height, double theta, double pivotX, double pivotY, boolean usePageFrame) {
public Canvas drawImage(String path, double x, double y, double width, double height,
double theta, double pivotX, double pivotY, boolean usePageFrame) {
ops.add(new Image(path, x, y, width, height, theta, pivotX, pivotY, usePageFrame));
return this;
}

public Canvas drawGrid(double x, double y, double width, double height, int numTicksX, int numTicksY) {
drawGrid(x, y, width, height, numTicksX, numTicksY, 0, 0,0, true);
public Canvas drawGrid(double x, double y, double width, double height, int numTicksX,
int numTicksY) {
drawGrid(x, y, width, height, numTicksX, numTicksY, 0, 0, 0, true);
return this;
}
public Canvas drawGrid(double x, double y, double width, double height, int numTicksX, int numTicksY, double theta, double pivotX, double pivotY, boolean usePageFrame) {
ops.add(new Grid(x, y, width, height, numTicksX, numTicksY, theta, pivotX, pivotY, usePageFrame));

public Canvas drawGrid(double x, double y, double width, double height, int numTicksX,
int numTicksY, double theta, double pivotX, double pivotY,
boolean usePageFrame) {
ops.add(new Grid(x, y, width, height, numTicksX, numTicksY, theta, pivotX, pivotY,
usePageFrame));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class Grid extends CanvasOp {
private double theta, pivotX, pivotY;
private boolean usePageFrame;

public Grid(double x, double y, double width, double height, int numTicksX, int numTicksY, double theta, double pivotX, double pivotY, boolean usePageFrame) {
public Grid(double x, double y, double width, double height, int numTicksX, int numTicksY,
double theta, double pivotX, double pivotY, boolean usePageFrame) {
super(Type.GRID);

this.x = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class Image extends CanvasOp {
private double theta, pivotX, pivotY;
private boolean usePageFrame;

public Image(String path, double x, double y, double width, double height, double theta, double pivotX, double pivotY, boolean usePageFrame) {
public Image(String path, double x, double y, double width, double height, double theta,
double pivotX, double pivotY, boolean usePageFrame) {
super(Type.IMAGE);

this.path = path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class Rotation extends CanvasOp {
private double rotation;

public Rotation(double radians) {
super(Type.ROTATION);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class Text extends CanvasOp {
private boolean stroke;
private boolean usePageFrame;

public Text(String text, double x, double y, String font, double theta, boolean stroke, boolean usePageFrame) {
public Text(String text, double x, double y, String font, double theta, boolean stroke,
boolean usePageFrame) {
super(Type.TEXT);
this.text = text;
this.x = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class Translate extends CanvasOp {
private double x;
private double y;

public Translate(double x, double y) {
super(Type.TRANSLATE);

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

/**
* A generic interface for providing and storing a single value.
*
* @param <T> type of the value
*/
public interface ValueProvider<T> {
Expand All @@ -12,6 +13,7 @@ public interface ValueProvider<T> {

/**
* Updates the value. {@link #get()} should now return this new value.
*
* @param value
*/
void set(T value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
package com.acmerobotics.dashboard.config.reflection;

import com.acmerobotics.dashboard.config.ValueProvider;

import java.lang.reflect.Array;
import java.lang.reflect.Field;

public class ArrayProvider<T> implements ValueProvider<T> {
private final Field field;
private final Object parent;
private final int[] indices;

public ArrayProvider(Field field, Object parent, int... indices) {
this.field = field;
this.parent = parent;
this.indices = indices;
}

@SuppressWarnings("unchecked")
@Override
public T get() {
try {
return (T) getArrayRecursive(field.get(parent), indices);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch(ArrayIndexOutOfBoundsException e)
{
} catch (ArrayIndexOutOfBoundsException e) {
return null;
}
}

@Override
public void set(T value) {
try {
setArrayRecursive(field.get(parent), value, indices);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}catch(ArrayIndexOutOfBoundsException ignored) { }
} catch (ArrayIndexOutOfBoundsException ignored) {
}
}


public static Object getArrayRecursive(Object object, int[] indices) throws ArrayIndexOutOfBoundsException, IllegalAccessException
{
public static Object getArrayRecursive(Object object, int[] indices)
throws ArrayIndexOutOfBoundsException, IllegalAccessException {
for (int index : indices) {
object = Array.get(object, index);
}
return object;
}
public static void setArrayRecursive(Object object, Object value, int[] indices)
{
for(int i=0;i< indices.length-1;i++)
{
object=Array.get(object,indices[i]);

public static void setArrayRecursive(Object object, Object value, int[] indices) {
for (int i = 0; i < indices.length - 1; i++) {
object = Array.get(object, indices[i]);
}
Array.set(object,indices[indices.length-1], value);
Array.set(object, indices[indices.length - 1], value);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.acmerobotics.dashboard.config.reflection;

import com.acmerobotics.dashboard.config.ValueProvider;

import java.lang.reflect.Field;

/**
* Value provider backed by a class field.
*
* @param <T> type of the class field
*/
public class FieldProvider<T> implements ValueProvider<T> {
Expand Down
Loading

0 comments on commit b129e90

Please sign in to comment.