package models.terms.meta;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import lombok.Getter;
import models.algebra.Constant;
import models.algebra.Expression;
import models.algebra.Symbol;
import models.algebra.Variable;
import models.terms.RDLTerm;
import models.terms.Resource;
import models.terms.ResourceConstant;
@Getter
public class MetaResource extends MetaVariable {
public MetaResource(Variable variableName, OrderConstraint constraint, Expression order) {
super(MetaRDLTerm.TermType.META_RESOURCE_VARIABLE, variableName, constraint, order);
}
public MetaResource(Variable variableName) {
super(MetaRDLTerm.TermType.META_RESOURCE_VARIABLE, variableName, OrderConstraint.ANY, new Constant("0"));
}
public MetaResource(Variable variableName, Expression order) {
super(MetaRDLTerm.TermType.META_RESOURCE_VARIABLE, variableName, OrderConstraint.EQ, order);
}
@Override
public Set<MatchConstraint> isMatchedBy(RDLTerm another, MatchConstraint constraint) {
Set<MatchConstraint> result = new HashSet<>();
Map<Variable, RDLTerm> binding = constraint.getBinding();
Map<Variable, OrderVariableConstraint> orderConstraint = constraint.getOrderConstraint();
if ((! (another instanceof Resource)) && (! (another instanceof ResourceConstant))) {
return result;
}
if (! orderConstraintCheck(another, orderConstraint)) {
return result;
}
if (! islinearRightNormalizedMatchedBy(another)) {
return result;
}
if (! binding.containsKey(this.variableName)) {
binding.put(this.variableName, another);
result.add(new MatchConstraint(binding, orderConstraint));
}
else if (binding.get(this.variableName).equals(another)) {
result.add(new MatchConstraint(binding, orderConstraint));
}
return result;
}
}