edu.columbia.surge.hashImpl
Class FDH

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--java.util.HashMap
              |
              +--edu.columbia.surge.hashImpl.FDH
Direct Known Subclasses:
APH, CircumH, ClauseH, CommonH, FDNullH, FDRefH, NPH, ParticH, PersonalPronounH, PersonNameH, PreModH, ProcH, ProperH

public class FDH
extends java.util.HashMap
implements FD

This is the class that implements the FD interface and is inherited from the HashMap class. This is the base class that all kinds of FD will be inherrited from. It consists of methods to modify and to get the key-value pairs of the map of the FD. The toXML() method of this class has not be implemented due to time constraint. All kinds of FD such as Clause, Common, Proc... has to extend this class in order for the items to be able to hashed into the hashmap.

See Also:
FD, Serialized Form

Constructor Summary
FDH()
          Default constructor which creates a default instance of FDH.
 
Method Summary
 boolean checkPath(java.lang.String path)
          A method to verify whether the given path exists in this FD.
 boolean checkPath(java.lang.String[] path)
          A method to verify whether the path exists in this FD.
protected  java.lang.String computePathDifference(java.lang.String[] currentPath, java.lang.String[] alreadyPrintedPath)
          This method computes the difference between the current path and the path that is already printed and returns their difference.
 java.lang.Object getPath(java.lang.String path)
          A method to return the object that associates with the given path.
 java.lang.Object getPath(java.lang.String[] path)
          A method to return the object that associates with the given path.
 void putPath(java.lang.String[] path, java.lang.Object newValue)
          A method for user to put a new value object into the key of a FD that is specified by the given existing path.
 void putPath(java.lang.String path, java.lang.Object newValue)
          A method for user to put a new value object into the key of a FD that is specified by the given existing path.
 void putPathOverride(java.lang.String[] path, java.lang.Object newValue)
          A method for user to put a new value object associate with the key of a FD that is specified by the given existing path.
 void putPathOverride(java.lang.String path, java.lang.Object newValue)
          A method for user to put a new value object associate with the key of a FD that is specified by the given existing path.
protected  java.lang.String[] stackToPath(java.util.Stack stack)
          A method that takes in a stack which stores the path names that the method has traversed to and convert the path into a string array.
protected  java.lang.String[] stringToArray(java.lang.String string)
          A method that takes in a path string and return a path string array equivalent.
 java.lang.String toString()
          Override the toString() method inherrited from HashMap, this method unifies the FD into its equivalent lisp-string representation by calling the private toString method.
protected  java.lang.String toString(java.util.Map alreadyPrinted, java.util.Stack currentPath)
          The private toString() method which constructs a lisp-string representation of the FD.
 java.lang.Object toXML()
          A method to exports the FD in the form of XML.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FDH

public FDH()
Default constructor which creates a default instance of FDH.
Method Detail

toXML

public java.lang.Object toXML()
                       throws InvalidPathException
A method to exports the FD in the form of XML. For now, the implementation has not been supplied yet. An exception should be thrown when the FD is invalid.
Specified by:
toXML in interface FD
Returns:
a XML object that represents the FD

putPath

public void putPath(java.lang.String[] path,
                    java.lang.Object newValue)
             throws InvalidPathException
A method for user to put a new value object into the key of a FD that is specified by the given existing path. If the path is not found, an exception will be thrown and no object will be inserted. This put path method is implemented in the form of recurrsion. It recurrsively traversed to the given path and put the value there.
Specified by:
putPath in interface FD
Parameters:
path - A path name which users specify the path to the desired node with a String array which each elelemnt in the path array will be the name of the node to be traversed.
newValue - A new value to be placed in the node of the given path
Throws:
InvalidPathException -  

putPath

public void putPath(java.lang.String path,
                    java.lang.Object newValue)
             throws InvalidPathException
A method for user to put a new value object into the key of a FD that is specified by the given existing path. This method basically use the stringToArray method to tokenized the given path into an array and then use then pass it to the putPath method.
Specified by:
putPath in interface FD
Parameters:
path - A path name which users specify the path to the desired node. The path is specified in one string with each path separated by spaces.
newValue - A new value to be placed in the node of the given path
Throws:
InvalidPathException -  
See Also:
putPath(String[] path, Object newValue), stringToArray(String path)

putPathOverride

public void putPathOverride(java.lang.String[] path,
                            java.lang.Object newValue)
                     throws InvalidPathException
A method for user to put a new value object associate with the key of a FD that is specified by the given existing path. If the given path is not found, it will be automatically created and the new object will be inserted at the end of the path. This is implemented in the form of recurrsion, it recurrsively traversed to the given path and put the value there. While it traverses, if the given path is not found in the present FD, it will automatically create the abscent paths along its way.
Specified by:
putPathOverride in interface FD
Parameters:
path - A path name which users specify the path to the desired node with a String array which each elelemnt in the path array will be the name of the node to be traversed.
newValue - A new value to be placed in the node of the given path
Throws:
InvalidPathException -  

