1 22 23 package org.xquark.xpath; 24 25 import java.util.ArrayList ; 26 27 public class PathExprImpl implements PathExpr { 28 29 private ArrayList steps = null; 30 private String hashCodeString = null; 31 35 public PathExprImpl() { 36 steps = new ArrayList (); 38 } 39 40 44 public PathExprImpl(int size) { 45 steps = new ArrayList (size); 47 } 48 49 53 public PathExprImpl(ArrayList steps) { 54 this.steps = (ArrayList )steps.clone(); 57 58 } 59 60 65 public StepExpr getStep(int num) { 66 if (num < 0 || num >= steps.size()) 67 return null; 68 return (StepExpr) steps.get(num); 69 } 70 71 75 public ArrayList getSteps() { 76 return steps; 77 } 78 79 83 public Object clone() throws CloneNotSupportedException { 84 PathExprImpl newobj = new PathExprImpl(steps); 85 return newobj; 86 } 87 88 91 public String toHashCodeString() { 92 if (hashCodeString != null) 93 return hashCodeString; 94 StringBuffer buf = new StringBuffer (); 95 for (int i = 0; i < steps.size(); i++) { 96 buf.append(((StepExpr) steps.get(i)).toHashCodeString()); 97 } 98 hashCodeString = buf.toString(); 99 return hashCodeString; 100 } 101 102 110 113 public boolean equals(Object o) { 114 if (!(o instanceof PathExprImpl)) 115 return false; 116 return toHashCodeString().equals(((PathExprImpl)o).toHashCodeString()); 117 } 118 119 public int hashCode() { 121 String str = ((PathExprImpl)this).toHashCodeString(); 122 return str.hashCode(); 123 } 124 125 } 126 | Popular Tags |