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

graphql.language.FieldDefinition Maven / Gradle / Ivy

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


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static graphql.language.NodeUtil.directivesByName;

public class FieldDefinition extends AbstractNode {
    private final String name;
    private Type type;
    private final List inputValueDefinitions;
    private final List directives;

    public FieldDefinition(String name) {
        this(name, null, new ArrayList<>(), new ArrayList<>());
    }

    public FieldDefinition(String name, Type type) {
        this(name, type, new ArrayList<>(), new ArrayList<>());
    }

    public FieldDefinition(String name, Type type, List inputValueDefinitions, List directives) {
        this.name = name;
        this.type = type;
        this.inputValueDefinitions = inputValueDefinitions;
        this.directives = directives;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public List getInputValueDefinitions() {
        return inputValueDefinitions;
    }

    public List getDirectives() {
        return directives;
    }

    public Map getDirectivesByName() {
        return directivesByName(directives);
    }

    public Directive getDirective(String directiveName) {
        return getDirectivesByName().get(directiveName);
    }


    @Override
    public List getChildren() {
        List result = new ArrayList<>();
        result.add(type);
        result.addAll(inputValueDefinitions);
        result.addAll(directives);
        return result;
    }

    @Override
    public boolean isEqualTo(Node o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        FieldDefinition that = (FieldDefinition) o;

        return NodeUtil.isEqualTo(this.name, that.name);
    }

    @Override
    public FieldDefinition deepCopy() {
        return new FieldDefinition(name,
                deepCopy(type),
                deepCopy(inputValueDefinitions),
                deepCopy(directives)
        );
    }

    @Override
    public String toString() {
        return "FieldDefinition{" +
                "name='" + name + '\'' +
                ", type=" + type +
                ", inputValueDefinitions=" + inputValueDefinitions +
                ", directives=" + directives +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy