001    /*
002     * Created on Sep 15, 2003 by Ravi Mohan
003     *  
004     */
005    package aima.logic.propositional.parsing.ast;
006    
007    import java.util.List;
008    
009    import aima.logic.propositional.parsing.PLVisitor;
010    
011    /**
012     * @author Ravi Mohan
013     * 
014     */
015    
016    public class MultiSentence extends ComplexSentence {
017            private String operator;
018    
019            private List<Sentence> sentences;
020    
021            public MultiSentence(String operator, List<Sentence> sentences) {
022                    this.operator = operator;
023                    this.sentences = sentences;
024            }
025    
026            public String getOperator() {
027                    return operator;
028            }
029    
030            public List getSentences() {
031                    return sentences;
032            }
033    
034            @Override
035            public boolean equals(Object o) {
036    
037                    if (this == o) {
038                            return true;
039                    }
040                    if ((o == null) || (this.getClass() != o.getClass())) {
041                            return false;
042                    }
043                    MultiSentence sen = (MultiSentence) o;
044                    return ((sen.getOperator().equals(getOperator())) && (sen
045                                    .getSentences().equals(getSentences())));
046    
047            }
048    
049            @Override
050            public int hashCode() {
051                    int result = 17;
052                    for (Sentence s : sentences) {
053                            result = 37 * result + s.hashCode();
054                    }
055                    return result;
056            }
057    
058            @Override
059            public String toString() {
060                    String part1 = "( " + getOperator() + " ";
061                    for (int i = 0; i < getSentences().size(); i++) {
062                            part1 = part1 + sentences.get(i).toString() + " ";
063                    }
064                    return part1 + " ) ";
065            }
066    
067            @Override
068            public Object accept(PLVisitor plv, Object arg) {
069                    return plv.visitMultiSentence(this, arg);
070            }
071    
072    }