/** * Author by flo on 10/25/15. * Project Num : Project 4 * Purpose : Node class to hold data when called from Driver class * : This class holds next node pointer and text data in each node * Algorithm : Just a simple Node class which has various methods to get and set * : text data values and return a node to user * : * Compile : javac Project4Driver.java * : java Project4Driver */ public class Node { // Node Data members public String data; public Node next; // Default empty Node Constructor public Node() { this.data = ""; this.next = null; } // Node constructor with data public Node(String d) { this.next = null; this.data = d; } // Node constructor specify a particular node public Node(String d, Node n) { this.next = n; this.data = d; } // return next node public Node getNext() { return this.next; } // set this node to next node public void setNext(Node n) { this.next = n; } // return data of a node public String getData() { return this.data; } // set the data of a node to String value public void setData(String d) { this.data = d; } // test to see if there is next node public boolean hasNext() { return this.next == null; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Node node = (Node) o; if (data != null ? !data.equals(node.data) : node.data != null) return false; return !(next != null ? !next.equals(node.next) : node.next != null); } @Override public int hashCode() { int result = data != null ? data.hashCode() : 0; result = 31 * result + (next != null ? next.hashCode() : 0); return result; } @Override public String toString() { return "Node{" + "data='" + data + '\'' + ", next=" + next + '}'; } }