All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.language.AbstractNode Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.language;


import graphql.Assert;
import graphql.PublicApi;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@PublicApi
public abstract class AbstractNode implements Node {

    private final SourceLocation sourceLocation;
    private final List comments;

    public AbstractNode(SourceLocation sourceLocation, List comments) {
        this.sourceLocation = sourceLocation;
        Assert.assertNotNull(comments, "comments can't be null");
        this.comments = new ArrayList<>(comments);
    }

    @Override
    public SourceLocation getSourceLocation() {
        return sourceLocation;
    }

    @Override
    public List getComments() {
        return new ArrayList<>(comments);
    }


    @SuppressWarnings("unchecked")
    protected  V deepCopy(V nullableObj) {
        if (nullableObj == null) {
            return null;
        }
        return (V) nullableObj.deepCopy();
    }

    @SuppressWarnings("unchecked")
    protected  List deepCopy(List list) {
        if (list == null) {
            return null;
        }
        return list.stream().map(Node::deepCopy).map(node -> (V) node).collect(Collectors.toList());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy