org.ggp.base.util.gdl.grammar.GdlOr Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alloy-ggp-base Show documentation
Show all versions of alloy-ggp-base Show documentation
A modified version of the GGP-Base library for Alloy.
The newest version!
package org.ggp.base.util.gdl.grammar;
import java.util.List;
import com.google.common.collect.ImmutableList;
public final class GdlOr extends GdlLiteral
{
private static final long serialVersionUID = 1L;
private final ImmutableList disjuncts;
private transient Boolean ground;
GdlOr(ImmutableList disjuncts)
{
this.disjuncts = disjuncts;
ground = null;
}
public int arity()
{
return disjuncts.size();
}
private boolean computeGround()
{
for (GdlLiteral literal : disjuncts)
{
if (!literal.isGround())
{
return false;
}
}
return true;
}
public GdlLiteral get(int index)
{
return disjuncts.get(index);
}
public List getDisjuncts() {
return disjuncts;
}
@Override
public boolean isGround()
{
if (ground == null)
{
ground = computeGround();
}
return ground;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("( or ");
for (GdlLiteral literal : disjuncts)
{
sb.append(literal + " ");
}
sb.append(")");
return sb.toString();
}
}