aboutsummaryrefslogtreecommitdiffstats
path: root/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java
diff options
context:
space:
mode:
Diffstat (limited to 'config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java')
-rw-r--r--config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java41
1 files changed, 18 insertions, 23 deletions
diff --git a/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java b/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java
index c2fed5b9e5a..9bbd9b594f8 100644
--- a/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java
+++ b/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java
@@ -16,47 +16,42 @@ import java.util.List;
*/
public class LeafNodeVector<REAL, NODE extends LeafNode<REAL>> extends NodeVector<NODE> {
- NODE defaultNode;
+ private final List<REAL> realValues;
- /**
- * Creates a new vector with the given default node.
- */
- // TODO: remove this ctor when the library uses reflection via builders, and resizing won't be necessary
- public LeafNodeVector(NODE defaultNode) {
+ // TODO: take class instead of default node
+ public LeafNodeVector(List<REAL> values, NODE defaultNode) {
assert (defaultNode != null) : "The default node cannot be null";
- this.defaultNode = defaultNode;
- if (createNew() == null) {
+ if (createNew(defaultNode) == null) {
throw new NullPointerException("Unable to duplicate the default node.");
}
- }
- // TODO: take class instead of default node when the library uses reflection via builders
- public LeafNodeVector(List<REAL> values, NODE defaultNode) {
- this(defaultNode);
for (REAL value : values) {
- NODE node = createNew();
+ NODE node = createNew(defaultNode);
node.value = value;
vector.add(node);
}
+ realValues = realList(vector);
+ }
+
+ public List<REAL> asList() {
+ return realValues;
}
/**
* Creates a new Node by cloning the default node.
*/
@SuppressWarnings("unchecked")
- protected NODE createNew() {
+ private static <NODE extends LeafNode<?>> NODE createNew(NODE defaultNode) {
return (NODE) (defaultNode).clone();
}
- // TODO: create unmodifiable list in ctor when the library uses reflection via builders
- @SuppressWarnings("unchecked")
- public List<REAL> asList() {
- List<REAL> ret = new ArrayList<REAL>();
- for(NODE node : vector) {
- ret.add(node.value());
+ private static<REAL, NODE extends LeafNode<REAL>> List<REAL> realList(List<NODE> nodes) {
+ List<REAL> reals = new ArrayList<>();
+ for(NODE node : nodes) {
+ reals.add(node.value());
}
- return Collections.unmodifiableList(ret);
+ return Collections.unmodifiableList(reals);
}
// TODO: Try to eliminate the need for this method when we have moved FileAcquirer to the config library
@@ -66,7 +61,7 @@ public class LeafNodeVector<REAL, NODE extends LeafNode<REAL>> extends NodeVecto
for (String s : values)
fileReferences.add(new FileReference(ReferenceNode.stripQuotes(s)));
- return new LeafNodeVector<FileReference, FileNode>(fileReferences, new FileNode());
+ return new LeafNodeVector<>(fileReferences, new FileNode());
}
public static LeafNodeVector<Path, PathNode> createPathNodeVector(Collection<FileReference> values) {
@@ -74,6 +69,6 @@ public class LeafNodeVector<REAL, NODE extends LeafNode<REAL>> extends NodeVecto
for (FileReference fileReference : values)
paths.add(Paths.get(fileReference.value()));
- return new LeafNodeVector<Path, PathNode>(paths, new PathNode());
+ return new LeafNodeVector<>(paths, new PathNode());
}
}