001    /*
002     * Created on Sep 14, 2003 by Ravi Mohan
003     *
004     */
005    package aima.logic.fol.parsing.ast;
006    
007    import java.util.List;
008    
009    import aima.logic.fol.parsing.FOLVisitor;
010    
011    /**
012     * @author Ravi Mohan
013     * @author Ciaran O'Reilly
014     */
015    public class Constant implements Term {
016            private String value;
017            private int hashCode = 0;
018    
019            public Constant(String s) {
020                    value = s;
021            }
022    
023            public String getValue() {
024                    return value;
025            }
026    
027            //
028            // START-Term
029            public String getSymbolicName() {
030                    return getValue();
031            }
032    
033            public boolean isCompound() {
034                    return false;
035            }
036    
037            public List<Term> getArgs() {
038                    // Is not Compound, therefore should
039                    // return null for its arguments
040                    return null;
041            }
042    
043            public Object accept(FOLVisitor v, Object arg) {
044                    return v.visitConstant(this, arg);
045            }
046    
047            public Constant copy() {
048                    return new Constant(value);
049            }
050    
051            // END-Term
052            //
053    
054            @Override
055            public boolean equals(Object o) {
056    
057                    if (this == o) {
058                            return true;
059                    }
060                    if (!(o instanceof Constant)) {
061                            return false;
062                    }
063                    Constant c = (Constant) o;
064                    return c.getValue().equals(getValue());
065    
066            }
067    
068            @Override
069            public int hashCode() {
070                    if (0 == hashCode) {
071                            hashCode = 17;
072                            hashCode = 37 * hashCode + value.hashCode();
073                    }
074                    return hashCode;
075            }
076    
077            @Override
078            public String toString() {
079                    return value;
080            }
081    }