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