⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleconstructor.java

📁 Mandarax是一个规则引擎的纯Java实现。它支持多类型的事实和基于反映的规则
💻 JAVA
字号:
/*
 * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.mandarax.kernel;


/**
 * Abstract super class for simple predicates.
 * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
 * @version 3.4 <7 March 05>
 * @since 1.3
 */
abstract class SimpleConstructor {

    private Class[] structure = null;
    private String  name      = null;

    /**
     * Constructor.
     */
    public SimpleConstructor() {
        super ();
    }

    /**
     * Constructor.
     * @param aName the name of the predicate
     * @param types the structure of the predicate (the types of the terms)
     */
    public SimpleConstructor(String aName, Class[] types) {
        super ();

        name      = aName;
        structure = types;
    }

    /**
     * Indicates whether the two objects are equal.
     * @return true if the objects are equal, false otherwise
     * @param obj the object to compare
     */
    public boolean equals(Object obj) {
        if(obj instanceof SimpleConstructor) {
            SimpleConstructor sc = (SimpleConstructor) obj;

            if(sc.name.equals (name)
                    && (structure.length == sc.structure.length)) {
                for(int i = 0; i < structure.length; i++) {
                    if(structure[i] != sc.structure[i]) {
                        return false;
                    }
                }

                return true;
            }
        }

        return false;
    }

    /**
     * Get the name of the predicate or function.
     * @return the name of the predicate or function
     */
    public String getName() {
        return name;
    }

    /**
     * Set the name of the predicate or function.
     * @param the name of the predicate or function
     */
    public void setName(String aName) {
        name = aName;
    }

    /**
     * Get the structure of the predicate or function.
     * @return the structure of the predicate or function
     */
    public Class[] getStructure() {
        return structure;
    }

    /**
     * Set the structure of the predicate or function.
     * @param struct the structure of the predicate or function
     */
    public void setStructure(Class[] struct) {
        structure = struct;
    }

    /**
     * Get the hashcode of the object.
     * @return the hash code value
     */
    public int hashCode() {
        int h = (name == null)
                ? 0
                : name.hashCode ();

        for(int i = 0; i < structure.length; i++) {
            h = h ^ structure[i].hashCode ();
        }

        return h;
    }

    /**
     * Perform the function or predicate using an array of terms as parameters.
     * @return the result of the perform operation
     * @param parameter an array of terms
     * @param session a session object
     * @throws java.lang.UnsupportedOperationException - thrown if this constructor does not have a sematics and this operation cannot be supported
     * @throws java.lang.IllegalArgumentException
     *
     */
    public Object perform(Term[] parameter,Session session) throws IllegalArgumentException, UnsupportedOperationException {
        throw new UnsupportedOperationException ("Simple predicates / simple functions do not suppot perform");
    }

    /**
     * Convert the object to a string.
     * @return the string representation of this object
     */
    public String toString() {
        return getName ();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -