1 28 package org.jvyamlb.nodes; 29 30 33 public abstract class Node { 34 private String tag; 35 private Object value; 36 private int hash = -1; 37 38 public Node(final String tag, final Object value) { 39 this.tag = tag; 40 this.value = value; 41 } 42 43 public String getTag() { 44 return this.tag; 45 } 46 47 public Object getValue() { 48 return this.value; 49 } 50 51 public int hashCode() { 52 if(hash == -1) { 53 hash = 3; 54 hash += (null == tag) ? 0 : 3*tag.hashCode(); 55 hash += (null == value) ? 0 : 3*value.hashCode(); 56 } 57 return hash; 58 } 59 60 public boolean equals(final Object oth) { 61 if(oth instanceof Node) { 62 final Node nod = (Node)oth; 63 return ((this.tag != null) ? this.tag.equals(nod.tag) : nod.tag == null) && 64 ((this.value != null) ? this.value.equals(nod.value) : nod.value == null); 65 } 66 return false; 67 } 68 69 public String toString() { 70 return "#<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue()+")>"; 71 } 72 } | Popular Tags |