Skip to content

Commit

Permalink
Solve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinShalit committed Aug 3, 2016
1 parent daa5110 commit c05e53d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.function.Consumer;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

/**
* Manages the interface between the {@link PublishAnnotatedOperation} and the actual network
Expand All @@ -18,7 +19,8 @@ public abstract class NetworkReceiver implements AutoCloseable {
* @param path The path of the object to get
*/
public NetworkReceiver(String path) {
checkArgument(!path.isEmpty(), "Name cannot be an empty string");
checkNotNull(path, "Path cannot be null");
checkArgument(!path.isEmpty(), "Path cannot be an empty string");
this.path = path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ public void close() {
NetworkTablesJNI.removeEntryListener(entryListenerFunctionUid);

synchronized (NetworkTable.class) {
// This publisher is no longer used.
// This receiver is no longer used.
if (NTManager.count.addAndGet(-1) == 0) {
// We are the last publisher so shut it down
// We are the last resource using NetworkTables so shut it down
NetworkTable.shutdown();
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public void close() {
synchronized (NetworkTable.class) {
// This publisher is no longer used.
if (NTManager.count.addAndGet(-1) == 0) {
// We are the last publisher so shut it down
// We are the last resource using NetworkTables so shut it down
NetworkTable.shutdown();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.wpi.grip.core.sockets.SocketHints;
import edu.wpi.grip.core.util.ExceptionWitness;

import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableList;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
Expand All @@ -24,12 +25,13 @@
/**
* Provides a way to get a {@link Types Type} from a NetworkTable that GRIP is connected to.
*/
@XStreamAlias("grip:NetworkValue")
@XStreamAlias("grip:NetworkTableValue")
public class NetworkTableEntrySource extends Source {

private static final String PATH_PROPERTY = "networktable_path";
private static final String TYPE_PROPERTY = "BOOLEAN";

private final EventBus eventBus;
private final OutputSocket output;
private final String path;
private final Types type;
Expand All @@ -46,7 +48,7 @@ public enum Types {

@Override
public String toString() {
return super.toString().charAt(0) + super.toString().substring(1).toLowerCase();
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
}

}
Expand Down Expand Up @@ -75,12 +77,11 @@ public String toString() {
@Assisted String path,
@Assisted Types type) {
super(exceptionWitnessFactory);
this.eventBus = eventBus;
this.path = path;
this.type = type;
networkReceiver = networkReceiverFactory.create(path);
output = osf.create(createOutputSocket(type));

networkReceiver.addListener(o -> eventBus.post(new SourceHasPendingUpdateEvent(this)));
}

@Override
Expand Down Expand Up @@ -117,7 +118,7 @@ public Properties getProperties() {

@Override
public void initialize() {
updateOutputSockets();
networkReceiver.addListener(o -> eventBus.post(new SourceHasPendingUpdateEvent(this)));
}

@Subscribe
Expand All @@ -141,7 +142,7 @@ private static SocketHint createOutputSocket(Types type) {
case STRING:
return SocketHints.Outputs.createStringSocketHint(Types.STRING.toString(), "");
default:
throw new IllegalArgumentException("Invalid NetworkTable source type");
throw new IllegalArgumentException(type + " is an invalid NetworkTable source type");
}
}
}

0 comments on commit c05e53d

Please sign in to comment.