graphql.language.FragmentSpread Maven / Gradle / Ivy
package graphql.language;
import graphql.Internal;
import graphql.PublicApi;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
@PublicApi
public class FragmentSpread extends AbstractNode implements Selection, DirectivesContainer {
private final String name;
private final List directives;
@Internal
protected FragmentSpread(String name, List directives, SourceLocation sourceLocation, List comments) {
super(sourceLocation, comments);
this.name = name;
this.directives = new ArrayList<>(directives);
}
/**
* alternative to using a Builder for convenience
*/
public FragmentSpread(String name) {
this(name, new ArrayList<>(), null, new ArrayList<>());
}
@Override
public String getName() {
return name;
}
@Override
public List getDirectives() {
return new ArrayList<>(directives);
}
@Override
public boolean isEqualTo(Node o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FragmentSpread that = (FragmentSpread) o;
return NodeUtil.isEqualTo(this.name, that.name);
}
@Override
public List getChildren() {
List result = new ArrayList<>();
result.addAll(directives);
return result;
}
@Override
public FragmentSpread deepCopy() {
return new FragmentSpread(name, deepCopy(directives), getSourceLocation(), getComments());
}
@Override
public String toString() {
return "FragmentSpread{" +
"name='" + name + '\'' +
", directives=" + directives +
'}';
}
@Override
public TraversalControl accept(TraverserContext context, NodeVisitor visitor) {
return visitor.visitFragmentSpread(this, context);
}
public static Builder newFragmentSpread() {
return new Builder();
}
public static Builder newFragmentSpread(String name) {
return new Builder().name(name);
}
public FragmentSpread transform(Consumer builderConsumer) {
Builder builder = new Builder(this);
builderConsumer.accept(builder);
return builder.build();
}
public static final class Builder implements NodeBuilder {
private SourceLocation sourceLocation;
private List comments = new ArrayList<>();
private String name;
private List directives = new ArrayList<>();
private Builder() {
}
private Builder(FragmentSpread existing) {
this.sourceLocation = existing.getSourceLocation();
this.comments = existing.getComments();
this.name = existing.getName();
this.directives = existing.getDirectives();
}
public Builder sourceLocation(SourceLocation sourceLocation) {
this.sourceLocation = sourceLocation;
return this;
}
public Builder comments(List comments) {
this.comments = comments;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder directives(List directives) {
this.directives = directives;
return this;
}
public FragmentSpread build() {
FragmentSpread fragmentSpread = new FragmentSpread(name, directives, sourceLocation, comments);
return fragmentSpread;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy