graphql.language.AbstractNode Maven / Gradle / Ivy
package graphql.language;
import graphql.Assert;
import graphql.PublicApi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
@PublicApi
public abstract class AbstractNode implements Node {
private final SourceLocation sourceLocation;
private final List comments;
private final IgnoredChars ignoredChars;
private final Map additionalData;
public AbstractNode(SourceLocation sourceLocation, List comments, IgnoredChars ignoredChars) {
this(sourceLocation, comments, ignoredChars, Collections.emptyMap());
}
public AbstractNode(SourceLocation sourceLocation, List comments, IgnoredChars ignoredChars, Map additionalData) {
Assert.assertNotNull(comments, "comments can't be null");
Assert.assertNotNull(ignoredChars, "ignoredChars can't be null");
Assert.assertNotNull(additionalData, "additionalData can't be null");
this.sourceLocation = sourceLocation;
this.additionalData = unmodifiableMap(new LinkedHashMap<>(additionalData));
this.comments = unmodifiableList(new ArrayList<>(comments));
this.ignoredChars = ignoredChars;
}
@Override
public SourceLocation getSourceLocation() {
return sourceLocation;
}
@Override
public List getComments() {
return comments;
}
@Override
public IgnoredChars getIgnoredChars() {
return ignoredChars;
}
public Map getAdditionalData() {
return additionalData;
}
@SuppressWarnings("unchecked")
protected V deepCopy(V nullableObj) {
if (nullableObj == null) {
return null;
}
return (V) nullableObj.deepCopy();
}
@SuppressWarnings("unchecked")
protected List deepCopy(List extends Node> list) {
if (list == null) {
return null;
}
return list.stream().map(Node::deepCopy).map(node -> (V) node).collect(Collectors.toList());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy