artisynth.core.util
Class AliasTable

java.lang.Object
  extended by artisynth.core.util.AliasTable

public class AliasTable
extends java.lang.Object

A hash-table that keeps track of names and aliases.


Constructor Summary
AliasTable()
          Creates a new AliasTable with no entries.
AliasTable(java.io.File file)
          Creates a new AliasTable and reads it's initial entries from a file.
AliasTable(java.net.URL url)
          Creates a new AliasTable and reads it's initial entries from a resource.
 
Method Summary
 void addEntry(java.lang.String alias, java.lang.String name)
          Adds an alias and it's corresponding name to this AliasTable.
 void clear()
          Clears all entries from the AliasTable
 boolean containsAlias(java.lang.String alias)
          Returns true if this table contains the specified alias.
 boolean containsName(java.lang.String name)
          Returns true if this table contains the specified name.
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> entrySet()
          Returns a Set view of the entries for this table.
 java.lang.String getAlias(java.lang.String name)
          Gets the first alias found that references a given name, or null if no such alias is found.
 java.lang.String[] getAliases()
          Returns a list of all the aliases in this table.
 java.lang.String getName(java.lang.String alias)
          Gets the name referenced by a given alias, or null if the alias has no entry.
 java.lang.String[] getNames()
          Returns a list of all the names in this table.
 void read(java.io.InputStream s)
          Reads the contents of an input stream and adds every successive pair of strings into this table as an alias/name pair.
 void removeEntry(java.lang.String alias)
          Removes an alias from this AliasTable.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AliasTable

public AliasTable()
Creates a new AliasTable with no entries.


AliasTable

public AliasTable(java.io.File file)
           throws java.io.IOException
Creates a new AliasTable and reads it's initial entries from a file.

Parameters:
file - File from which to read table entries
Throws:
java.io.IOException - if there was an error reading the file

AliasTable

public AliasTable(java.net.URL url)
           throws java.io.IOException
Creates a new AliasTable and reads it's initial entries from a resource.

Parameters:
url - Resource from which to read table entries
Throws:
java.io.IOException - if there was an error reading the resource
Method Detail

read

public void read(java.io.InputStream s)
          throws java.io.IOException
Reads the contents of an input stream and adds every successive pair of strings into this table as an alias/name pair. Strings are delineated either by double quotes " or by whitespace. Whitespace-delineated strings may contain alphanumeric characters, plus the characters $./_-, but must not start with a digit. Quoted strings may contain any character and support the usual escape sequences. This function returns a list of all the aliases read.

Parameters:
s - Stream from which to read table entries
Throws:
java.io.IOException - if there was an error reading the stream

addEntry

public void addEntry(java.lang.String alias,
                     java.lang.String name)
Adds an alias and it's corresponding name to this AliasTable.

Parameters:
alias - alias which references the name
name - name which is referenced by the alias

removeEntry

public void removeEntry(java.lang.String alias)
Removes an alias from this AliasTable.

Parameters:
alias - alias which references the name

clear

public void clear()
Clears all entries from the AliasTable


getName

public java.lang.String getName(java.lang.String alias)
Gets the name referenced by a given alias, or null if the alias has no entry.

Parameters:
alias - alias which references the name
Returns:
name referenced by the alias

getAlias

public java.lang.String getAlias(java.lang.String name)
Gets the first alias found that references a given name, or null if no such alias is found.

Parameters:
name - name which is referenced
Returns:
first alias which references the name

getAliases

public java.lang.String[] getAliases()
Returns a list of all the aliases in this table.

Returns:
list of all the aliases

getNames

public java.lang.String[] getNames()
Returns a list of all the names in this table.

Returns:
list of all the name

containsName

public boolean containsName(java.lang.String name)
Returns true if this table contains the specified name.

Parameters:
name - to check for
Returns:
true if the name is present in this table

containsAlias

public boolean containsAlias(java.lang.String alias)
Returns true if this table contains the specified alias.

Parameters:
alias - to check for
Returns:
true if the alias is present in this table

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> entrySet()
Returns a Set view of the entries for this table.