"

2013 FRC Java API

"

edu.wpi.first.wpilibj.networktables
Class NetworkTable

java.lang.Object
  extended by edu.wpi.first.wpilibj.networktables.NetworkTable
All Implemented Interfaces:
IRemote, ITable

public class NetworkTable
extends Object
implements ITable, IRemote

Author:
Fredric, mwills

Field Summary
static int DEFAULT_PORT
          The default port that network tables operates on
static char PATH_SEPARATOR
          The path separator for sub-tables and keys
 
Method Summary
 void addConnectionListener(IRemoteConnectionListener listener, boolean immediateNotify)
          Register an object to listen for connection and disconnection events
 void addSubTableListener(ITableListener listener)
          This will immediately notify the listener of all current sub tables
 void addTableListener(ITableListener listener)
          Add a listener for changes to the table
 void addTableListener(ITableListener listener, boolean immediateNotify)
          Add a listener for changes to the table
 void addTableListener(String key, ITableListener listener, boolean immediateNotify)
          Add a listener for changes to a specific key the table
 boolean containsKey(String key)
          Checks the table and tells if it contains the specified key
 boolean containsSubTable(String key)
           
 boolean getBoolean(String key)
          Returns the key that the name maps to.
 boolean getBoolean(String key, boolean defaultValue)
          Returns the key that the name maps to.
 double getDouble(String key)
          Deprecated. Returns the value at the specified key.
 double getDouble(String key, double defaultValue)
          Deprecated. Returns the value at the specified key.
 int getInt(String key)
          Deprecated. Returns the value at the specified key.
 int getInt(String key, int defaultValue)
          Deprecated. Returns the value at the specified key.
 double getNumber(String key)
          Returns the key that the name maps to.
 double getNumber(String key, double defaultValue)
          Returns the key that the name maps to.
 String getString(String key)
          Returns the key that the name maps to.
 String getString(String key, String defaultValue)
          Returns the key that the name maps to.
 ITable getSubTable(String key)
          Returns the table at the specified key.
static NetworkTable getTable(String key)
          Gets the table with the specified key.
 Object getValue(String key)
          Returns the key that the name maps to.
 Object getValue(String key, Object defaultValue)
          Returns the key that the name maps to.
static void initialize()
           
 boolean isConnected()
          Get the current state of the objects connection
 boolean isServer()
          If the object is acting as a server
 void putBoolean(String key, boolean value)
          Maps the specified key to the specified value in this table.
 void putDouble(String key, double value)
          Deprecated. 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.
 void putInt(String key, int value)
          Deprecated. 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.
 void putNumber(String key, double value)
          Maps the specified key to the specified value in this table.
 void putString(String key, String value)
          Maps the specified key to the specified value in this table.
 void putValue(String key, Object value)
          Maps the specified key to the specified value in this table.
 void removeConnectionListener(IRemoteConnectionListener listener)
          Unregister a listener from connection events
 void removeTableListener(ITableListener listener)
          Remove a listener from receiving table events
 void retrieveValue(String key, Object externalValue)
           
static void setIPAddress(String address)
           
static void setServerMode()
          set that network tables should be a server This must be called before initalize or getTable
static void setTeam(int team)
          set the team the robot is configured for (this will set the ip address that network tables will connect to in client mode) This must be called before initalize or getTable
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PATH_SEPARATOR

public static final char PATH_SEPARATOR
The path separator for sub-tables and keys

See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port that network tables operates on

See Also:
Constant Field Values
Method Detail

initialize

public static void initialize()
                       throws IOException
Throws:
IOException

setServerMode

public static void setServerMode()
set that network tables should be a server This must be called before initalize or getTable


setTeam

public static void setTeam(int team)
set the team the robot is configured for (this will set the ip address that network tables will connect to in client mode) This must be called before initalize or getTable

Parameters:
team - the team number

setIPAddress

public static void setIPAddress(String address)
Parameters:
address - the adress that network tables will connect to in client mode

getTable

public static NetworkTable getTable(String key)
Gets the table with the specified key. If the table does not exist, a new table will be created.
This will automatically initialize network tables if it has not been already

