Class NetworkTableEntry

java.lang.Object
edu.wpi.first.networktables.NetworkTableEntry
All Implemented Interfaces:
Publisher, PubSub, Subscriber, AutoCloseable

public final class NetworkTableEntry
extends Object
implements Publisher, Subscriber
NetworkTables Entry.

For backwards compatibility, the NetworkTableEntry close() does not release the entry.

  • Field Details

  • Constructor Details

  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface PubSub
    • isValid

      public boolean isValid()
      Determines if the native handle is valid.
      Specified by:
      isValid in interface PubSub
      Returns:
      True if the native handle is valid, false otherwise.
    • getHandle

      public int getHandle()
      Gets the native handle for the entry.
      Specified by:
      getHandle in interface PubSub
      Returns:
      Native handle
    • getTopic

      public Topic getTopic()
      Gets the subscribed-to / published-to topic.
      Specified by:
      getTopic in interface PubSub
      Returns:
      Topic
    • getInstance

      Gets the instance for the entry.
      Returns:
      Instance
    • exists

      public boolean exists()
      Determines if the entry currently exists.
      Specified by:
      exists in interface Subscriber
      Returns:
      True if the entry exists, false otherwise.
    • getName

      public String getName()
      Gets the name of the entry (the key).
      Returns:
      the entry's name
    • getType

      Gets the type of the entry.
      Returns:
      the entry's type
    • getFlags

      @Deprecated(since="2022", forRemoval=true) public int getFlags()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use isPersistent() or topic properties instead
      Returns the flags.
      Returns:
      the flags (bitmask)
    • getLastChange

      public long getLastChange()
      Gets the last time the entry's value was changed.
      Specified by:
      getLastChange in interface Subscriber
      Returns:
      Entry last change time
    • getValue

      Gets the entry's value. Returns a value with type NetworkTableType.kUnassigned if the value does not exist.
      Returns:
      the entry's value
    • getBoolean

      public boolean getBoolean​(boolean defaultValue)
      Gets the entry's value as a boolean. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getInteger

      public long getInteger​(long defaultValue)
      Gets the entry's value as a long. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getFloat

      public float getFloat​(float defaultValue)
      Gets the entry's value as a float. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getDouble

      public double getDouble​(double defaultValue)
      Gets the entry's value as a double. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getString

      public String getString​(String defaultValue)
      Gets the entry's value as a String. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getRaw

      public byte[] getRaw​(byte[] defaultValue)
      Gets the entry's value as a byte[]. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getBooleanArray

      public boolean[] getBooleanArray​(boolean[] defaultValue)
      Gets the entry's value as a boolean[]. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getBooleanArray

      public Boolean[] getBooleanArray​(Boolean[] defaultValue)
      Gets the entry's value as a boolean array. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getIntegerArray

      public long[] getIntegerArray​(long[] defaultValue)
      Gets the entry's value as a long[]. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getIntegerArray

      public Long[] getIntegerArray​(Long[] defaultValue)
      Gets the entry's value as a boolean array. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getFloatArray

      public float[] getFloatArray​(float[] defaultValue)
      Gets the entry's value as a float[]. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getFloatArray

      public Float[] getFloatArray​(Float[] defaultValue)
      Gets the entry's value as a boolean array. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getDoubleArray

      public double[] getDoubleArray​(double[] defaultValue)
      Gets the entry's value as a double[]. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getDoubleArray

      public Double[] getDoubleArray​(Double[] defaultValue)
      Gets the entry's value as a boolean array. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getStringArray

      public String[] getStringArray​(String[] defaultValue)
      Gets the entry's value as a String[]. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getNumber

      public Number getNumber​(Number defaultValue)
      Gets the entry's value as a double. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • getNumberArray

      public Number[] getNumberArray​(Number[] defaultValue)
      Gets the entry's value as a double array. If the entry does not exist or is of different type, it will return the default value.
      Parameters:
      defaultValue - the value to be returned if no value is found
      Returns:
      the entry's value or the given default value
    • readQueue

      Get an array of all value changes since the last call to readQueue.

      The "poll storage" subscribe option can be used to set the queue depth.

      Returns:
      Array of values; empty array if no new changes have been published since the previous call.
    • isValidDataType

      public static boolean isValidDataType​(Object data)
      Checks if a data value is of a type that can be placed in a NetworkTable entry.
      Parameters:
      data - the data to check
      Returns:
      true if the data can be placed in an entry, false if it cannot
    • setDefaultValue

      public boolean setDefaultValue​(Object defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
      Throws:
      IllegalArgumentException - if the value is not a known type
    • setDefaultBoolean

      public boolean setDefaultBoolean​(boolean defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultInteger

      public boolean setDefaultInteger​(long defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultFloat

      public boolean setDefaultFloat​(float defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultDouble

      public boolean setDefaultDouble​(double defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultString

      public boolean setDefaultString​(String defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultRaw

      public boolean setDefaultRaw​(byte[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultRaw

      public boolean setDefaultRaw​(ByteBuffer defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set; will send from defaultValue.position() to defaultValue.capacity()
      Returns:
      False if the entry exists with a different type
    • setDefaultRaw

      public boolean setDefaultRaw​(byte[] defaultValue, int start, int len)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      start - Start position of data (in buffer)
      len - Length of data (must be less than or equal to value.length - start)
      Returns:
      False if the entry exists with a different type
    • setDefaultRaw

      public boolean setDefaultRaw​(ByteBuffer defaultValue, int start, int len)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      start - Start position of data (in buffer)
      len - Length of data (must be less than or equal to value.capacity() - start)
      Returns:
      False if the entry exists with a different type
    • setDefaultBooleanArray

      public boolean setDefaultBooleanArray​(boolean[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultBooleanArray

      public boolean setDefaultBooleanArray​(Boolean[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultIntegerArray

      public boolean setDefaultIntegerArray​(long[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultIntegerArray

      public boolean setDefaultIntegerArray​(Long[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultFloatArray

      public boolean setDefaultFloatArray​(float[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultFloatArray

      public boolean setDefaultFloatArray​(Float[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultDoubleArray

      public boolean setDefaultDoubleArray​(double[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultDoubleArray

      public boolean setDefaultDoubleArray​(Double[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultStringArray

      public boolean setDefaultStringArray​(String[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultNumber

      public boolean setDefaultNumber​(Number defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setDefaultNumberArray

      public boolean setDefaultNumberArray​(Number[] defaultValue)
      Sets the entry's value if it does not exist.
      Parameters:
      defaultValue - the default value to set
      Returns:
      False if the entry exists with a different type
    • setValue

      public boolean setValue​(Object value)
      Sets the entry's value.
      Parameters:
      value - the value that will be assigned
      Returns:
      False if the table key already exists with a different type
      Throws:
      IllegalArgumentException - if the value is not a known type
    • setBoolean

      public boolean setBoolean​(boolean value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setInteger

      public boolean setInteger​(long value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setFloat

      public boolean setFloat​(float value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setDouble

      public boolean setDouble​(double value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setString

      public boolean setString​(String value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setRaw

      public boolean setRaw​(byte[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setRaw

      public boolean setRaw​(ByteBuffer value)
      Sets the entry's value.
      Parameters:
      value - the value to set; will send from value.position() to value.capacity()
      Returns:
      False if the entry exists with a different type
    • setRaw

      public boolean setRaw​(byte[] value, int start, int len)
      Sets the entry's value.
      Parameters:
      value - the value to set
      start - Start position of data (in buffer)
      len - Length of data (must be less than or equal to value.length - start)
      Returns:
      False if the entry exists with a different type
    • setRaw

      public boolean setRaw​(ByteBuffer value, int start, int len)
      Sets the entry's value.
      Parameters:
      value - the value to set
      start - Start position of data (in buffer)
      len - Length of data (must be less than or equal to value.capacity() - start)
      Returns:
      False if the entry exists with a different type
    • setBooleanArray

      public boolean setBooleanArray​(boolean[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setBooleanArray

      public boolean setBooleanArray​(Boolean[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setIntegerArray

      public boolean setIntegerArray​(long[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setIntegerArray

      public boolean setIntegerArray​(Long[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setFloatArray

      public boolean setFloatArray​(float[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setFloatArray

      public boolean setFloatArray​(Float[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setDoubleArray

      public boolean setDoubleArray​(double[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setDoubleArray

      public boolean setDoubleArray​(Double[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setStringArray

      public boolean setStringArray​(String[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setNumber

      public boolean setNumber​(Number value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setNumberArray

      public boolean setNumberArray​(Number[] value)
      Sets the entry's value.
      Parameters:
      value - the value to set
      Returns:
      False if the entry exists with a different type
    • setFlags

      @Deprecated(since="2022", forRemoval=true) public void setFlags​(int flags)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use setPersistent() or topic properties instead
      Sets flags.
      Parameters:
      flags - the flags to set (bitmask)
    • clearFlags

      @Deprecated(since="2022", forRemoval=true) public void clearFlags​(int flags)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use setPersistent() or topic properties instead
      Clears flags.
      Parameters:
      flags - the flags to clear (bitmask)
    • setPersistent

      public void setPersistent()
      Make value persistent through program restarts.
    • clearPersistent

      public void clearPersistent()
      Stop making value persistent through program restarts.
    • isPersistent

      public boolean isPersistent()
      Returns whether the value is persistent through program restarts.
      Returns:
      True if the value is persistent.
    • unpublish

      public void unpublish()
      Stops publishing the entry if it's been published.
    • delete

      @Deprecated(since="2022", forRemoval=true) public void delete()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use unpublish() instead.
      Deletes the entry.
    • equals

      public boolean equals​(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object