////////////////////////////////////////////////////////////////////// // Node.java // // --Container for Node IP and structure information-- // // // // Supervised Peer-to-peer Overlay Network (SPON) Simulator // // // // Computer Science Independent Study Project // // Modified by: Peter Keeler // // The Node class is no longer used by SPON. // // // // Computer Science M.S.E. Project // // Programmed by: Joey Chau // // Copyright: February, 2003 // // // // Research Advisor: Christian Scheideler // // Computer Science // // Johns Hopkins University // ////////////////////////////////////////////////////////////////////// import java.io.*; import java.net.*; import java.util.*; /** Node used to hold and manage parent, child, and next node information */ class Node { private String mKey; private int mHeight; // present height of this node private String mLeftChild; // my left child private String mRightChild; // my right child private String sLeftChild; // secondary left child private String sRightChild; // secondary right child private String coparent; // parent of secondary children. private String mParent; // parent of this node private String sParent; // secondary parent of this node private String mAncestor; // grandparent of this node private String mNext; /** Default node constructor */ public Node() { mKey = "0.0.0.0"; mHeight = -1; mLeftChild = "0.0.0.0"; mRightChild = "0.0.0.0"; sLeftChild = "0.0.0.0"; sRightChild = "0.0.0.0"; coparent = "0.0.0.0"; mAncestor = "0.0.0.0"; mNext = "0.0.0.0"; } /** Node constructor which declares the source node IP @param iaddy - String representation of the source node IP */ public Node( String iaddy ) { mKey = iaddy; mHeight = 0; mLeftChild = "0.0.0.0"; mRightChild = "0.0.0.0"; sLeftChild = "0.0.0.0"; sRightChild = "0.0.0.0"; coparent = "0.0.0.0"; mAncestor = "0.0.0.0"; mNext = "0.0.0.0"; } /** Copy constructor which duplicates the values of another node @param other - Node which will be duplicated */ public Node( Node other ) { mKey = other.mKey; mHeight = other.mHeight; mLeftChild = other.mLeftChild; mRightChild = other.mRightChild; sLeftChild = other.sLeftChild; sRightChild = other.sRightChild; coparent = other.coparent; mAncestor = other.mAncestor; mNext = other.mNext; } /** Modify the default key of this node @param iaddy - String key */ public void setKey( String iaddy ) { mKey = iaddy; } /** Access the the key of the node @return String - the key */ public String getKey() { return mKey; } /** Modify the height of this node @param h - int height */ public void setHeight( int h ) { mHeight = h; } /** Access the height of this node @return int - height */ public int getHeight() { return mHeight; } /** Access the right child of this node @return String - the key of the right child */ public String getRightChild() { return mRightChild; } /** Modify the right child of this node @param rc - String key of the new right child */ public void setRightChild( String rc ) { mRightChild = rc; } /** Access the secondary right child of this node @return String - the key of the secondary right child */ public String getSRightChild() { return sRightChild; } /** Modify the secondary right child of this node @param rc - String key of the new secondary right child */ public void setSRightChild( String rc ) { sRightChild = rc; } /** Access the left child of this node @return String - the key of the left child */ public String getLeftChild() { return mLeftChild; } /** Modify the left child of this node @param lc - String key of the new left child */ public void setLeftChild( String lc ) { mLeftChild = lc; } /** Access the secondary left child of this node @return String - the key of the secondary left child */ public String getSLeftChild() { return sLeftChild; } /** Modify the secondary left child of this node @param lc - String key of the new secondary left child */ public void setSLeftChild( String lc ) { sLeftChild = lc; } /** Access the co-parent @return String - the key of the co-parent */ public String getCoparent() { return coparent; } /** Modify the co-parent @param cp - String key of the new coparent */ public void setCoparent( String cp ) { coparent = cp; } /** Access the primary parent @return String - the key of the co-parent */ public String getMParent() { return mParent; } /** Modify the primary parent @param cp - String key of the new coparent */ public void setMParent( String cp ) { mParent = cp; } /** Access the seconday parent @return String - the key of the co-parent */ public String getSParent() { return sParent; } /** Modify the secondary parent @param cp - String key of the new coparent */ public void setSParent( String cp ) { sParent = cp; } /** Access the ancestor @return String - the key of the ancestor */ public String getAncestor() { return mAncestor; } /** Modify the ancestor @param cp - String key of the new ancestor */ public void setAncestor( String cp ) { mAncestor = cp; } /** Access the next node @return String - the key of the next node */ public String getNext() { return mNext; } /** Modify the next node @param nx - String key of the next node */ public void setNext( String nx ) { mNext = nx; } /** Determines whether the node has not been set @return boolean - true if node is empty or undelcared or unset */ public boolean isEmpty() { return (mHeight == -1); } /** String representation of the node used for communication and information maintenance @return String - the String representation of the information in Node */ public String toString() { return mKey + ":" + mHeight + ":" + mLeftChild + ":" + mRightChild + ":" + sLeftChild + ":" + sRightChild + ":" + coparent + ":" + mAncestor + ":" + mNext; } /** Given a formated Node string, it attempts to parse the String and set the attributes of the node @param pStr - String containing Node information @boolean - true if parse was successful for the given parameter */ public boolean parseString( String pStr ) { StringTokenizer stok = new StringTokenizer( pStr, ":" ); int count; count = stok.countTokens(); if( count != 9 ) { return false; } mKey = stok.nextToken(); try { mHeight = Integer.parseInt( stok.nextToken() ); } catch( NumberFormatException e ) { return false; } mLeftChild = stok.nextToken(); mRightChild = stok.nextToken(); sLeftChild = stok.nextToken(); sRightChild = stok.nextToken(); coparent = stok.nextToken(); mAncestor = stok.nextToken(); mNext = stok.nextToken(); return true; } }