public class NamePattern extends PatternNode {
char[] pattern;
int starCount = 0;
+ private int hashcode = -1;
public static final NamePattern ELLIPSIS = new NamePattern("");
public static final NamePattern ANY = new NamePattern("*");
for (int i=0, len=pattern.length; i<len; i++) {
if (pattern[i] == '*') starCount++;
}
+ hashcode = new String(pattern).hashCode();
}
public boolean matches(char[] a2) {
public boolean equals(Object other) {
if (other instanceof NamePattern) {
NamePattern otherPat = (NamePattern)other;
- return otherPat.starCount == this.starCount &&
- new String(otherPat.pattern).equals(new String(this.pattern));
+ if (otherPat.starCount!=this.starCount) return false;
+ if (otherPat.pattern.length!=this.pattern.length) return false;
+ for (int i = 0; i < this.pattern.length; i++) {
+ if (this.pattern[i]!=otherPat.pattern[i]) return false;
+ }
+ return true;
}
return false;
}
+
public int hashCode() {
- return new String(pattern).hashCode();
+ return hashcode;
}
private TypePatternList parameterTypes;
private ThrowsPattern throwsPattern;
private AnnotationTypePattern annotationPattern;
+ private transient int hashcode = -1;
public SignaturePattern(Member.Kind kind, ModifiersPattern modifiers,
TypePattern returnType, TypePattern declaringType,
annotationPattern = annotationPattern.resolveBindings(scope,bindings,false);
checkForIncorrectTargetKind(annotationPattern,scope,true);
}
-
+ hashcode =-1;
return this;
}
&& o.annotationPattern.equals(this.annotationPattern);
}
public int hashCode() {
- int result = 17;
- result = 37*result + kind.hashCode();
- result = 37*result + modifiers.hashCode();
- result = 37*result + returnType.hashCode();
- result = 37*result + declaringType.hashCode();
- result = 37*result + name.hashCode();
- result = 37*result + parameterTypes.hashCode();
- result = 37*result + throwsPattern.hashCode();
- result = 37*result + annotationPattern.hashCode();
- return result;
+ if (hashcode==-1) {
+ hashcode = 17;
+ hashcode = 37*hashcode + kind.hashCode();
+ hashcode = 37*hashcode + modifiers.hashCode();
+ hashcode = 37*hashcode + returnType.hashCode();
+ hashcode = 37*hashcode + declaringType.hashCode();
+ hashcode = 37*hashcode + name.hashCode();
+ hashcode = 37*hashcode + parameterTypes.hashCode();
+ hashcode = 37*hashcode + throwsPattern.hashCode();
+ hashcode = 37*hashcode + annotationPattern.hashCode();
+ }
+ return hashcode;
}
public void write(DataOutputStream s) throws IOException {