edu.wpi.first.wpilibj.networktables
Class NetworkTable

java.lang.Object
  extended by edu.wpi.first.wpilibj.networktables.NetworkTable

public class NetworkTable
extends java.lang.Object

Author:
Joe Grinstead

Constructor Summary
NetworkTable()
          Creates a new NetworkTable.
 
Method Summary
 void addAdditionListener(NetworkAdditionListener listener)
          Adds the NetworkAdditionListener to the table.
 void addConnectionListener(NetworkConnectionListener listener, boolean immediateNotify)
          Adds a NetworkConnectionListener to this table.
 void addListener(java.lang.String key, NetworkListener listener)
          Adds a NetworkListener to listen to the specified element.
 void addListenerToAll(NetworkListener listener)
           
 void beginTransaction()
          Begins a transaction.
 boolean containsKey(java.lang.String key)
          Returns whether or not there is a value mapped to the given key
 void endTransaction()
           
 boolean getBoolean(java.lang.String key)
          Returns the value at the specified key.
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Returns the value at the specified key.
 double getDouble(java.lang.String key)
          Returns the value at the specified key.
 double getDouble(java.lang.String key, double defaultValue)
          Returns the value at the specified key.
 int getInt(java.lang.String key)
          Returns the value at the specified key.
 int getInt(java.lang.String key, int defaultValue)
          Returns the value at the specified key.
 java.util.Vector getKeys()
          Returns a vector of the keys for this table.
 java.lang.String getString(java.lang.String key)
          Returns the value at the specified key.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Returns the value at the specified key.
 NetworkTable getSubTable(java.lang.String key)
          Returns the value at the specified key.
static NetworkTable getTable(java.lang.String name)
          Returns the table with the given name.
 java.lang.Object getValue(java.lang.String key)
          Returns the value at the specified key.
static void initialize()
          Opens up the connection stream.
 boolean isConnected()
          Returns whether or not this table is connected to the robot.
 void putBoolean(java.lang.String key, boolean value)
          Maps the specified key to the specified value in this table.
 void putDouble(java.lang.String key, double value)
          Maps the specified key to the specified value in this table.
 void putInt(java.lang.String key, int value)
          Maps the specified key to the specified value in this table.
 void putString(java.lang.String key, java.lang.String value)
          Maps the specified key to the specified value in this table.
 void putSubTable(java.lang.String key, NetworkTable value)
          Maps the specified key to the specified value in this table.
 void removeAdditionListener(NetworkAdditionListener listener)
          Removes the given NetworkAdditionListener from the set of listeners.
 void removeConnectionListener(NetworkConnectionListener listener)
          Removes the given NetworkConnectionListener from the table.
 void removeListener(java.lang.String key, NetworkListener listener)
          Removes the given NetworkListener from the specified element.
 void removeListenerFromAll(NetworkListener listener)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetworkTable

public NetworkTable()
Creates a new NetworkTable.

Method Detail

initialize

public static void initialize()
Opens up the connection stream. Note that this method will be called automatically when getTable(java.lang.String) is called. This will only have an effect the first time this is called.


getTable

public static NetworkTable getTable(java.lang.String name)
Returns the table with the given name. The table will automatically be connected by clients asking for the same table.

Parameters:
name - the name of the table
Returns:
the table
Throws:
NoTeamNumberException - if setTeam(...) has not yet been called

beginTransaction

public void beginTransaction()
Begins a transaction. Note that you must call endTransaction() afterwards.


endTransaction

public void endTransaction()

getKeys

public java.util.Vector getKeys()
Returns a vector of the keys for this table. The vector will not stay updated, and is in fact completely detached. It is a Vector of strings. from the table.

Returns:
a vector of the keys for this table

putInt

public void putInt(java.lang.String key,
                   int value)
Maps the specified key to the specified value in this table. The key can not be null. The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
key - the key
value - the value
Throws:
java.lang.IllegalArgumentException - if key is null

putBoolean

public void putBoolean(java.lang.String key,
                       boolean value)
Maps the specified key to the specified value in this table. The key can not be null. The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
key - the key
value - the value
Throws:
java.lang.IllegalArgumentException - if key is null

putDouble

public void putDouble(java.lang.String key,
                      double value)
Maps the specified key to the specified value in this table. The key can not be null. The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
key - the key
value - the value
Throws:
java.lang.IllegalArgumentException - if key is null

putString

public void putString(java.lang.String key,
                      java.lang.String value)
Maps the specified key to the specified value in this table. Neither the key nor the value can be null. The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
key - the key
value - the value
Throws:
java.lang.IllegalArgumentException - if key or value is null

putSubTable

public void putSubTable(java.lang.String key,
                        NetworkTable value)
Maps the specified key to the specified value in this table. Neither the key nor the value can be null. The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
key - the key
value - the value
Throws:
java.lang.IllegalArgumentException - if key or value is null

addListener

public void addListener(java.lang.String key,
                        NetworkListener listener)
Adds a NetworkListener to listen to the specified element.

Parameters:
key - the key to listen to
listener - the listener
See Also:
NetworkListener

addListenerToAll

public void addListenerToAll(NetworkListener listener)

removeListener

public void removeListener(java.lang.String key,
                           NetworkListener listener)
