net.intelie.pipes.ast.CallNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pipes-api Show documentation
Show all versions of pipes-api Show documentation
Intelie Pipes' API classes and interfaces
package net.intelie.pipes.ast;
import net.intelie.pipes.Function;
import net.intelie.pipes.util.Escapes;
import net.intelie.pipes.util.Iterables;
import net.intelie.pipes.util.Preconditions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class CallNode implements AstNode {
private static final long serialVersionUID = 1L;
private final String name;
private final List children;
private final SourceLocation location;
private final int _hash;
public CallNode(SourceLocation location, String name, AstNode... children) {
this(location, name, Arrays.asList(children));
}
public CallNode(SourceLocation location, String name, List children) {
Preconditions.checkArgument(name != null, "must have name");
Preconditions.checkArgument(children != null, "children array must be non null");
Preconditions.checkArgument(children.stream().allMatch(Objects::nonNull), "must have non null children");
this.location = location;
this.name = name;
this.children = new ArrayList<>(children);
this._hash = Objects.hash(this.name, this.children);
}
public String getName() {
return name;
}
public List getArgs() {
return children;
}
@Override
public SourceLocation getLocation() {
return location;
}
@Override
public String toString() {
return Escapes.formatIdentifier(name) + "(" + Iterables.join(", ", children) + ")";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CallNode that = (CallNode) o;
return Objects.equals(this.name, that.name) &&
Objects.equals(this.children, that.children);
}
@Override
public int hashCode() {
return _hash;
}
}