aima.core.logic.fol.parsing.ast.Constant Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aima-core Show documentation
Show all versions of aima-core Show documentation
AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.
The newest version!
package aima.core.logic.fol.parsing.ast;
import java.util.List;
import aima.core.logic.fol.parsing.FOLVisitor;
/**
* @author Ravi Mohan
* @author Ciaran O'Reilly
*/
public class Constant implements Term {
private String value;
private int hashCode = 0;
public Constant(String s) {
value = s;
}
public String getValue() {
return value;
}
//
// START-Term
public String getSymbolicName() {
return getValue();
}
public boolean isCompound() {
return false;
}
public List getArgs() {
// Is not Compound, therefore should
// return null for its arguments
return null;
}
public Object accept(FOLVisitor v, Object arg) {
return v.visitConstant(this, arg);
}
public Constant copy() {
return new Constant(value);
}
// END-Term
//
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Constant)) {
return false;
}
Constant c = (Constant) o;
return c.getValue().equals(getValue());
}
@Override
public int hashCode() {
if (0 == hashCode) {
hashCode = 17;
hashCode = 37 * hashCode + value.hashCode();
}
return hashCode;
}
@Override
public String toString() {
return value;
}
}