Removes the given NetworkListener from the specified element. Note that setting the key to NetworkTable.ALL will only remove the listener from listening in the all category. It will not remove that listener from every category it is listening to

Parameters:
key - the key to no longer listen to (or NetworkTable.ALL).
listener - the listener to remove
See Also:
NetworkListener

removeListenerFromAll

public void removeListenerFromAll(NetworkListener listener)

addAdditionListener

public void addAdditionListener(NetworkAdditionListener listener)
Adds the NetworkAdditionListener to the table.

Parameters:
listener - the listener to add
See Also:
NetworkAdditionListener

removeAdditionListener

public void removeAdditionListener(NetworkAdditionListener listener)
Removes the given NetworkAdditionListener from the set of listeners.

Parameters:
listener - the listener to remove
See Also:
NetworkAdditionListener

addConnectionListener

public void addConnectionListener(NetworkConnectionListener listener,
                                  boolean immediateNotify)
Adds a NetworkConnectionListener to this table.

Parameters:
listener - the listener to add
immediateNotify - whether to tell the listener of the current connection status
See Also:
NetworkConnectionListener

removeConnectionListener

public void removeConnectionListener(NetworkConnectionListener listener)
Removes the given NetworkConnectionListener from the table.

Parameters:
listener - the listener to remove
See Also:
NetworkConnectionListener

getValue

public java.lang.Object getValue(java.lang.String key)
                          throws NetworkTableKeyNotDefined
Returns the value at the specified key. It will be an object wrapper around the actual value. For instance, if there is a double at the position, this will return a Double.

Parameters:
key - the key
Returns:
the value
Throws:
NetworkTableKeyNotDefined - if there is no value mapped to by the key
java.lang.IllegalArgumentException - if the key is null

getInt

public int getInt(java.lang.String key)
           throws NetworkTableKeyNotDefined
Returns the value at the specified key.

Parameters:
key - the key
Returns:
the value
Throws:
NetworkTableKeyNotDefined - if there is no value mapped to by the key
java.lang.IllegalArgumentException - if the value mapped to by the key is not an int
java.lang.IllegalArgumentException - if the key is null

getDouble

public double getDouble(java.lang.String key)
                 throws NetworkTableKeyNotDefined
Returns the value at the specified key.

Parameters:
key - the key
Returns:
the value
Throws:
NetworkTableKeyNotDefined - if there is no value mapped to by the key
java.lang.IllegalArgumentException - if the value mapped to by the key is not a double
java.lang.IllegalArgumentException - if the key is null

getString

public java.lang.String getString(java.lang.String key)
                           throws NetworkTableKeyNotDefined
Returns the value at the specified key.

Parameters:
key - the key
Returns:
the value
Throws:
NetworkTableKeyNotDefined - if there is no value mapped to by the key
java.lang.IllegalArgumentException - if the value mapped to by the key is not a string
java.lang.IllegalArgumentException - if the key is null

getSubTable

public NetworkTable getSubTable(java.lang.String key)
                         throws NetworkTableKeyNotDefined
Returns the value at the specified key.

Parameters:
key - the key
Returns:
the value
Throws:
NetworkTableKeyNotDefined - if there is no value mapped to by the key
java.lang.IllegalArgumentException - if the value mapped to by the key is not a string
java.lang.IllegalArgumentException - if the key is null

getBoolean

public boolean getBoolean(java.lang.String key)
                   throws NetworkTableKeyNotDefined
Returns the value at the specified key.

Parameters:
key - the key
Returns:
the value
Throws:
NetworkTableKeyNotDefined - if there is no value mapped to by the key
java.lang.IllegalArgumentException - if the value mapped to by the key is not a boolean
java.lang.IllegalArgumentException - if the key is null

getInt

public int getInt(java.lang.String key,
                  int defaultValue)
Returns the value at the specified key.

Parameters:
key - the key
defaultValue - The value returned if the key is undefined
Returns:
the value
Throws:
NetworkTableKeyNotDefined - if there is no value mapped to by the key
java.lang.IllegalArgumentException - if the value mapped to by the key is not an int
java.lang.IllegalArgumentException - if the key is null

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
Returns the value at the specified key.

Parameters:
key - the key
defaultValue - the value returned if the key is undefined
Returns:
the value
Throws:
NetworkTableKeyNotDefined - if there is no value mapped to by the key
java.lang.IllegalArgumentException - if the value mapped to by the key is not a double
java.lang.IllegalArgumentException - if the key is null

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
Returns the value at the specified key.

Parameters:
key - the key
defaultValue - the value returned if the key is undefined
Returns:
the value
Throws:
NetworkTableKeyNotDefined - if there is no value mapped to by the key
java.lang.IllegalArgumentException - if the value mapped to by the key is not a string
java.lang.IllegalArgumentException - if the key is null

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
Returns the value at the specified key.

Parameters:
key - the key
Returns:
the value
Throws:
NetworkTableKeyNotDefined - if there is no value mapped to by the key
java.lang.IllegalArgumentException - if the value mapped to by the key is not a boolean
java.lang.IllegalArgumentException - if the key is null

isConnected

public boolean isConnected()
Returns whether or not this table is connected to the robot.

Returns:
whether or not this table is connected to the robot

containsKey

public boolean containsKey(java.lang.String key)
Returns whether or not there is a value mapped to the given key

Parameters:
key - the key
Returns:
if there is a value