summaryrefslogtreecommitdiffstats
path: root/processing
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-04-14 08:30:39 +0200
committerJon Bratseth <bratseth@gmail.com>2020-04-14 08:30:39 +0200
commit3a6f4ba76bca8c8dddd4df16972f1a3ede097a23 (patch)
tree5dcb0a992b700a55a99f3abaa516035796ae3039 /processing
parente40c993de0b870a2aec7fff91a64ac229b36fd0b (diff)
Compute string on the fly
Diffstat (limited to 'processing')
-rw-r--r--processing/src/main/java/com/yahoo/processing/request/CompoundName.java58
1 files changed, 14 insertions, 44 deletions
diff --git a/processing/src/main/java/com/yahoo/processing/request/CompoundName.java b/processing/src/main/java/com/yahoo/processing/request/CompoundName.java
index 976fb3e2796..2185aac7adc 100644
--- a/processing/src/main/java/com/yahoo/processing/request/CompoundName.java
+++ b/processing/src/main/java/com/yahoo/processing/request/CompoundName.java
@@ -20,12 +20,6 @@ import static com.yahoo.text.Lowercase.toLowerCase;
*/
public final class CompoundName {
- /**
- * The string name of this compound.
- */
- private final String name;
- private final String lowerCasedName;
-
private final ImmutableList<String> compounds;
/** A hashcode which is always derived from the compounds (NEVER the string) */
@@ -43,7 +37,7 @@ public final class CompoundName {
* @throws NullPointerException if name is null
*/
public CompoundName(String name) {
- this(name, parse(name));
+ this(parse(name));
}
/** Constructs this from an array of name components which are assumed not to contain dots */
@@ -53,21 +47,6 @@ public final class CompoundName {
/** Constructs this from a list of compounds. */
public CompoundName(List<String> compounds) {
- this(toCompoundString(compounds), compounds);
- }
-
- /**
- * Constructs this from a name with already parsed compounds.
- * Private to avoid creating names with inconsistencies.
- *
- * @param name the string representation of the compounds
- * @param compounds the compounds of this name
- */
- private CompoundName(String name, List<String> compounds) {
- if (name == null) throw new NullPointerException("Name can not be null");
-
- this.name = name;
- this.lowerCasedName = toLowerCase(name);
if (compounds.size()==1 && compounds.get(0).isEmpty())
this.compounds = ImmutableList.of();
else
@@ -111,7 +90,7 @@ public final class CompoundName {
if (isEmpty()) return new CompoundName(name);
List<String> newCompounds = new ArrayList<>(compounds);
newCompounds.addAll(parse(name));
- return new CompoundName(concat(this.name, name), newCompounds);
+ return new CompoundName(newCompounds);
}
/**
@@ -124,11 +103,7 @@ public final class CompoundName {
if (isEmpty()) return name;
List<String> newCompounds = new ArrayList<>(compounds);
newCompounds.addAll(name.compounds);
- return new CompoundName(concat(this.name, name.name), newCompounds);
- }
-
- private String concat(String name1, String name2) {
- return name1 + "." + name2;
+ return new CompoundName(newCompounds);
}
/**
@@ -242,14 +217,11 @@ public final class CompoundName {
public boolean hasPrefix(CompoundName prefix) {
if (prefix.size() > this.size()) return false;
- int prefixLength = prefix.name.length();
- if (prefixLength == 0)
- return true;
-
- if (name.length() > prefixLength && name.charAt(prefixLength) != '.')
- return false;
-
- return name.startsWith(prefix.name);
+ for (int i = 0; i < prefix.size(); i++) {
+ if ( ! this.compounds.get(i).equals(prefix.get(i)))
+ return false;
+ }
+ return true;
}
/**
@@ -267,24 +239,22 @@ public final class CompoundName {
if (o == this) return true;
if ( ! (o instanceof CompoundName)) return false;
CompoundName other = (CompoundName)o;
- return this.name.equals(other.name);
+ return this.compounds.equals(other.compounds);
}
/**
* Returns the string representation of this - all the name components in order separated by dots.
*/
@Override
- public String toString() { return name; }
-
- public String getLowerCasedName() {
- return lowerCasedName;
- }
-
- private static String toCompoundString(List<String> compounds) {
+ public String toString() {
StringBuilder b = new StringBuilder();
for (String compound : compounds)
b.append(compound).append(".");
return b.length()==0 ? "" : b.substring(0, b.length()-1);
}
+ public String getLowerCasedName() {
+ return toString().toLowerCase();
+ }
+
}