Parameters:
key - the key name
Returns:
the network table requested

toString

public String toString()
Description copied from class: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString in class Object
Returns:
a string representation of the object.

isConnected

public boolean isConnected()
Description copied from interface: IRemote
Get the current state of the objects connection

Specified by:
isConnected in interface IRemote
Returns:
the current connection state

isServer

public boolean isServer()
Description copied from interface: IRemote
If the object is acting as a server

Specified by:
isServer in interface IRemote
Returns:
if the object is a server

addConnectionListener

public void addConnectionListener(IRemoteConnectionListener listener,
                                  boolean immediateNotify)
Description copied from interface: IRemote
Register an object to listen for connection and disconnection events

Specified by:
addConnectionListener in interface IRemote
Parameters:
listener - the listener to be register
immediateNotify - if the listener object should be notified of the current connection state

removeConnectionListener

public void removeConnectionListener(IRemoteConnectionListener listener)
Description copied from interface: IRemote
Unregister a listener from connection events

Specified by:
removeConnectionListener in interface IRemote
Parameters:
listener - the listener to be unregistered

addTableListener

public void addTableListener(ITableListener listener)
Description copied from interface: ITable
Add a listener for changes to the table

Specified by:
addTableListener in interface ITable
Parameters:
listener - the listener to add

addTableListener

public void addTableListener(ITableListener listener,
                             boolean immediateNotify)
Description copied from interface: ITable
Add a listener for changes to the table

Specified by:
addTableListener in interface ITable
Parameters:
listener - the listener to add
immediateNotify - if true then this listener will be notified of all current entries (marked as new)

addTableListener

public void addTableListener(String key,
                             ITableListener listener,
                             boolean immediateNotify)
Description copied from interface: ITable
Add a listener for changes to a specific key the table

Specified by:
addTableListener in interface ITable
Parameters:
key - the key to listen for
listener - the listener to add
immediateNotify - if true then this listener will be notified of all current entries (marked as new)

addSubTableListener

public void addSubTableListener(ITableListener listener)
Description copied from interface: ITable
This will immediately notify the listener of all current sub tables

Specified by:
addSubTableListener in interface ITable

removeTableListener

public void removeTableListener(ITableListener listener)
Description copied from interface: ITable
Remove a listener from receiving table events

Specified by:
removeTableListener in interface ITable
Parameters:
listener - the listener to be removed

getSubTable

public ITable getSubTable(String key)
Returns the table at the specified key. If there is no table at the specified key, it will create a new table

Specified by:
getSubTable in interface ITable
Parameters:
key - the key name
Returns:
the networktable to be returned

containsKey

public boolean containsKey(String key)
Checks the table and tells if it contains the specified key

Specified by:
containsKey in interface ITable
Parameters:
key - the key to be checked
Returns:
true if the table as a value assigned to the given key

containsSubTable

public boolean containsSubTable(String key)
Specified by:
containsSubTable in interface ITable
Parameters:
key - the key to search for
Returns:
true if there is a subtable with the key which contains at least one key/subtable of its own

putNumber