putPathOverride

public void putPathOverride(java.lang.String path,
                            java.lang.Object newValue)
                     throws InvalidPathException
A method for user to put a new value object associate with the key of a FD that is specified by the given existing path. If the given path is not found, it will be automatically created and the new object will be inserted at the end of the path. Same as that of putPath(), this modifies the string path into the string[] equivalent and use the other putPathOverride method to process the information.
Specified by:
putPathOverride in interface FD
Parameters:
path - A path name which users specify the path to the desired node with a string which path names are separated by spaces.
newValue - A new value to be placed in the node of the given path
Throws:
InvalidPathException -  

checkPath

public boolean checkPath(java.lang.String[] path)
A method to verify whether the path exists in this FD. This method recurssively looks for the given path within the map of the given FD.
Specified by:
checkPath in interface FD
Parameters:
path - the path to be verified, specified by a string array with the names of the nodes of the path.
Returns:
a boolean of the verification result, true if the path exists and vice versa.

checkPath

public boolean checkPath(java.lang.String path)
A method to verify whether the given path exists in this FD. This method uses the stringToArray method to convert the path string into a path array and then use the checkPath(String[] array) method to compute the result.
Specified by:
checkPath in interface FD
Parameters:
path - the path to be verified, specified by a string with the names of the nodes of the path separated by spaces.
Returns:
a boolean of the verification result
See Also:
stringToArray(String path), checkPath(String[] path)

getPath

public java.lang.Object getPath(java.lang.String[] path)
                         throws InvalidPathException
A method to return the object that associates with the given path. This method is implemented using recurssion; it recurssively traverse the map within the FD using the given path and obtain the object at the end of the path. An exception is thrown when the given path is not be found.
Specified by:
getPath in interface FD
Parameters:
path - the path of the object to be retrieved, specified in a string array that stores each path node name.
Returns:
value the object on that path.
Throws:
InvalidPathException -  

getPath

public java.lang.Object getPath(java.lang.String path)
                         throws InvalidPathException
A method to return the object that associates with the given path. This method converts the input path to a string array and uses the getPath(String[] path) to compute the result.
Specified by:
getPath in interface FD
Parameters:
path - the path of the object to be retrieved, specified in a string array that stores each path node name.
Returns:
value the object on that path.
Throws:
InvalidPathException -  
See Also:
stringToArray(String path), getPath(String[] path)

toString

public java.lang.String toString()
Override the toString() method inherrited from HashMap, this method unifies the FD into its equivalent lisp-string representation by calling the private toString method.
Specified by:
toString in interface FD
Returns:
the lisp equivalent string representation of the FD
Overrides:
toString in class java.util.AbstractMap
See Also:
toString(Map alreadyPrinted, Stack currentPath)

toString

protected java.lang.String toString(java.util.Map alreadyPrinted,
                                    java.util.Stack currentPath)
The private toString() method which constructs a lisp-string representation of the FD. In addition to combining nodes and putting them into the right paranthesized form, it keeps track of the path that it currently traversed and the nodes that are already printed so that we will not print re-used nodes and also we are able to produce the correct statement for the holes in a FD.
Parameters:
alreadyPrinted - a HashMap that keeps track of the FD that is already printed and processed
currentPath - a stack which keeps track of the current path that the method traverses
Returns:
the lisp equivalent string representation of the FD

computePathDifference

protected java.lang.String computePathDifference(java.lang.String[] currentPath,
                                                 java.lang.String[] alreadyPrintedPath)
This method computes the difference between the current path and the path that is already printed and returns their difference. It is used to compute what needs to be put into the scope statement and it is also used when constructing reuse-able nodes. This method is used by the toString() method to construct the lisp representation of the FD.
Parameters:
currentPath - the current path that it has traversed to
alreadyPrintedPath - the path that is already printed
Returns:
a string consists of the difference between the two paths with each path name separated by a space.
See Also:
toString(Map alreadyPrinted, Stack currentPath)

stackToPath

protected java.lang.String[] stackToPath(java.util.Stack stack)
A method that takes in a stack which stores the path names that the method has traversed to and convert the path into a string array. This method is used by the toString(Map alreadyPrinted, Stack currentPath) method to construct the lisp representation of the FD.
Parameters:
a - stack which stores all the path names
Returns:
the path that is represented as a string array.
See Also:
toString(Map alreadyPrinted, Stack currentPath)

stringToArray

protected java.lang.String[] stringToArray(java.lang.String string)
A method that takes in a path string and return a path string array equivalent.
Parameters:
string - the path string
Returns:
the path string array