001/**
002 * Copyright (C) 2007 - 2016, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package org.dllearner.prolog;
020
021/**
022 * 
023 * @author Sebastian Bader
024 * 
025 */
026public class PredicateDefinition {
027        private String name;
028        private int arity;
029
030        public PredicateDefinition(String name, int arity) {
031                super();
032                this.name = name;
033                this.arity = arity;
034        }
035
036        public PredicateDefinition(Atom atom) {
037                this(atom.getName(), atom.getArity());
038        }
039
040        public int getArity() {
041                return arity;
042        }
043
044        public String getName() {
045                return name;
046        }
047
048        @Override
049        public int hashCode() {
050                return name.hashCode() * (arity + 1);
051        }
052
053        @Override
054        public boolean equals(Object obj) {
055                if (obj == null)
056                        return false;
057                try {
058                        PredicateDefinition pd = (PredicateDefinition) obj;
059                        if (pd.getArity() != getArity())
060                                return false;
061                        if (!pd.getName().equals(getName()))
062                                return false;
063                } catch (ClassCastException cce) {
064                        return false;
065                }
066                return true;
067        }
068
069        @Override
070        public String toString() {
071                return name + "/" + arity;
072        }
073
074}