Skip to content

Commit

Permalink
add descriptive null handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Oblarg committed Jun 3, 2019
1 parent b8d6357 commit b5f313b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/src/main/java/io/github/oblarg/oblog/NTContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.shuffleboard.LayoutType;

import static io.github.oblarg.oblog.Util.nullCheck;

class NTContainer implements ShuffleboardContainerWrapper {

NetworkTable table;
Expand All @@ -19,11 +21,13 @@ public ShuffleboardLayoutWrapper getLayout(String title, LayoutType type) {

@Override
public SimpleWidgetWrapper add(String title, Object defaultValue) {
nullCheck(defaultValue, title, table.getPath());
return new NTSimpleWidget(table.getEntry(title), defaultValue);
}

@Override
public ComplexWidgetWrapper add(String title, Sendable defaultValue) {
nullCheck(defaultValue, title, table.getPath());
return new NTComplexWidget(table, title, defaultValue);
}
}
4 changes: 4 additions & 0 deletions lib/src/main/java/io/github/oblarg/oblog/NTLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import java.util.Map;

import static io.github.oblarg.oblog.Util.nullCheck;

class NTLayout implements ShuffleboardLayoutWrapper {

private NetworkTable table;
Expand All @@ -26,11 +28,13 @@ public ShuffleboardLayoutWrapper getLayout(String title, LayoutType type) {

@Override
public SimpleWidgetWrapper add(String title, Object defaultValue) {
nullCheck(defaultValue, title, table.getPath());
return new NTSimpleWidget(table.getEntry(title), defaultValue);
}

@Override
public ComplexWidgetWrapper add(String title, Sendable defaultValue) {
nullCheck(defaultValue, title, table.getPath());
return new NTComplexWidget(table, title, defaultValue);
}

Expand Down
10 changes: 10 additions & 0 deletions lib/src/main/java/io/github/oblarg/oblog/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.oblarg.oblog;

import static java.util.Objects.requireNonNull;

public class Util {
public static void nullCheck(Object obj, String title, String containerName) {
requireNonNull(obj, "Error! Attempted to log null value with widget title " + title + " in container "
+ containerName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import edu.wpi.first.wpilibj.shuffleboard.LayoutType;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardContainer;

import static io.github.oblarg.oblog.Util.nullCheck;

class WrappedShuffleboardContainer implements ShuffleboardContainerWrapper {

private ShuffleboardContainer container;
Expand All @@ -19,11 +21,13 @@ public ShuffleboardLayoutWrapper getLayout(String title, LayoutType type) {

@Override
public SimpleWidgetWrapper add(String title, Object defaultValue) {
nullCheck(defaultValue, title, container.getTitle());
return new WrappedSimpleWidget(container.add(title, defaultValue));
}

@Override
public ComplexWidgetWrapper add(String title, Sendable defaultValue) {
nullCheck(defaultValue, title, container.getTitle());
return new WrappedComplexWidget(container.add(title, defaultValue));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import java.util.Map;

import static io.github.oblarg.oblog.Util.nullCheck;

class WrappedShuffleboardLayout implements ShuffleboardLayoutWrapper {

private ShuffleboardLayout layout;
Expand All @@ -21,11 +23,13 @@ public ShuffleboardLayoutWrapper getLayout(String title, LayoutType type) {

@Override
public SimpleWidgetWrapper add(String title, Object defaultValue) {
nullCheck(defaultValue, title, layout.getTitle());
return new WrappedSimpleWidget(layout.add(title, defaultValue));
}

@Override
public ComplexWidgetWrapper add(String title, Sendable defaultValue) {
nullCheck(defaultValue, title, layout.getTitle());
return new WrappedComplexWidget(layout.add(title, defaultValue));
}

Expand Down

0 comments on commit b5f313b

Please sign in to comment.