diff options
author | gjoranv <gv@yahoo-inc.com> | 2017-07-19 00:43:22 +0200 |
---|---|---|
committer | gjoranv <gv@yahoo-inc.com> | 2017-07-19 10:40:57 +0200 |
commit | eb363cee950aae3613bef708a402c31c6a5c21fd (patch) | |
tree | fe39c22a3b8e7707340d374bb57eabdc5c084d74 /config-lib/src | |
parent | a200877eb3011661e982405135ada581041928f6 (diff) |
Remove InnerNodeVector.defaultNode and add a new primary ctor.
- defaultNode was a remnant used by the now removed setSize()
Diffstat (limited to 'config-lib/src')
3 files changed, 5 insertions, 52 deletions
diff --git a/config-lib/src/main/java/com/yahoo/config/InnerNodeVector.java b/config-lib/src/main/java/com/yahoo/config/InnerNodeVector.java index 2c0287b5ff4..2b12de8c3fc 100644 --- a/config-lib/src/main/java/com/yahoo/config/InnerNodeVector.java +++ b/config-lib/src/main/java/com/yahoo/config/InnerNodeVector.java @@ -1,9 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; import java.util.List; /** @@ -12,52 +9,13 @@ import java.util.List; */ public class InnerNodeVector<NODE extends InnerNode> extends NodeVector<NODE> { - NODE defaultNode; - - /** - * 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 InnerNodeVector(NODE defaultNode) { - assert (defaultNode != null) : "The default node cannot be null"; - - this.defaultNode = defaultNode; - if (createNew() == null) { - throw new NullPointerException("Unable to duplicate the default node."); - } + public InnerNodeVector(List<NODE> nodes) { + vector.addAll(nodes); } + // TODO: Remove for Vespa 7 public InnerNodeVector(List<NODE> nodes, NODE defaultNode) { - this(defaultNode); - for (NODE node : nodes) { - vector.add(node); - } - } - - /** - * Creates a new Node by creating a new instance with the 0-argument constructor - */ - // TODO: remove, only used for NodeVector.setSize which only seems to be used by unit tests. - @SuppressWarnings("unchecked") - protected NODE createNew() { - try { - Class<? extends InnerNode> nodeClass = defaultNode.getClass(); - Class<?> builderClass = Arrays.stream(nodeClass.getClasses()) - .filter(klass -> klass.getSimpleName().equals("Builder")) - .findFirst() - .orElseThrow(() -> new ConfigurationRuntimeException("Could not find builder class for " + nodeClass.getName())); - - Constructor<?> builderCtor = builderClass.getConstructor(); - Object builderInstance = builderCtor.newInstance(); - if (! (builderInstance instanceof ConfigBuilder)) - throw new ConfigurationRuntimeException("Builder is not a ConfigBuilder, has class: " + builderInstance.getClass().getName()); - - Constructor<? extends InnerNode> nodeCtor = nodeClass.getDeclaredConstructor(builderClass, boolean.class); - nodeCtor.setAccessible(true); - return (NODE) nodeCtor.newInstance(builderInstance, false); - } catch (InvocationTargetException | IllegalAccessException | InstantiationException | NoSuchMethodException e) { - throw new ConfigurationRuntimeException(e); - } + this(nodes); } } 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..e6dd8f3091f 100644 --- a/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java +++ b/config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java @@ -45,7 +45,7 @@ public class LeafNodeVector<REAL, NODE extends LeafNode<REAL>> extends NodeVecto * Creates a new Node by cloning the default node. */ @SuppressWarnings("unchecked") - protected NODE createNew() { + private NODE createNew() { return (NODE) (defaultNode).clone(); } diff --git a/config-lib/src/main/java/com/yahoo/config/NodeVector.java b/config-lib/src/main/java/com/yahoo/config/NodeVector.java index 0b8cf6a049b..79a6b0658ef 100644 --- a/config-lib/src/main/java/com/yahoo/config/NodeVector.java +++ b/config-lib/src/main/java/com/yahoo/config/NodeVector.java @@ -15,11 +15,6 @@ public abstract class NodeVector<NODE> implements java.util.List<NODE> { protected final ArrayList<NODE> vector = new ArrayList<NODE>(); /** - * Creates a new Node. - */ - protected abstract NODE createNew(); - - /** * Returns the number of elements in this NodeVector. * Alias for size(). * |