summaryrefslogtreecommitdiffstats
path: root/config-lib
diff options
context:
space:
mode:
authorgjoranv <gv@yahoo-inc.com>2017-07-19 12:12:21 +0200
committergjoranv <gv@yahoo-inc.com>2017-07-19 12:14:24 +0200
commit08cb10529409f97a8b2ff56e7d398436419c53fa (patch)
tree909412518fde7425726650d43df8230d158b0af1 /config-lib
parentff06432f7004264db920d955160ad32f911bbe96 (diff)
Refactor LeafNodeVector
- Remove unnecessary ctor. - Create unmodifiable list in ctor to reflect that the data is now immutable. - Remove defaultNode field.
Diffstat (limited to 'config-lib')
-rw-r--r--config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java36
1 files changed, 16 insertions, 20 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 e6dd8f3091f..a5dee11637f 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,43 @@ 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);
}
/**
* Creates a new Node by cloning the default node.
*/
@SuppressWarnings("unchecked")
- private NODE createNew() {
+ private 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>();
+ private List<REAL> realList(List<NODE> nodes) {
+ List<REAL> reals = new ArrayList<REAL>();
for(NODE node : vector) {
- ret.add(node.value());
+ reals.add(node.value());
}
- return Collections.unmodifiableList(ret);
+ return Collections.unmodifiableList(reals);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<REAL> asList() {
+ return realValues;
}
// TODO: Try to eliminate the need for this method when we have moved FileAcquirer to the config library