001package clone.deepVshallow;
002class Node implements Cloneable {
003        private int i;
004        private Node next;
005
006        public Node(int i, Node next) { this.i = i; this.next = next; }
007        public Node(int i)            { this(i,null); }
008
009        public Object shallow_copy() {
010                return new Node(i, next);
011        }
012
013        public Object shallow_clone() throws CloneNotSupportedException {
014                return super.clone();
015        }
016
017        public boolean shallow_equals(Object o) {
018                if (!(this.getClass().equals(o.getClass())))
019                        return false;
020                Node that = (Node) o;
021                return (i == that.i) && (next == that.next);
022        }
023
024        public Object deep_copy() {
025                Node next_copy = (next==null) ? null : (Node) next.deep_copy();
026                return new Node(i, next_copy);
027        }
028
029        public Object deep_clone() throws CloneNotSupportedException {
030                Node result = (Node) super.clone();
031                result.next = (next==null) ? null : (Node) next.deep_clone();
032                return result;
033        }
034
035        public boolean deep_equals(Object o) {
036                if (!(this.getClass().equals(o.getClass())))
037                        return false;
038                Node that = (Node) o;
039                return (i == that.i)
040                                && ((next==null) ? (that.next==null) : next.deep_equals(that.next));
041        }
042}