summaryrefslogtreecommitdiffstats
path: root/config-lib
diff options
context:
space:
mode:
authorHarald Musum <musum@yahoo-inc.com>2017-07-19 14:24:49 +0200
committerGitHub <noreply@github.com>2017-07-19 14:24:49 +0200
commitf47431033d153605a083e955a990b5310fabf949 (patch)
tree624087c5f23d9ca2fd3d0b6a64008e13f92607b2 /config-lib
parentff06432f7004264db920d955160ad32f911bbe96 (diff)
parent07062cb52dd1c9e9a43f8d4348f246bb58cc1110 (diff)
Merge pull request #2974 from yahoo/gjoranv/cleanup-LeafNodeVector
Refactor LeafNodeVector
Diffstat (limited to 'config-lib')
-rw-r--r--config-lib/src/main/java/com/yahoo/config/LeafNodeVector.java38
1 files changed, 17 insertions, 21 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..d1d5fc61915 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);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<REAL> asList() {
+ return realValues;
}
/**
* Creates a new Node by cloning the default node.
*/
@SuppressWarnings("unchecked")
- private 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