com.yahoo.config.ModelNode Maven / Gradle / Ivy
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Represents a 'model' in a {@link ConfigInstance}.
*
* @author bratseth
*/
public class ModelNode extends LeafNode {
private final ModelReference reference;
public ModelNode() {
this.value = null;
this.reference = null;
}
public ModelNode(ModelReference modelReference) {
super(true);
this.value = modelReference.value(); // The resolved value, or null if not resolved
this.reference = modelReference;
}
@Override
public String getValue() {
return reference.toString();
}
@Override
public String toString() {
return (value == null) ? "(null)" : '"' + getValue() + '"';
}
@Override
protected boolean doSetValue(String stringVal) {
throw new UnsupportedOperationException();
}
public ModelReference getModelReference() {
return reference;
}
public static List toModelReferences(List modelNodes) {
List modelReferences = new ArrayList<>();
for (ModelNode modelNode : modelNodes)
modelReferences.add(modelNode.getModelReference());
return modelReferences;
}
public static Map toModelReferenceMap(Map nodeMap) {
Map referenceMap = new LinkedHashMap<>();
for (var entry : nodeMap.entrySet()) {
referenceMap.put(entry.getKey(), entry.getValue().getModelReference());
}
return referenceMap;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy