blob: 72ca0138a53d3aacca7006b5efadf13fb9b61b8f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config;
import java.util.List;
/**
* @author gjoranv
* @since 5.1.4
*/
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, 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 when the library uses reflection via builders
@SuppressWarnings("unchecked")
protected NODE createNew() {
try {
return (NODE) defaultNode.getClass().newInstance();
} catch (IllegalAccessException | InstantiationException ex) {
throw new ConfigurationRuntimeException(ex);
}
}
}
|