1 package com.daffodilwoods.daffodildb.utils.parser; 2 3 7 8 public class Key { 9 10 13 String nameOfRule; 14 15 18 int position; 19 20 23 int hashCode; 24 String recursiveState; 25 26 public Key(String nameOfRule,int position){ 27 this.nameOfRule = nameOfRule; 28 this.position = position; 29 hashCode = 1; 30 } 31 32 public Key(String nameOfRule,int position,String recursiveState){ 33 this.nameOfRule = nameOfRule; 34 this.position = position; 35 hashCode = 1; 36 this.recursiveState = recursiveState; 37 } 38 39 43 public int hashCode() { 44 if ( hashCode != 1 ) 45 return hashCode; 46 hashCode = 31*hashCode + (nameOfRule==null ? 0 : nameOfRule.hashCode()); 47 hashCode += 31*hashCode + position; 48 hashCode += 31*hashCode + (recursiveState==null ? 0 : recursiveState.hashCode()); 49 return hashCode; 50 } 51 52 55 public boolean equals(Object object){ 56 boolean flag = true; 57 if (!(object instanceof Key) ) 58 return false; 59 Key key = (Key)object; 60 flag = nameOfRule == null ? true : nameOfRule.equals(key.nameOfRule); flag = flag && (position == key.position ? true : false); 62 flag = flag && recursiveState == null ? true : recursiveState.equals(key.recursiveState); 63 return flag; 64 } 65 66 69 private boolean compareTwoString(String string1,String string2){ 70 if ( string1.length() != string2.length() ) 71 return false; 72 char []source = string1.toCharArray(); 73 char []target = string2.toCharArray(); 74 for(int j = 0; j < source.length; ++j) 75 if ( source[j] != target[j] ) 76 return false; 77 return true; 78 } 79 80 public String toString(){ 81 StringBuffer str=new StringBuffer ("Key ["); 82 str.append(nameOfRule).append("--").append(position).append("]"); 83 return str.toString(); 84 } 85 } 86 | Popular Tags |