Skip to content

Commit c05e53d

Browse files
committed
Solve comments
1 parent daa5110 commit c05e53d

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

core/src/main/java/edu/wpi/grip/core/operations/network/NetworkReceiver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.function.Consumer;
44

55
import static com.google.common.base.Preconditions.checkArgument;
6+
import static com.google.common.base.Preconditions.checkNotNull;
67

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

core/src/main/java/edu/wpi/grip/core/operations/network/networktables/NTManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ public void close() {
178178
NetworkTablesJNI.removeEntryListener(entryListenerFunctionUid);
179179

180180
synchronized (NetworkTable.class) {
181-
// This publisher is no longer used.
181+
// This receiver is no longer used.
182182
if (NTManager.count.addAndGet(-1) == 0) {
183-
// We are the last publisher so shut it down
183+
// We are the last resource using NetworkTables so shut it down
184184
NetworkTable.shutdown();
185185
}
186186
}
@@ -247,7 +247,7 @@ public void close() {
247247
synchronized (NetworkTable.class) {
248248
// This publisher is no longer used.
249249
if (NTManager.count.addAndGet(-1) == 0) {
250-
// We are the last publisher so shut it down
250+
// We are the last resource using NetworkTables so shut it down
251251
NetworkTable.shutdown();
252252
}
253253
}

core/src/main/java/edu/wpi/grip/core/sources/NetworkTableEntrySource.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import edu.wpi.grip.core.sockets.SocketHints;
1111
import edu.wpi.grip.core.util.ExceptionWitness;
1212

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

3031
private static final String PATH_PROPERTY = "networktable_path";
3132
private static final String TYPE_PROPERTY = "BOOLEAN";
3233

34+
private final EventBus eventBus;
3335
private final OutputSocket output;
3436
private final String path;
3537
private final Types type;
@@ -46,7 +48,7 @@ public enum Types {
4648

4749
@Override
4850
public String toString() {
49-
return super.toString().charAt(0) + super.toString().substring(1).toLowerCase();
51+
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
5052
}
5153

5254
}
@@ -75,12 +77,11 @@ public String toString() {
7577
@Assisted String path,
7678
@Assisted Types type) {
7779
super(exceptionWitnessFactory);
80+
this.eventBus = eventBus;
7881
this.path = path;
7982
this.type = type;
8083
networkReceiver = networkReceiverFactory.create(path);
8184
output = osf.create(createOutputSocket(type));
82-
83-
networkReceiver.addListener(o -> eventBus.post(new SourceHasPendingUpdateEvent(this)));
8485
}
8586

8687
@Override
@@ -117,7 +118,7 @@ public Properties getProperties() {
117118

118119
@Override
119120
public void initialize() {
120-
updateOutputSockets();
121+
networkReceiver.addListener(o -> eventBus.post(new SourceHasPendingUpdateEvent(this)));
121122
}
122123

123124
@Subscribe
@@ -141,7 +142,7 @@ private static SocketHint createOutputSocket(Types type) {
141142
case STRING:
142143
return SocketHints.Outputs.createStringSocketHint(Types.STRING.toString(), "");
143144
default:
144-
throw new IllegalArgumentException("Invalid NetworkTable source type");
145+
throw new IllegalArgumentException(type + " is an invalid NetworkTable source type");
145146
}
146147
}
147148
}

0 commit comments

Comments
 (0)