public void putNumber(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.

Specified by:
putNumber in interface ITable
Parameters:
key - the key
value - the value

getNumber

public double getNumber(String key)
                 throws TableKeyNotDefinedException
Returns the key that the name maps to.

Specified by:
getNumber in interface ITable
Parameters:
key - the key name
Returns:
the key
Throws:
TableKeyNotDefinedException - if the specified key is null

getNumber

public double getNumber(String key,
                        double defaultValue)
Returns the key that the name maps to. If the key is null, it will return the default value

Specified by:
getNumber in interface ITable
Parameters:
key - the key name
defaultValue - the default value if the key is null
Returns:
the key

putString

public void putString(String key,
                      String 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.

Specified by:
putString in interface ITable
Parameters:
key - the key
value - the value

getString

public String getString(String key)
                 throws TableKeyNotDefinedException
Returns the key that the name maps to.

Specified by:
getString in interface ITable
Parameters:
key - the key name
Returns:
the key
Throws:
TableKeyNotDefinedException - if the specified key is null

getString

public String getString(String key,
                        String defaultValue)
Returns the key that the name maps to. If the key is null, it will return the default value

Specified by:
getString in interface ITable
Parameters:
key - the key name
defaultValue - the default value if the key is null
Returns:
the key

putBoolean

public void putBoolean(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.

Specified by:
putBoolean in interface ITable
Parameters:
key - the key
value - the value

getBoolean

public boolean getBoolean(String key)
                   throws TableKeyNotDefinedException
Returns the key that the name maps to.

Specified by:
getBoolean in interface ITable
Parameters:
key - the key name
Returns:
the key
Throws:
TableKeyNotDefinedException - if the specified key is null

getBoolean

public boolean getBoolean(String key,
                          boolean defaultValue)
Returns the key that the name maps to. If the key is null, it will return the default value

Specified by:
getBoolean in interface ITable
Parameters:
key - the key name
defaultValue - the default value if the key is null
Returns:
the key

retrieveValue

public void retrieveValue(String key,
                          Object externalValue)
Specified by:
retrieveValue in interface ITable

putValue

public void putValue(String key,
                     Object 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.

Specified by:
putValue in interface ITable
Parameters:
key - the key name
value - the value to be put

getValue

public Object getValue(String key)
                throws TableKeyNotDefinedException
Returns the key that the name maps to. NOTE: If the value is a double, it will return a Double object, not a primitive. To get the primitive, use getDouble

Specified by:
getValue in interface ITable
Parameters:
key - the key name
Returns:
the key
Throws:
TableKeyNotDefinedException - if the specified key is null

getValue

public Object getValue(String key,
                       Object defaultValue)
Returns the key that the name maps to. If the key is null, it will return the default value NOTE: If the value is a double, it will return a Double object, not a primitive. To get the primitive, use getDouble

Parameters:
key - the key name
defaultValue - the default value if the key is null
Returns:
the key

putInt

public void putInt(String key,
                   int value)
Deprecated. 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.

Specified by:
putInt in interface ITable
Parameters:
key - the key
value - the value
Throws:
IllegalArgumentException - if key is null

getInt

public int getInt(String key)
           throws TableKeyNotDefinedException
Deprecated. Returns the value at the specified key.

Specified by:
getInt in interface ITable
Parameters:
key - the key
Returns:
the value
Throws:
TableKeyNotDefinedException - if there is no value mapped to by the key
IllegalArgumentException - if the value mapped to by the key is not an int
IllegalArgumentException - if the key is null

getInt

public int getInt(String key,
                  int defaultValue)
           throws TableKeyNotDefinedException
Deprecated. Returns the value at the specified key.

Specified by:
getInt in interface ITable
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
IllegalArgumentException - if the value mapped to by the key is not an int
IllegalArgumentException - if the key is null
TableKeyNotDefinedException

putDouble

public void putDouble(String key,
                      double value)
Deprecated. 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.

Specified by:
putDouble in interface ITable
Parameters:
key - the key
value - the value
Throws:
IllegalArgumentException - if key is null

getDouble

public double getDouble(String key)
                 throws TableKeyNotDefinedException
Deprecated. Returns the value at the specified key.

Specified by:
getDouble in interface ITable
Parameters:
key - the key
Returns:
the value
Throws:
NoSuchEleNetworkTableKeyNotDefinedmentException - if there is no value mapped to by the key
IllegalArgumentException - if the value mapped to by the key is not a double
IllegalArgumentException - if the key is null
TableKeyNotDefinedException

getDouble

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

Specified by:
getDouble in interface ITable
Parameters:
key - the key
defaultValue - the value returned if the key is undefined
Returns:
the value
Throws:
NoSuchEleNetworkTableKeyNotDefinedmentException - if there is no value mapped to by the key
IllegalArgumentException - if the value mapped to by the key is not a double
IllegalArgumentException - if the key is null

"

2013 FRC Java API

"

"
For updated information see the Java FRC site
"