diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-06-29 18:22:05 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-06-29 18:22:05 +0200 |
commit | 0ea6bd254a9b0efc986055431ce9eefc7c63840c (patch) | |
tree | ee2d400a7ad48c91f35f9cc66a8d9084a8e7ea84 /container-core | |
parent | 63d415951811b71dc94dec840673160f76e1a0a0 (diff) |
Use List.of/copyOf instead of ImmutableList.
Diffstat (limited to 'container-core')
-rw-r--r-- | container-core/src/main/java/com/yahoo/processing/request/CompoundName.java | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java index efed58f4ab0..205352c4d49 100644 --- a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java +++ b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java @@ -1,10 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.processing.request; -import com.google.common.collect.ImmutableList; - import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import static com.yahoo.text.Lowercase.toLowerCase; @@ -25,7 +22,7 @@ public final class CompoundName { private final String name; private final String lowerCasedName; - private final ImmutableList<String> compounds; + private final List<String> compounds; /** A hashcode which is always derived from the compounds (NEVER the string) */ private final int hashCode; @@ -42,12 +39,12 @@ public final class CompoundName { * @throws NullPointerException if name is null */ public CompoundName(String name) { - this(name, parse(name)); + this(name, parse(name, null)); } /** Constructs this from an array of name components which are assumed not to contain dots */ public static CompoundName fromComponents(String ... components) { - return new CompoundName(Arrays.asList(components)); + return new CompoundName(List.of(components)); } /** Constructs this from a list of compounds. */ @@ -68,9 +65,9 @@ public final class CompoundName { this.name = name; this.lowerCasedName = toLowerCase(name); if (compounds.size() == 1 && compounds.get(0).isEmpty()) - this.compounds = ImmutableList.of(); + this.compounds = List.of(); else - this.compounds = ImmutableList.copyOf(compounds); + this.compounds = List.copyOf(compounds); this.hashCode = this.compounds.hashCode(); int size = this.compounds.size(); @@ -78,9 +75,7 @@ public final class CompoundName { : size == 1 ? empty : this; // size==0 -> this needed during construction of empty } - private static List<String> parse(String s) { - ArrayList<String> l = null; - + private static List<String> parse(String s, List<String> l) { int p = 0; final int m = s.length(); for (int i = 0; i < m; i++) { @@ -91,7 +86,7 @@ public final class CompoundName { } } if (p == 0) { - return ImmutableList.of(s); + return List.of(s); } else if (p < m) { l.add(s.substring(p, m)); } else { @@ -108,8 +103,7 @@ public final class CompoundName { public CompoundName append(String name) { if (name.isEmpty()) return this; if (isEmpty()) return new CompoundName(name); - List<String> newCompounds = new ArrayList<>(compounds); - newCompounds.addAll(parse(name)); + List<String> newCompounds = parse(name, new ArrayList<>(compounds)); return new CompoundName(concat(this.name, name), newCompounds); } @@ -126,7 +120,7 @@ public final class CompoundName { return new CompoundName(concat(this.name, name.name), newCompounds); } - private String concat(String name1, String name2) { + private static String concat(String name1, String name2) { return name1 + "." + name2; } @@ -141,7 +135,7 @@ public final class CompoundName { if (isEmpty()) return fromComponents(nameParts); List<String> newCompounds = new ArrayList<>(nameParts.length + compounds.size()); - newCompounds.addAll(Arrays.asList(nameParts)); + newCompounds.addAll(List.of(nameParts)); newCompounds.addAll(this.compounds); return new CompoundName(newCompounds); } |