
com.hazelcast.internal.config.override.ConfigNode Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.internal.config.override;
import javax.annotation.Nonnull;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* A representation of a single generic configuration node.
*
* Used while overriding configuration with environment variables/system properties.
*/
class ConfigNode {
private final ConfigNode parent;
private final String name;
private final Map children = new LinkedHashMap<>();
private String value;
private boolean isRead;
ConfigNode(@Nonnull String name) {
this(name, null);
}
ConfigNode(String name, ConfigNode parent) {
Objects.requireNonNull(name);
this.name = name;
this.parent = parent;
}
boolean isRead() {
return isRead;
}
String getName() {
return name;
}
boolean hasValue() {
return value != null;
}
String getValue() {
isRead = true;
return value;
}
void setValue(String value) {
this.value = value;
}
Map getChildren() {
return children;
}
Optional getParent() {
return Optional.ofNullable(parent);
}
@Override
public String toString() {
return String.format("ConfigNode{name='%s', children=%s, value='%s'}", name, children, value);
}
}