4141public class Deadeye <T extends TargetData > {
4242
4343 static final Logger logger = LoggerFactory .getLogger (Deadeye .class );
44- private static volatile Link link ;
45- private final NetworkTable cameraTable ;
46- private final String id ;
47- private final DeadeyeJsonAdapter <T > jsonAdapter ;
48- private TargetDataListener <T > targetDataListener ;
49- private T targetData ;
44+ private static volatile @ Nullable Link link ;
45+ private final @ NotNull NetworkTable cameraTable ;
46+ private final @ NotNull String id ;
47+ private final @ NotNull DeadeyeJsonAdapter <T > jsonAdapter ;
48+ private @ NotNull TargetDataListener <T > targetDataListener = data -> {
49+ };
50+ private @ NotNull T targetData ;
5051
5152 /**
5253 * Constructs an instance of {@code Deadeye} and initializes a connection to the associated
@@ -55,11 +56,10 @@ public class Deadeye<T extends TargetData> {
5556 * @param id the camera id, i.e. the Deadeye unit letter followed by the camera number, for
5657 * example "A0".
5758 * @param cls the {@code TargetData} Java class corresponding to the Deadeye pipeline type.
58- * @throws NullPointerException if the {@code cls} is {@code null}
5959 * @throws IllegalArgumentException if the {@code id} is not a letter followed by a 0-4 digit
6060 * @throws IllegalArgumentException if the {@code cls} is not a valid {@code TargetData} class
6161 */
62- public Deadeye (String id , Class <T > cls ) {
62+ public Deadeye (@ NotNull String id , @ NotNull Class <T > cls ) {
6363 this (id , cls , NetworkTableInstance .getDefault (), null );
6464 }
6565
@@ -78,13 +78,12 @@ public Deadeye(String id, Class<T> cls) {
7878 * @param linkAddress the IP address the Deadeye daemon should send data to. If null, this client
7979 * will reuse a previously configured address or attempt to automatically
8080 * detect the correct IP address.
81- * @throws NullPointerException if the {@code cls} is {@code null}
8281 * @throws IllegalArgumentException if the {@code id} is not a letter followed by a 0-4 digit
8382 * @throws IllegalArgumentException if the {@code cls} is not a valid {@code TargetData} class
8483 * @throws IllegalArgumentException if the {@code linkAddress} supplied more than once and does
8584 * not match address already in use
8685 */
87- public Deadeye (String id , Class <T > cls , String linkAddress ) {
86+ public Deadeye (@ NotNull String id , @ NotNull Class <T > cls , @ Nullable String linkAddress ) {
8887 this (id , cls , NetworkTableInstance .getDefault (), linkAddress );
8988 }
9089
@@ -98,11 +97,10 @@ public Deadeye(String id, Class<T> cls, String linkAddress) {
9897 * example "A0".
9998 * @param cls the {@code TargetData} Java class corresponding to the Deadeye pipeline type.
10099 * @param nti the NetworkTables instance to connect through.
101- * @throws NullPointerException if the {@code cls} or {@code nti} is {@code null}
102100 * @throws IllegalArgumentException if the {@code id} is not a letter followed by a 0-4 digit
103101 * @throws IllegalArgumentException if the {@code cls} is not a valid {@code TargetData} class
104102 */
105- public Deadeye (String id , Class <T > cls , NetworkTableInstance nti ) {
103+ public Deadeye (@ NotNull String id , @ NotNull Class <T > cls , @ NotNull NetworkTableInstance nti ) {
106104 this (id , cls , nti , null );
107105 }
108106
@@ -121,14 +119,15 @@ public Deadeye(String id, Class<T> cls, NetworkTableInstance nti) {
121119 * @param nti the NetworkTables instance to connect through.
122120 * @param linkAddress the IP address the Deadeye daemon should send data to. If null, this client
123121 * will attempt to automatically detect the correct IP address.
124- * @throws NullPointerException if the {@code cls} or {@code nti} is {@code null}
125122 * @throws IllegalArgumentException if the {@code id} is not a letter followed by a 0-4 digit
126123 * @throws IllegalArgumentException if the {@code cls} is not a valid {@code TargetData} class
127124 * @throws IllegalArgumentException if the {@code linkAddress} supplied more than once and does
128125 * not match address already in use
129126 */
130127 @ SuppressWarnings ("unchecked" )
131- public Deadeye (String id , Class <T > cls , NetworkTableInstance nti , String linkAddress ) {
128+ public Deadeye (
129+ @ NotNull String id , @ NotNull Class <T > cls , @ NotNull NetworkTableInstance nti ,
130+ @ Nullable String linkAddress ) {
132131 Objects .requireNonNull (cls , "cls must not be null" );
133132 Objects .requireNonNull (nti , "nti must not be null" );
134133 if (!Pattern .matches ("^[A-Za-z][0-4]$" , id )) {
@@ -143,6 +142,7 @@ public Deadeye(String id, Class<T> cls, NetworkTableInstance nti, String linkAdd
143142 }
144143 }
145144
145+ Link link = Objects .requireNonNull (Deadeye .link );
146146 if (linkAddress != null && !link .getAddress ().equals (linkAddress )) {
147147 throw new IllegalArgumentException (
148148 "supplied linkAddress does not match address already in use" );
@@ -191,6 +191,7 @@ static JsonAdapter<Capture> getCaptureJsonAdapter() {
191191 *
192192 * @return the associated {@code TargetDataListener}.
193193 */
194+ @ NotNull
194195 public TargetDataListener <T > getTargetDataListener () {
195196 return targetDataListener ;
196197 }
@@ -201,7 +202,7 @@ public TargetDataListener<T> getTargetDataListener() {
201202 *
202203 * @param targetDataListener class to receive target data
203204 */
204- public void setTargetDataListener (TargetDataListener <T > targetDataListener ) {
205+ public void setTargetDataListener (@ NotNull TargetDataListener <T > targetDataListener ) {
205206 this .targetDataListener = targetDataListener ;
206207 }
207208
@@ -215,16 +216,15 @@ public void setTargetDataListener(TargetDataListener<T> targetDataListener) {
215216 */
216217 public void handleTargetData (BufferedSource source ) throws IOException {
217218 targetData = jsonAdapter .fromJson (source );
218- if (targetDataListener != null ) {
219- targetDataListener .onTargetData (targetData );
220- }
219+ targetDataListener .onTargetData (targetData );
221220 }
222221
223222 /**
224223 * Gets the most recent {@code TargetData} received by this {@code Deadeye} instance.
225224 *
226225 * @return the last valid target data update.
227226 */
227+ @ NotNull
228228 public T getTargetData () {
229229 return targetData ;
230230 }
@@ -323,7 +323,12 @@ public Capture getCapture() {
323323 return new Capture ();
324324 }
325325
326- Link getLink () {
326+ /**
327+ * Provide Link for testing.
328+ *
329+ * @return the {@code Link} or {@code null} if a Deadeye unit has not been initialized yet
330+ */
331+ @ Nullable Link getLink () {
327332 return link ;
328333 }
329334
@@ -356,7 +361,7 @@ public Info(boolean logging, String pipeline, String version) {
356361 }
357362
358363 @ Override
359- public boolean equals (Object o ) {
364+ public boolean equals (@ Nullable Object o ) {
360365 if (this == o ) {
361366 return true ;
362367 }
@@ -375,7 +380,7 @@ public int hashCode() {
375380 }
376381
377382 @ Override
378- public String toString () {
383+ public @ NotNull String toString () {
379384 return "Info{"
380385 + "logging="
381386 + logging
@@ -417,7 +422,9 @@ public static class Capture {
417422 @ Json (name = "h" )
418423 public final int height ;
419424
420- public Capture () {this ("ERROR" ,0 ,0 ,0 );}
425+ public Capture () {
426+ this ("ERROR" , 0 , 0 , 0 );
427+ }
421428
422429 public Capture (String type , int frameRate , int width , int height ) {
423430 this .type = type ;
@@ -427,7 +434,7 @@ public Capture(String type, int frameRate, int width, int height) {
427434 }
428435
429436 @ Override
430- public boolean equals (Object o ) {
437+ public boolean equals (@ Nullable Object o ) {
431438 if (this == o ) {
432439 return true ;
433440 }
@@ -445,7 +452,7 @@ public int hashCode() {
445452 }
446453
447454 @ Override
448- public String toString () {
455+ public @ NotNull String toString () {
449456 return "Capture{" +
450457 "type='" + type + '\'' +
451458 ", frameRate=" + frameRate +
0 commit comments