[Minor] Locator caches toString and hashcode

This commit is contained in:
Robert von Burg 2017-06-13 10:27:31 +02:00
parent 5bf7cd8b72
commit 79122f2887
1 changed files with 12 additions and 5 deletions

View File

@ -55,6 +55,9 @@ public class Locator {
*/ */
private final List<String> pathElements; private final List<String> pathElements;
private String asString;
private Integer hashcode;
/** /**
* Constructs a new {@link Locator} with the given list of path elements * Constructs a new {@link Locator} with the given list of path elements
* *
@ -198,7 +201,9 @@ public class Locator {
*/ */
@Override @Override
public String toString() { public String toString() {
return formatPath(this.pathElements); if (this.asString == null)
this.asString = formatPath(this.pathElements);
return this.asString;
} }
/** /**
@ -276,10 +281,12 @@ public class Locator {
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; if (this.hashcode == null) {
int result = 1; final int prime = 31;
result = prime * result + ((this.pathElements == null) ? 0 : this.pathElements.hashCode()); this.hashcode = prime * 1 + ((this.pathElements == null) ? 0 : this.pathElements.hashCode());
return result; }
return this.hashcode;
} }
@Override @Override