151 lines
3.2 KiB
Java
151 lines
3.2 KiB
Java
/**
|
|
* <PRE>
|
|
* HashNode.java
|
|
*
|
|
* Revisions: 1.0 Oct. 06, 2002
|
|
* Created the HashNode class
|
|
* 1.1 oCT. 06, 2002
|
|
* Compiled, Tested, Commented
|
|
*
|
|
* </PRE>
|
|
*
|
|
* Collaboration Statement:
|
|
* I worked on the homework assignment alone, using only
|
|
* course materials.
|
|
*
|
|
* Created with JCreatorLE, some indents are off when viewed through notepad
|
|
* or EMACS
|
|
*
|
|
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
|
* @version Version 1.1, Oct. 06, 2002
|
|
*/
|
|
|
|
public class HashNode {
|
|
|
|
private HashNode next;
|
|
private Object key ;
|
|
private Object data;
|
|
|
|
public static final boolean bDebug = false; //there's nothing to debug
|
|
//that bDebug can handle
|
|
|
|
////////////////
|
|
//Constructors//
|
|
////////////////
|
|
|
|
/**
|
|
*Constructor for HashNode
|
|
*@param key, the object to be stored as the key
|
|
*@param data, the object to be stored as data
|
|
*/
|
|
public HashNode(Object key, Object data){
|
|
this.key = key ;
|
|
this.data = data;
|
|
}
|
|
|
|
///////////////////////
|
|
//Accessors/Modifiers//
|
|
///////////////////////
|
|
|
|
/**
|
|
*Modifier for next
|
|
*@param next, the next HashNode
|
|
*/
|
|
public void setNext(HashNode next){
|
|
this.next = next;
|
|
}
|
|
|
|
/**
|
|
*Accessor for next
|
|
*@return the next HashNode
|
|
*/
|
|
public HashNode getNext(){
|
|
return next;
|
|
}
|
|
|
|
/**
|
|
*Modifier for key
|
|
*@param key, the new value for key
|
|
*/
|
|
public void setKey(Object key){
|
|
this.key = key;
|
|
}
|
|
|
|
/**
|
|
*Accessor for key
|
|
*@return the value of key
|
|
*/
|
|
public Object getKey(){
|
|
return key;
|
|
}
|
|
|
|
/**
|
|
*Modifier for data
|
|
*@param data, the new value for data
|
|
*/
|
|
public void setData(Object data){
|
|
this.data = data;
|
|
}
|
|
|
|
/**
|
|
*Accessor for data
|
|
*@return the value of data
|
|
*/
|
|
public Object getData(){
|
|
return data;
|
|
}
|
|
|
|
///////////
|
|
//Methods//
|
|
///////////
|
|
|
|
/**
|
|
*Equals method for HashNode
|
|
*@return true if both HashNodes have the same key
|
|
*/
|
|
public boolean equals(Object obj){
|
|
if(!(obj instanceof HashNode)){
|
|
return false;
|
|
}
|
|
|
|
HashNode hTemp = (HashNode)obj;
|
|
if(hTemp.getData().equals(this.data)){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public String toString(){
|
|
return (data.toString());
|
|
}
|
|
|
|
/*************************************************************/
|
|
|
|
/**
|
|
* Debugging main for class HashNode.
|
|
* This method will rigorously test my code.
|
|
*
|
|
* <br><br>
|
|
* @param args a String array of command line arguments.
|
|
*/
|
|
public static void main(String[] args) {
|
|
HashNode dooby = new HashNode("key","data");
|
|
HashNode stinky = new HashNode("key","data");
|
|
|
|
System.out.println(dooby.equals(stinky));
|
|
|
|
stinky.setKey(new Integer(6));
|
|
|
|
stinky.setData("key");
|
|
|
|
stinky.setNext(dooby);
|
|
|
|
System.out.println(dooby.equals(stinky));
|
|
System.out.println(stinky.getKey());
|
|
System.out.println(stinky.getData());
|
|
System.out.println(stinky.getNext().getKey());
|
|
|
|
}// end of main(String[] args)
|
|
|
|
}// end of class HashNode
|