001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY
006
007package edu.wpi.first.networktables;
008
009import java.nio.ByteBuffer;
010
011/**
012 * NetworkTables Entry.
013 *
014 * <p>For backwards compatibility, the NetworkTableEntry close() does not release the entry.
015 */
016@SuppressWarnings("UnnecessaryParentheses")
017public final class NetworkTableEntry implements Publisher, Subscriber {
018  /**
019   * Flag values (as returned by {@link #getFlags()}).
020   *
021   * @deprecated Use isPersistent() instead.
022   */
023  @Deprecated(since = "2022", forRemoval = true)
024  public static final int kPersistent = 0x01;
025
026  /**
027   * Construct from native handle.
028   *
029   * @param inst Instance
030   * @param handle Native handle
031   */
032  public NetworkTableEntry(NetworkTableInstance inst, int handle) {
033    this(new Topic(inst, NetworkTablesJNI.getTopicFromHandle(handle)), handle);
034  }
035
036  /**
037   * Construct from native handle.
038   *
039   * @param topic Topic
040   * @param handle Native handle
041   */
042  public NetworkTableEntry(Topic topic, int handle) {
043    m_topic = topic;
044    m_handle = handle;
045  }
046
047  @Override
048  public void close() {}
049
050  /**
051   * Determines if the native handle is valid.
052   *
053   * @return True if the native handle is valid, false otherwise.
054   */
055  @Override
056  public boolean isValid() {
057    return m_handle != 0;
058  }
059
060  /**
061   * Gets the native handle for the entry.
062   *
063   * @return Native handle
064   */
065  @Override
066  public int getHandle() {
067    return m_handle;
068  }
069
070  /**
071   * Gets the subscribed-to / published-to topic.
072   *
073   * @return Topic
074   */
075  @Override
076  public Topic getTopic() {
077    return m_topic;
078  }
079
080  /**
081   * Gets the instance for the entry.
082   *
083   * @return Instance
084   */
085  public NetworkTableInstance getInstance() {
086    return m_topic.getInstance();
087  }
088
089  /**
090   * Determines if the entry currently exists.
091   *
092   * @return True if the entry exists, false otherwise.
093   */
094  @Override
095  public boolean exists() {
096    return NetworkTablesJNI.getType(m_handle) != 0;
097  }
098
099  /**
100   * Gets the name of the entry (the key).
101   *
102   * @return the entry's name
103   */
104  public String getName() {
105    return NetworkTablesJNI.getEntryName(m_handle);
106  }
107
108  /**
109   * Gets the type of the entry.
110   *
111   * @return the entry's type
112   */
113  public NetworkTableType getType() {
114    return NetworkTableType.getFromInt(NetworkTablesJNI.getType(m_handle));
115  }
116
117  /**
118   * Returns the flags.
119   *
120   * @return the flags (bitmask)
121   * @deprecated Use isPersistent() or topic properties instead
122   */
123  @Deprecated(since = "2022", forRemoval = true)
124  public int getFlags() {
125    return NetworkTablesJNI.getEntryFlags(m_handle);
126  }
127
128  /**
129   * Gets the last time the entry's value was changed.
130   *
131   * @return Entry last change time
132   */
133  @Override
134  public long getLastChange() {
135    return NetworkTablesJNI.getEntryLastChange(m_handle);
136  }
137
138  /**
139   * Gets the entry's value. Returns a value with type NetworkTableType.kUnassigned if the value
140   * does not exist.
141   *
142   * @return the entry's value
143   */
144  public NetworkTableValue getValue() {
145    return NetworkTablesJNI.getValue(m_handle);
146  }
147
148  /**
149   * Gets the entry's value as a boolean. If the entry does not exist or is of different type, it
150   * will return the default value.
151   *
152   * @param defaultValue the value to be returned if no value is found
153   * @return the entry's value or the given default value
154   */
155  public boolean getBoolean(boolean defaultValue) {
156    return NetworkTablesJNI.getBoolean(m_handle, defaultValue);
157  }
158
159  /**
160   * Gets the entry's value as a long. If the entry does not exist or is of different type, it
161   * will return the default value.
162   *
163   * @param defaultValue the value to be returned if no value is found
164   * @return the entry's value or the given default value
165   */
166  public long getInteger(long defaultValue) {
167    return NetworkTablesJNI.getInteger(m_handle, defaultValue);
168  }
169
170  /**
171   * Gets the entry's value as a float. If the entry does not exist or is of different type, it
172   * will return the default value.
173   *
174   * @param defaultValue the value to be returned if no value is found
175   * @return the entry's value or the given default value
176   */
177  public float getFloat(float defaultValue) {
178    return NetworkTablesJNI.getFloat(m_handle, defaultValue);
179  }
180
181  /**
182   * Gets the entry's value as a double. If the entry does not exist or is of different type, it
183   * will return the default value.
184   *
185   * @param defaultValue the value to be returned if no value is found
186   * @return the entry's value or the given default value
187   */
188  public double getDouble(double defaultValue) {
189    return NetworkTablesJNI.getDouble(m_handle, defaultValue);
190  }
191
192  /**
193   * Gets the entry's value as a String. If the entry does not exist or is of different type, it
194   * will return the default value.
195   *
196   * @param defaultValue the value to be returned if no value is found
197   * @return the entry's value or the given default value
198   */
199  public String getString(String defaultValue) {
200    return NetworkTablesJNI.getString(m_handle, defaultValue);
201  }
202
203  /**
204   * Gets the entry's value as a byte[]. If the entry does not exist or is of different type, it
205   * will return the default value.
206   *
207   * @param defaultValue the value to be returned if no value is found
208   * @return the entry's value or the given default value
209   */
210  public byte[] getRaw(byte[] defaultValue) {
211    return NetworkTablesJNI.getRaw(m_handle, defaultValue);
212  }
213
214  /**
215   * Gets the entry's value as a boolean[]. If the entry does not exist or is of different type, it
216   * will return the default value.
217   *
218   * @param defaultValue the value to be returned if no value is found
219   * @return the entry's value or the given default value
220   */
221  public boolean[] getBooleanArray(boolean[] defaultValue) {
222    return NetworkTablesJNI.getBooleanArray(m_handle, defaultValue);
223  }
224
225  /**
226   * Gets the entry's value as a boolean array. If the entry does not exist or is of different type,
227   * it will return the default value.
228   *
229   * @param defaultValue the value to be returned if no value is found
230   * @return the entry's value or the given default value
231   */
232  public Boolean[] getBooleanArray(Boolean[] defaultValue) {
233    return NetworkTableValue.fromNativeBooleanArray(
234        getBooleanArray(NetworkTableValue.toNativeBooleanArray(defaultValue)));
235  }
236
237  /**
238   * Gets the entry's value as a long[]. If the entry does not exist or is of different type, it
239   * will return the default value.
240   *
241   * @param defaultValue the value to be returned if no value is found
242   * @return the entry's value or the given default value
243   */
244  public long[] getIntegerArray(long[] defaultValue) {
245    return NetworkTablesJNI.getIntegerArray(m_handle, defaultValue);
246  }
247
248  /**
249   * Gets the entry's value as a boolean array. If the entry does not exist or is of different type,
250   * it will return the default value.
251   *
252   * @param defaultValue the value to be returned if no value is found
253   * @return the entry's value or the given default value
254   */
255  public Long[] getIntegerArray(Long[] defaultValue) {
256    return NetworkTableValue.fromNativeIntegerArray(
257        getIntegerArray(NetworkTableValue.toNativeIntegerArray(defaultValue)));
258  }
259
260  /**
261   * Gets the entry's value as a float[]. If the entry does not exist or is of different type, it
262   * will return the default value.
263   *
264   * @param defaultValue the value to be returned if no value is found
265   * @return the entry's value or the given default value
266   */
267  public float[] getFloatArray(float[] defaultValue) {
268    return NetworkTablesJNI.getFloatArray(m_handle, defaultValue);
269  }
270
271  /**
272   * Gets the entry's value as a boolean array. If the entry does not exist or is of different type,
273   * it will return the default value.
274   *
275   * @param defaultValue the value to be returned if no value is found
276   * @return the entry's value or the given default value
277   */
278  public Float[] getFloatArray(Float[] defaultValue) {
279    return NetworkTableValue.fromNativeFloatArray(
280        getFloatArray(NetworkTableValue.toNativeFloatArray(defaultValue)));
281  }
282
283  /**
284   * Gets the entry's value as a double[]. If the entry does not exist or is of different type, it
285   * will return the default value.
286   *
287   * @param defaultValue the value to be returned if no value is found
288   * @return the entry's value or the given default value
289   */
290  public double[] getDoubleArray(double[] defaultValue) {
291    return NetworkTablesJNI.getDoubleArray(m_handle, defaultValue);
292  }
293
294  /**
295   * Gets the entry's value as a boolean array. If the entry does not exist or is of different type,
296   * it will return the default value.
297   *
298   * @param defaultValue the value to be returned if no value is found
299   * @return the entry's value or the given default value
300   */
301  public Double[] getDoubleArray(Double[] defaultValue) {
302    return NetworkTableValue.fromNativeDoubleArray(
303        getDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue)));
304  }
305
306  /**
307   * Gets the entry's value as a String[]. If the entry does not exist or is of different type, it
308   * will return the default value.
309   *
310   * @param defaultValue the value to be returned if no value is found
311   * @return the entry's value or the given default value
312   */
313  public String[] getStringArray(String[] defaultValue) {
314    return NetworkTablesJNI.getStringArray(m_handle, defaultValue);
315  }
316
317  /**
318   * Gets the entry's value as a double. If the entry does not exist or is of different type, it
319   * will return the default value.
320   *
321   * @param defaultValue the value to be returned if no value is found
322   * @return the entry's value or the given default value
323   */
324  public Number getNumber(Number defaultValue) {
325    return getDouble(defaultValue.doubleValue());
326  }
327
328  /**
329   * Gets the entry's value as a double array. If the entry does not exist or is of different type,
330   * it will return the default value.
331   *
332   * @param defaultValue the value to be returned if no value is found
333   * @return the entry's value or the given default value
334   */
335  public Number[] getNumberArray(Number[] defaultValue) {
336    return NetworkTableValue.fromNativeDoubleArray(
337        getDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue)));
338  }
339
340  /**
341   * Get an array of all value changes since the last call to readQueue.
342   *
343   * <p>The "poll storage" subscribe option can be used to set the queue
344   * depth.
345   *
346   * @return Array of values; empty array if no new changes have been
347   *     published since the previous call.
348   */
349  public NetworkTableValue[] readQueue() {
350    return NetworkTablesJNI.readQueueValue(m_handle);
351  }
352
353  /**
354   * Checks if a data value is of a type that can be placed in a NetworkTable entry.
355   *
356   * @param data the data to check
357   * @return true if the data can be placed in an entry, false if it cannot
358   */
359  public static boolean isValidDataType(Object data) {
360    return data instanceof Number
361        || data instanceof Boolean
362        || data instanceof String
363        || data instanceof long[]
364        || data instanceof Long[]
365        || data instanceof float[]
366        || data instanceof Float[]
367        || data instanceof double[]
368        || data instanceof Double[]
369        || data instanceof Number[]
370        || data instanceof boolean[]
371        || data instanceof Boolean[]
372        || data instanceof String[]
373        || data instanceof byte[]
374        || data instanceof Byte[];
375  }
376
377  /**
378   * Sets the entry's value if it does not exist.
379   *
380   * @param defaultValue the default value to set
381   * @return False if the entry exists with a different type
382   * @throws IllegalArgumentException if the value is not a known type
383   */
384  public boolean setDefaultValue(Object defaultValue) {
385    if (defaultValue instanceof NetworkTableValue) {
386      long time = ((NetworkTableValue) defaultValue).getTime();
387      Object otherValue = ((NetworkTableValue) defaultValue).getValue();
388      switch (((NetworkTableValue) defaultValue).getType()) {
389        case kBoolean:
390          return NetworkTablesJNI.setDefaultBoolean(m_handle, time, (Boolean) otherValue);
391        case kInteger:
392          return NetworkTablesJNI.setDefaultInteger(
393              m_handle, time, ((Number) otherValue).longValue());
394        case kFloat:
395          return NetworkTablesJNI.setDefaultFloat(
396              m_handle, time, ((Number) otherValue).floatValue());
397        case kDouble:
398          return NetworkTablesJNI.setDefaultDouble(
399              m_handle, time, ((Number) otherValue).doubleValue());
400        case kString:
401          return NetworkTablesJNI.setDefaultString(m_handle, time, (String) otherValue);
402        case kRaw:
403          return NetworkTablesJNI.setDefaultRaw(m_handle, time, (byte[]) otherValue);
404        case kBooleanArray:
405          return NetworkTablesJNI.setDefaultBooleanArray(m_handle, time, (boolean[]) otherValue);
406        case kIntegerArray:
407          return NetworkTablesJNI.setDefaultIntegerArray(m_handle, time, (long[]) otherValue);
408        case kFloatArray:
409          return NetworkTablesJNI.setDefaultFloatArray(m_handle, time, (float[]) otherValue);
410        case kDoubleArray:
411          return NetworkTablesJNI.setDefaultDoubleArray(m_handle, time, (double[]) otherValue);
412        case kStringArray:
413          return NetworkTablesJNI.setDefaultStringArray(m_handle, time, (String[]) otherValue);
414        default:
415          return true;
416      }
417    } else if (defaultValue instanceof Boolean) {
418      return setDefaultBoolean((Boolean) defaultValue);
419    } else if (defaultValue instanceof Integer) {
420      return setDefaultInteger((Integer) defaultValue);
421    } else if (defaultValue instanceof Float) {
422      return setDefaultFloat((Float) defaultValue);
423    } else if (defaultValue instanceof Number) {
424      return setDefaultNumber((Number) defaultValue);
425    } else if (defaultValue instanceof String) {
426      return setDefaultString((String) defaultValue);
427    } else if (defaultValue instanceof byte[]) {
428      return setDefaultRaw((byte[]) defaultValue);
429    } else if (defaultValue instanceof boolean[]) {
430      return setDefaultBooleanArray((boolean[]) defaultValue);
431    } else if (defaultValue instanceof long[]) {
432      return setDefaultIntegerArray((long[]) defaultValue);
433    } else if (defaultValue instanceof float[]) {
434      return setDefaultFloatArray((float[]) defaultValue);
435    } else if (defaultValue instanceof double[]) {
436      return setDefaultDoubleArray((double[]) defaultValue);
437    } else if (defaultValue instanceof Boolean[]) {
438      return setDefaultBooleanArray((Boolean[]) defaultValue);
439    } else if (defaultValue instanceof Long[]) {
440      return setDefaultIntegerArray((Long[]) defaultValue);
441    } else if (defaultValue instanceof Float[]) {
442      return setDefaultFloatArray((Float[]) defaultValue);
443    } else if (defaultValue instanceof Number[]) {
444      return setDefaultNumberArray((Number[]) defaultValue);
445    } else if (defaultValue instanceof String[]) {
446      return setDefaultStringArray((String[]) defaultValue);
447    } else {
448      throw new IllegalArgumentException(
449          "Value of type " + defaultValue.getClass().getName() + " cannot be put into a table");
450    }
451  }
452
453  /**
454   * Sets the entry's value if it does not exist.
455   *
456   * @param defaultValue the default value to set
457   * @return False if the entry exists with a different type
458   */
459  public boolean setDefaultBoolean(boolean defaultValue) {
460    return NetworkTablesJNI.setDefaultBoolean(m_handle, 0, defaultValue);
461  }
462
463  /**
464   * Sets the entry's value if it does not exist.
465   *
466   * @param defaultValue the default value to set
467   * @return False if the entry exists with a different type
468   */
469  public boolean setDefaultInteger(long defaultValue) {
470    return NetworkTablesJNI.setDefaultInteger(m_handle, 0, defaultValue);
471  }
472
473  /**
474   * Sets the entry's value if it does not exist.
475   *
476   * @param defaultValue the default value to set
477   * @return False if the entry exists with a different type
478   */
479  public boolean setDefaultFloat(float defaultValue) {
480    return NetworkTablesJNI.setDefaultFloat(m_handle, 0, defaultValue);
481  }
482
483  /**
484   * Sets the entry's value if it does not exist.
485   *
486   * @param defaultValue the default value to set
487   * @return False if the entry exists with a different type
488   */
489  public boolean setDefaultDouble(double defaultValue) {
490    return NetworkTablesJNI.setDefaultDouble(m_handle, 0, defaultValue);
491  }
492
493  /**
494   * Sets the entry's value if it does not exist.
495   *
496   * @param defaultValue the default value to set
497   * @return False if the entry exists with a different type
498   */
499  public boolean setDefaultString(String defaultValue) {
500    return NetworkTablesJNI.setDefaultString(m_handle, 0, defaultValue);
501  }
502
503  /**
504   * Sets the entry's value if it does not exist.
505   *
506   * @param defaultValue the default value to set
507   * @return False if the entry exists with a different type
508   */
509  public boolean setDefaultRaw(byte[] defaultValue) {
510    return NetworkTablesJNI.setDefaultRaw(m_handle, 0, defaultValue);
511  }
512
513  /**
514   * Sets the entry's value if it does not exist.
515   *
516   * @param defaultValue the default value to set; will send from defaultValue.position() to
517   *                     defaultValue.capacity()
518   * @return False if the entry exists with a different type
519   */
520  public boolean setDefaultRaw(ByteBuffer defaultValue) {
521    return NetworkTablesJNI.setDefaultRaw(m_handle, 0, defaultValue);
522  }
523
524  /**
525   * Sets the entry's value if it does not exist.
526   *
527   * @param defaultValue the default value to set
528   * @param start Start position of data (in buffer)
529   * @param len Length of data (must be less than or equal to value.length - start)
530   * @return False if the entry exists with a different type
531   */
532  public boolean setDefaultRaw(byte[] defaultValue, int start, int len) {
533    return NetworkTablesJNI.setDefaultRaw(m_handle, 0, defaultValue, start, len);
534  }
535
536  /**
537   * Sets the entry's value if it does not exist.
538   *
539   * @param defaultValue the default value to set
540   * @param start Start position of data (in buffer)
541   * @param len Length of data (must be less than or equal to value.capacity() - start)
542   * @return False if the entry exists with a different type
543   */
544  public boolean setDefaultRaw(ByteBuffer defaultValue, int start, int len) {
545    return NetworkTablesJNI.setDefaultRaw(m_handle, 0, defaultValue, start, len);
546  }
547
548  /**
549   * Sets the entry's value if it does not exist.
550   *
551   * @param defaultValue the default value to set
552   * @return False if the entry exists with a different type
553   */
554  public boolean setDefaultBooleanArray(boolean[] defaultValue) {
555    return NetworkTablesJNI.setDefaultBooleanArray(m_handle, 0, defaultValue);
556  }
557
558  /**
559   * Sets the entry's value if it does not exist.
560   *
561   * @param defaultValue the default value to set
562   * @return False if the entry exists with a different type
563   */
564  public boolean setDefaultBooleanArray(Boolean[] defaultValue) {
565    return setDefaultBooleanArray(NetworkTableValue.toNativeBooleanArray(defaultValue));
566  }
567
568  /**
569   * Sets the entry's value if it does not exist.
570   *
571   * @param defaultValue the default value to set
572   * @return False if the entry exists with a different type
573   */
574  public boolean setDefaultIntegerArray(long[] defaultValue) {
575    return NetworkTablesJNI.setDefaultIntegerArray(m_handle, 0, defaultValue);
576  }
577
578  /**
579   * Sets the entry's value if it does not exist.
580   *
581   * @param defaultValue the default value to set
582   * @return False if the entry exists with a different type
583   */
584  public boolean setDefaultIntegerArray(Long[] defaultValue) {
585    return setDefaultIntegerArray(NetworkTableValue.toNativeIntegerArray(defaultValue));
586  }
587
588  /**
589   * Sets the entry's value if it does not exist.
590   *
591   * @param defaultValue the default value to set
592   * @return False if the entry exists with a different type
593   */
594  public boolean setDefaultFloatArray(float[] defaultValue) {
595    return NetworkTablesJNI.setDefaultFloatArray(m_handle, 0, defaultValue);
596  }
597
598  /**
599   * Sets the entry's value if it does not exist.
600   *
601   * @param defaultValue the default value to set
602   * @return False if the entry exists with a different type
603   */
604  public boolean setDefaultFloatArray(Float[] defaultValue) {
605    return setDefaultFloatArray(NetworkTableValue.toNativeFloatArray(defaultValue));
606  }
607
608  /**
609   * Sets the entry's value if it does not exist.
610   *
611   * @param defaultValue the default value to set
612   * @return False if the entry exists with a different type
613   */
614  public boolean setDefaultDoubleArray(double[] defaultValue) {
615    return NetworkTablesJNI.setDefaultDoubleArray(m_handle, 0, defaultValue);
616  }
617
618  /**
619   * Sets the entry's value if it does not exist.
620   *
621   * @param defaultValue the default value to set
622   * @return False if the entry exists with a different type
623   */
624  public boolean setDefaultDoubleArray(Double[] defaultValue) {
625    return setDefaultDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue));
626  }
627
628  /**
629   * Sets the entry's value if it does not exist.
630   *
631   * @param defaultValue the default value to set
632   * @return False if the entry exists with a different type
633   */
634  public boolean setDefaultStringArray(String[] defaultValue) {
635    return NetworkTablesJNI.setDefaultStringArray(m_handle, 0, defaultValue);
636  }
637
638  /**
639   * Sets the entry's value if it does not exist.
640   *
641   * @param defaultValue the default value to set
642   * @return False if the entry exists with a different type
643   */
644  public boolean setDefaultNumber(Number defaultValue) {
645    return setDefaultDouble(defaultValue.doubleValue());
646  }
647
648  /**
649   * Sets the entry's value if it does not exist.
650   *
651   * @param defaultValue the default value to set
652   * @return False if the entry exists with a different type
653   */
654  public boolean setDefaultNumberArray(Number[] defaultValue) {
655    return setDefaultDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue));
656  }
657
658  /**
659   * Sets the entry's value.
660   *
661   * @param value the value that will be assigned
662   * @return False if the table key already exists with a different type
663   * @throws IllegalArgumentException if the value is not a known type
664   */
665  public boolean setValue(Object value) {
666    if (value instanceof NetworkTableValue) {
667      long time = ((NetworkTableValue) value).getTime();
668      Object otherValue = ((NetworkTableValue) value).getValue();
669      switch (((NetworkTableValue) value).getType()) {
670        case kBoolean:
671          return NetworkTablesJNI.setBoolean(m_handle, time, (Boolean) otherValue);
672        case kInteger:
673          return NetworkTablesJNI.setInteger(
674              m_handle, time, ((Number) otherValue).longValue());
675        case kFloat:
676          return NetworkTablesJNI.setFloat(
677              m_handle, time, ((Number) otherValue).floatValue());
678        case kDouble:
679          return NetworkTablesJNI.setDouble(
680              m_handle, time, ((Number) otherValue).doubleValue());
681        case kString:
682          return NetworkTablesJNI.setString(m_handle, time, (String) otherValue);
683        case kRaw:
684          return NetworkTablesJNI.setRaw(m_handle, time, (byte[]) otherValue);
685        case kBooleanArray:
686          return NetworkTablesJNI.setBooleanArray(m_handle, time, (boolean[]) otherValue);
687        case kIntegerArray:
688          return NetworkTablesJNI.setIntegerArray(m_handle, time, (long[]) otherValue);
689        case kFloatArray:
690          return NetworkTablesJNI.setFloatArray(m_handle, time, (float[]) otherValue);
691        case kDoubleArray:
692          return NetworkTablesJNI.setDoubleArray(m_handle, time, (double[]) otherValue);
693        case kStringArray:
694          return NetworkTablesJNI.setStringArray(m_handle, time, (String[]) otherValue);
695        default:
696          return true;
697      }
698    } else if (value instanceof Boolean) {
699      return setBoolean((Boolean) value);
700    } else if (value instanceof Long) {
701      return setInteger((Long) value);
702    } else if (value instanceof Float) {
703      return setFloat((Float) value);
704    } else if (value instanceof Number) {
705      return setNumber((Number) value);
706    } else if (value instanceof String) {
707      return setString((String) value);
708    } else if (value instanceof byte[]) {
709      return setRaw((byte[]) value);
710    } else if (value instanceof boolean[]) {
711      return setBooleanArray((boolean[]) value);
712    } else if (value instanceof long[]) {
713      return setIntegerArray((long[]) value);
714    } else if (value instanceof float[]) {
715      return setFloatArray((float[]) value);
716    } else if (value instanceof double[]) {
717      return setDoubleArray((double[]) value);
718    } else if (value instanceof Boolean[]) {
719      return setBooleanArray((Boolean[]) value);
720    } else if (value instanceof Long[]) {
721      return setIntegerArray((Long[]) value);
722    } else if (value instanceof Float[]) {
723      return setFloatArray((Float[]) value);
724    } else if (value instanceof Number[]) {
725      return setNumberArray((Number[]) value);
726    } else if (value instanceof String[]) {
727      return setStringArray((String[]) value);
728    } else {
729      throw new IllegalArgumentException(
730          "Value of type " + value.getClass().getName() + " cannot be put into a table");
731    }
732  }
733
734  /**
735   * Sets the entry's value.
736   *
737   * @param value the value to set
738   * @return False if the entry exists with a different type
739   */
740  public boolean setBoolean(boolean value) {
741    return NetworkTablesJNI.setBoolean(m_handle, 0, value);
742  }
743
744  /**
745   * Sets the entry's value.
746   *
747   * @param value the value to set
748   * @return False if the entry exists with a different type
749   */
750  public boolean setInteger(long value) {
751    return NetworkTablesJNI.setInteger(m_handle, 0, value);
752  }
753
754  /**
755   * Sets the entry's value.
756   *
757   * @param value the value to set
758   * @return False if the entry exists with a different type
759   */
760  public boolean setFloat(float value) {
761    return NetworkTablesJNI.setFloat(m_handle, 0, value);
762  }
763
764  /**
765   * Sets the entry's value.
766   *
767   * @param value the value to set
768   * @return False if the entry exists with a different type
769   */
770  public boolean setDouble(double value) {
771    return NetworkTablesJNI.setDouble(m_handle, 0, value);
772  }
773
774  /**
775   * Sets the entry's value.
776   *
777   * @param value the value to set
778   * @return False if the entry exists with a different type
779   */
780  public boolean setString(String value) {
781    return NetworkTablesJNI.setString(m_handle, 0, value);
782  }
783
784  /**
785   * Sets the entry's value.
786   *
787   * @param value the value to set
788   * @return False if the entry exists with a different type
789   */
790  public boolean setRaw(byte[] value) {
791    return NetworkTablesJNI.setRaw(m_handle, 0, value);
792  }
793
794  /**
795   * Sets the entry's value.
796   *
797   * @param value the value to set; will send from value.position() to value.capacity()
798   * @return False if the entry exists with a different type
799   */
800  public boolean setRaw(ByteBuffer value) {
801    return NetworkTablesJNI.setRaw(m_handle, 0, value);
802  }
803
804  /**
805   * Sets the entry's value.
806   *
807   * @param value the value to set
808   * @param start Start position of data (in buffer)
809   * @param len Length of data (must be less than or equal to value.length - start)
810   * @return False if the entry exists with a different type
811   */
812  public boolean setRaw(byte[] value, int start, int len) {
813    return NetworkTablesJNI.setRaw(m_handle, 0, value, start, len);
814  }
815
816  /**
817   * Sets the entry's value.
818   *
819   * @param value the value to set
820   * @param start Start position of data (in buffer)
821   * @param len Length of data (must be less than or equal to value.capacity() - start)
822   * @return False if the entry exists with a different type
823   */
824  public boolean setRaw(ByteBuffer value, int start, int len) {
825    return NetworkTablesJNI.setRaw(m_handle, 0, value, start, len);
826  }
827
828  /**
829   * Sets the entry's value.
830   *
831   * @param value the value to set
832   * @return False if the entry exists with a different type
833   */
834  public boolean setBooleanArray(boolean[] value) {
835    return NetworkTablesJNI.setBooleanArray(m_handle, 0, value);
836  }
837
838  /**
839   * Sets the entry's value.
840   *
841   * @param value the value to set
842   * @return False if the entry exists with a different type
843   */
844  public boolean setBooleanArray(Boolean[] value) {
845    return setBooleanArray(NetworkTableValue.toNativeBooleanArray(value));
846  }
847
848  /**
849   * Sets the entry's value.
850   *
851   * @param value the value to set
852   * @return False if the entry exists with a different type
853   */
854  public boolean setIntegerArray(long[] value) {
855    return NetworkTablesJNI.setIntegerArray(m_handle, 0, value);
856  }
857
858  /**
859   * Sets the entry's value.
860   *
861   * @param value the value to set
862   * @return False if the entry exists with a different type
863   */
864  public boolean setIntegerArray(Long[] value) {
865    return setIntegerArray(NetworkTableValue.toNativeIntegerArray(value));
866  }
867
868  /**
869   * Sets the entry's value.
870   *
871   * @param value the value to set
872   * @return False if the entry exists with a different type
873   */
874  public boolean setFloatArray(float[] value) {
875    return NetworkTablesJNI.setFloatArray(m_handle, 0, value);
876  }
877
878  /**
879   * Sets the entry's value.
880   *
881   * @param value the value to set
882   * @return False if the entry exists with a different type
883   */
884  public boolean setFloatArray(Float[] value) {
885    return setFloatArray(NetworkTableValue.toNativeFloatArray(value));
886  }
887
888  /**
889   * Sets the entry's value.
890   *
891   * @param value the value to set
892   * @return False if the entry exists with a different type
893   */
894  public boolean setDoubleArray(double[] value) {
895    return NetworkTablesJNI.setDoubleArray(m_handle, 0, value);
896  }
897
898  /**
899   * Sets the entry's value.
900   *
901   * @param value the value to set
902   * @return False if the entry exists with a different type
903   */
904  public boolean setDoubleArray(Double[] value) {
905    return setDoubleArray(NetworkTableValue.toNativeDoubleArray(value));
906  }
907
908  /**
909   * Sets the entry's value.
910   *
911   * @param value the value to set
912   * @return False if the entry exists with a different type
913   */
914  public boolean setStringArray(String[] value) {
915    return NetworkTablesJNI.setStringArray(m_handle, 0, value);
916  }
917
918  /**
919   * Sets the entry's value.
920   *
921   * @param value the value to set
922   * @return False if the entry exists with a different type
923   */
924  public boolean setNumber(Number value) {
925    return setDouble(value.doubleValue());
926  }
927
928  /**
929   * Sets the entry's value.
930   *
931   * @param value the value to set
932   * @return False if the entry exists with a different type
933   */
934  public boolean setNumberArray(Number[] value) {
935    return setDoubleArray(NetworkTableValue.toNativeDoubleArray(value));
936  }
937
938  /**
939   * Sets flags.
940   *
941   * @param flags the flags to set (bitmask)
942   * @deprecated Use setPersistent() or topic properties instead
943   */
944  @Deprecated(since = "2022", forRemoval = true)
945  public void setFlags(int flags) {
946    NetworkTablesJNI.setEntryFlags(m_handle, getFlags() | flags);
947  }
948
949  /**
950   * Clears flags.
951   *
952   * @param flags the flags to clear (bitmask)
953   * @deprecated Use setPersistent() or topic properties instead
954   */
955  @Deprecated(since = "2022", forRemoval = true)
956  public void clearFlags(int flags) {
957    NetworkTablesJNI.setEntryFlags(m_handle, getFlags() & ~flags);
958  }
959
960  /** Make value persistent through program restarts. */
961  public void setPersistent() {
962    NetworkTablesJNI.setTopicPersistent(m_topic.getHandle(), true);
963  }
964
965  /** Stop making value persistent through program restarts. */
966  public void clearPersistent() {
967    NetworkTablesJNI.setTopicPersistent(m_topic.getHandle(), false);
968  }
969
970  /**
971   * Returns whether the value is persistent through program restarts.
972   *
973   * @return True if the value is persistent.
974   */
975  public boolean isPersistent() {
976    return NetworkTablesJNI.getTopicPersistent(m_topic.getHandle());
977  }
978
979  /** Stops publishing the entry if it's been published. */
980  public void unpublish() {
981    NetworkTablesJNI.unpublish(m_handle);
982  }
983
984  /**
985   * Deletes the entry.
986   *
987   * @deprecated Use unpublish() instead.
988   */
989  @Deprecated(since = "2022", forRemoval = true)
990  public void delete() {
991    unpublish();
992  }
993
994  @Override
995  public boolean equals(Object other) {
996    if (other == this) {
997      return true;
998    }
999    if (!(other instanceof NetworkTableEntry)) {
1000      return false;
1001    }
1002
1003    return m_handle == ((NetworkTableEntry) other).m_handle;
1004  }
1005
1006  @Override
1007  public int hashCode() {
1008    return m_handle;
1009  }
1010
1011  private final Topic m_topic;
1012  private final int m_handle;
1013}