Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply spotless for java everywhere #762

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.prefs.BackingStoreException;

/**
* A mock preferences class that stores values in a {@link Map Map<String, String>}.
* This cannot have child preference nodes.
* A mock preferences class that stores values in a {@link Map Map<String, String>}. This
* cannot have child preference nodes.
*/
public class MockPreferences extends AbstractPreferences {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
package edu.wpi.first.shuffleboard.api;

import edu.wpi.first.shuffleboard.api.properties.AsyncProperty;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;

/**
* An enum representing the possible modes of dashboard operation.
*/
/** An enum representing the possible modes of dashboard operation. */
public enum DashboardMode {

/**
* Normal operation. No recording or playback is taking place.
*/
/** Normal operation. No recording or playback is taking place. */
NORMAL,

/**
* The dashboard behaves as {@link #NORMAL}, but records all incoming data in the background.
*/
/** The dashboard behaves as {@link #NORMAL}, but records all incoming data in the background. */
RECORDING,

/**
* When in this mode, the dashboard is playing back recorded data.
*/
/** When in this mode, the dashboard is playing back recorded data. */
PLAYBACK;

private static final ObjectProperty<DashboardMode> currentMode
= new AsyncProperty<>(DashboardMode.class, "currentMode", NORMAL);
private static final ObjectProperty<DashboardMode> currentMode =
new AsyncProperty<>(DashboardMode.class, "currentMode", NORMAL);

public static Property<DashboardMode> currentModeProperty() {
return currentMode;
}

/**
* Gets the current mode of the dashboard.
*/
/** Gets the current mode of the dashboard. */
public static DashboardMode getCurrentMode() {
return currentMode.get();
}

/**
* Sets the current mode of the dashboard.
*/
/** Sets the current mode of the dashboard. */
public static void setCurrentMode(DashboardMode currentMode) {
DashboardMode.currentMode.set(currentMode);
}

public static boolean inPlayback() {
return getCurrentMode() == PLAYBACK;
}

}
19 changes: 8 additions & 11 deletions api/src/main/java/edu/wpi/first/shuffleboard/api/Populatable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import edu.wpi.first.shuffleboard.api.sources.DataSource;
import edu.wpi.first.shuffleboard.api.sources.SourceTypes;

/**
* Common interface for items that support auto-population of UI components by the application.
*/
/** Common interface for items that support auto-population of UI components by the application. */
public interface Populatable {

/**
* Checks if the given data source is supported, ie it matches some criteria; for example, a widget that populates
* with data under a certain path should check if the source's ID starts with that path. Containers with no criteria
* should always return {@code true}.
* Checks if the given data source is supported, ie it matches some criteria; for example, a
* widget that populates with data under a certain path should check if the source's ID starts
* with that path. Containers with no criteria should always return {@code true}.
*
* @param sourceId the ID of the source to check
*/
Expand All @@ -32,8 +30,8 @@ public interface Populatable {
void addComponentFor(DataSource<?> source);

/**
* If possible, adds a component for a data source. A component will only be added iff the source is supported and
* there is no component present that already corresponds to that source.
* If possible, adds a component for a data source. A component will only be added iff the source
* is supported and there is no component present that already corresponds to that source.
*
* @param source the source to check/add a component for
*/
Expand All @@ -44,8 +42,8 @@ default void addComponentIfPossible(DataSource<?> source) {
}

/**
* If possible, adds a component for a data source. A component will only be added iff the source ID is supported and
* there is no component present that already corresponds to that source ID.
* If possible, adds a component for a data source. A component will only be added iff the source
* ID is supported and there is no component present that already corresponds to that source ID.
*
* @param sourceTypes the source type registry to use to create a new source to populate
* @param sourceId the ID of the source for the component to add
Expand All @@ -55,5 +53,4 @@ default void addComponentIfPossible(SourceTypes sourceTypes, String sourceId) {
addComponentFor(sourceTypes.forUri(sourceId));
}
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package edu.wpi.first.shuffleboard.api;

/**
* Parses arbitrary input and returns the result. This is used to set the values of
* {@link edu.wpi.first.shuffleboard.api.widget.Component Component} settings provided by a remote definition (such as
* a FRC robot program).
* Parses arbitrary input and returns the result. This is used to set the values of {@link
* edu.wpi.first.shuffleboard.api.widget.Component Component} settings provided by a remote
* definition (such as a FRC robot program).
*
* @param <T> the type of values this parser provides
*/
public interface PropertyParser<T> {

/**
* Creates a new property parser for an enum type. Valid inputs are {@code E}, {@code String} (matching the enum
* constant name), and {@code Integer} (enum ordinal).
* Creates a new property parser for an enum type. Valid inputs are {@code E}, {@code String}
* (matching the enum constant name), and {@code Integer} (enum ordinal).
*
* @param type the enum type to create a parser for
* @param <E> the type of the enum class
*
* @param <E> the type of the enum class
* @return a parser that outputs constants from the given enum type
*/
static <E extends Enum<E>> PropertyParser<E> forEnum(Class<E> type) {
Expand All @@ -30,9 +29,7 @@ public Class<E> outputType() {

@Override
public boolean canParse(Object input) {
return type.isInstance(input)
|| input instanceof String
|| input instanceof Integer;
return type.isInstance(input) || input instanceof String || input instanceof Integer;
}

@Override
Expand All @@ -55,16 +52,13 @@ public E parse(Object input) {
};
}

/**
* Gets the type of the output of the parser.
*/
/** Gets the type of the output of the parser. */
Class<T> outputType();

/**
* Checks if the given input is supported by this parser.
*
* @param input the input to check
*
* @return true if the input can be {@link #parse(Object) parsed}, false if not
*/
boolean canParse(Object input);
Expand All @@ -73,7 +67,6 @@ public E parse(Object input) {
* Parses the given input and returns the result.
*
* @param input the value to parse
*
* @return the parsed value
*/
T parse(Object input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import edu.wpi.first.shuffleboard.api.util.Registry;
import edu.wpi.first.shuffleboard.api.widget.LayoutBase;

import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import javafx.geometry.Orientation;
import javafx.scene.paint.Color;

/**
* Registry for {@link PropertyParser PropertyParsers}.
*/
/** Registry for {@link PropertyParser PropertyParsers}. */
public final class PropertyParsers extends Registry<PropertyParser<?>> {

private static final PropertyParser<Orientation> ORIENTATION =
Expand Down Expand Up @@ -58,28 +54,29 @@ public void unregister(PropertyParser<?> item) {
/**
* Parses the given input as a value of the given output type.
*
* @param input the value to parse
* @param input the value to parse
* @param outputType the type of the value to parse as
* @param <T> the type of the parsed result
*
* @param <T> the type of the parsed result
* @return the parse result
*
* @throws IllegalStateException if there are multiple registered parsers for type {@code T}
*/
public <T> Optional<T> parse(Object input, Class<T> outputType) {
Set<T> possibilities = getItems()
.stream()
.filter(p -> p.outputType().isAssignableFrom(outputType))
.filter(p -> p.canParse(input))
.map(p -> (PropertyParser<T>) p)
.map(p -> p.parse(input))
.collect(Collectors.toSet());
Set<T> possibilities =
getItems().stream()
.filter(p -> p.outputType().isAssignableFrom(outputType))
.filter(p -> p.canParse(input))
.map(p -> (PropertyParser<T>) p)
.map(p -> p.parse(input))
.collect(Collectors.toSet());
if (possibilities.isEmpty()) {
return Optional.empty();
}
if (possibilities.size() > 1) {
throw new IllegalStateException(
"Multiple parsers for " + input + " supporting output type " + outputType.getSimpleName());
"Multiple parsers for "
+ input
+ " supporting output type "
+ outputType.getSimpleName());
}
return Optional.of(possibilities.iterator().next());
}
Expand Down Expand Up @@ -143,9 +140,7 @@ public Class<Color> outputType() {

@Override
public boolean canParse(Object input) {
return input instanceof Color
|| input instanceof String
|| input instanceof Number;
return input instanceof Color || input instanceof String || input instanceof Number;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package edu.wpi.first.shuffleboard.api;

public enum TileTitleDisplayMode {
/**
* The default tile view type - large title ad header bar.
*/
/** The default tile view type - large title ad header bar. */
DEFAULT("Default"),
/**
* Minimal tiles with smaller header bars and titles.
*/
/** Minimal tiles with smaller header bars and titles. */
MINIMAL("Minimal"),
/**
* No header bars at all.
*/
/** No header bars at all. */
HIDDEN("Hidden");

private final String humanReadable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package edu.wpi.first.shuffleboard.api.components;

import edu.wpi.first.shuffleboard.api.util.PropertyUtils;

import java.util.Objects;

import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;

/**
* A type of text field that only accepts valid numbers.
*/
/** A type of text field that only accepts valid numbers. */
public abstract class AbstractNumberField<N extends Number> extends TextField {

private final Property<N> number = new SimpleObjectProperty<>(this, "number");
Expand All @@ -23,28 +19,31 @@ protected AbstractNumberField() {
getStyleClass().add("number-field");
setText("0");
setNumber(getNumberFromText("0"));
setTextFormatter(new TextFormatter<>(change -> {
String text = change.getControlNewText();
if (isCompleteNumber(text)) {
// Bounds check
final N number = getNumberFromText(text);
if (getMaxValue() != null && number.doubleValue() > getMaxValue().doubleValue()) {
return null;
}
if (getMinValue() != null && number.doubleValue() < getMinValue().doubleValue()) {
return null;
}
}
if (isStartOfNumber(text)) {
return change;
}
return null;
}));
setTextFormatter(
new TextFormatter<>(
change -> {
String text = change.getControlNewText();
if (isCompleteNumber(text)) {
// Bounds check
final N number = getNumberFromText(text);
if (getMaxValue() != null && number.doubleValue() > getMaxValue().doubleValue()) {
return null;
}
if (getMinValue() != null && number.doubleValue() < getMinValue().doubleValue()) {
return null;
}
}
if (isStartOfNumber(text)) {
return change;
}
return null;
}));
PropertyUtils.bindBidirectionalWithConverter(
textProperty(),
number,
text -> isCompleteNumber(text) ? getNumberFromText(text) : getNumber(),
num -> Objects.equals(num, getNumberFromText(getText())) ? getText() : getTextFromNumber(num));
num ->
Objects.equals(num, getNumberFromText(getText())) ? getText() : getTextFromNumber(num));
}

protected AbstractNumberField(N initialValue) {
Expand All @@ -53,16 +52,14 @@ protected AbstractNumberField(N initialValue) {
}

/**
* Checks if the given string is a valid start to an acceptable number in text form.
* This differs from {@link #isCompleteNumber(String) isCompleteNumber} because this checks if the
* text is only a valid <i>beginning</i> of a string representation of a number. For example, this
* method could accept a single "-" because it's a valid start to a negative number.
* Checks if the given string is a valid start to an acceptable number in text form. This differs
* from {@link #isCompleteNumber(String) isCompleteNumber} because this checks if the text is only
* a valid <i>beginning</i> of a string representation of a number. For example, this method could
* accept a single "-" because it's a valid start to a negative number.
*/
protected abstract boolean isStartOfNumber(String text);

/**
* Checks if the given string is a valid number acceptable by this text field.
*/
/** Checks if the given string is a valid number acceptable by this text field. */
protected abstract boolean isCompleteNumber(String text);

/**
Expand Down
Loading