
org.nosceon.connellite.NodeRef Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2013 the original author or authors.
*
* 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 org.nosceon.connellite;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
/**
* @author Johan Siebens
*/
final class NodeRef {
private final AtomicReference ref = new AtomicReference<>(Node.newNode());
public NodeRef() {
}
public Node node() {
return ref.get();
}
public NodeRef(NodeRef nodeRef) {
this.ref.set(nodeRef.ref.get());
}
public int hashCode(String path) {
Node node = node(path);
return node == null ? -1 : node.hashCode();
}
public void set(Node node) {
this.ref.set(node);
}
public int size(String path) {
Node node = node(path);
return node == null ? -1 : node.size();
}
public Map toMap(String path) {
return ref.get().node(path).toMap();
}
public String value(String path) {
Node node = node(path);
return node == null ? null : node.value();
}
public List values(String path) {
Node node = node(path);
return node == null ? emptyList() : node.values();
}
private List emptyList() {
return Collections. emptyList();
}
private Node node(String path) {
return ref.get().node(path);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy