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 FunctionDefinition {
027    public static int TYPE_USUAL = 0;
028    public static int TYPE_INFIX = 1;
029    public static int TYPE_POSTFIX = 2;
030    public static int TYPE_PREFIX = 3;
031    
032    public static String[] TYPE_NAMES = new String[]{"usual", "infix", "postfix", "prefix"};
033    
034    private String name;
035    private int arity;
036    private int type;
037    
038    public FunctionDefinition(String name, int arity, int type) {
039        super();
040        this.name = name;
041        this.arity = arity;
042    }
043    
044    public FunctionDefinition(Function function) {
045        this(function.getName(), function.getArity(), function.getType());
046    }
047    
048    public int getArity() {
049        return arity;
050    }
051    public String getName() {
052        return name;
053    }
054    public int getType() {
055        return type;
056    }
057
058    @Override
059        public int hashCode() {
060        return name.hashCode() * (arity + 1);
061    }
062
063    @Override
064        public boolean equals(Object obj) {
065        if (obj == null)
066            return false;
067        try {
068            FunctionDefinition fd = (FunctionDefinition) obj;
069            if (fd.getArity() != getArity())
070                return false;
071            if (!fd.getName().equals(getName()))
072                return false;
073            if (fd.getType() != getType())
074                return false;
075        } catch (ClassCastException cce) {
076            return false;
077        }
078        return true;
079    }
080    
081    @Override
082        public String toString() {
083        return name+TYPE_NAMES[type]+"/"+arity;
084    }
085}