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

📄 factimpl.java

📁 Mandarax是一个规则引擎的纯Java实现。它支持多类型的事实和基于反映的规则
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	/**
	 * Get the positive literals.
	 * @return the collection of positive literals, this is a singleton containing only this object
	 */
	public java.util.List getPositiveLiterals() {
		if(posLiterals == null) {
			posLiterals = new java.util.Vector (1);
			posLiterals.add (this);
		}

		return posLiterals;
	}
	/**
	 * Get the predicate.
	 * @return the predicate
	 */
	public org.mandarax.kernel.Predicate getPredicate() {
		return predicate;
	}
	/**
	 * Get the hash code of a fact.
	 * @return the hash value
	 */
	public int hashCode() {
		int i = (predicate == null)
				? 0
				: predicate.hashCode ();

		if(terms.length == 0) {
			return i;
		}

		if(terms.length == 1) {
			return i ^ ((terms[0] == null)
						? 0
						: terms[0].hashCode ());
		} else {
			return i ^ ((terms[0] == null)
						? 0
						: terms[0].hashCode ()) ^ ((terms[terms.length - 1]
													== null)
												   ? 0
												   : terms[terms.length - 1]
													   .hashCode ());
		}
	}
	/**
	 * Indicates whether the clause is atomic.
	 * @return a boolean
	 */
	public boolean isAtomic() {
		return true;
	}
	/**
	 * Indicates whether the clause is the empty clause.
	 * @return false
	 */
	public boolean isEmpty() {
		return false;
	}
	/**
	 * Indicates whether the object (usually a term or a clause set) can be performed
	 * using the java semantics.
	 * @return a boolean
	 */
	public boolean isExecutable() {
		if((predicate != null) && predicate.isExecutable ()) {
			Term[] t = getTerms ();
			for(int i = 0; i < t.length; i++) {
				if( !t[i].isExecutable ()) {
					return false;
				}
			}

			return true;
		}

		return false;
	}
	/**
	 * Remove a clause set listener.
	 * @param l a listener
	 */
	public void removeClauseSetChangeListener(ClauseSetChangeListener l) {
		clauseSetChangeListener.remove (l);
	}
	/**
	 * Resolve a fact: if supported, the predicate
	 * should be performed using its semantic. E.g., for a fact
	 * like <i>isFather(Max,Jens)</i> the function <i>isFather</i> is performed
	 * for the objects (constant terms) <i>Max</i> and <i>Jens</i> and the result (e.g., <i>true</i>) is returned.
	 * Note that not all predicates support this (since not all predicates
	 * have a semantic), and the operation can also fail
	 * in case one term is variable. In these cases we throw appropriate exceptions.
	 * @param session a session object
	 * @return the result of resolving the term
	 * @throws java.lang.UnsupportedOperationException
	 * @throws java.lang.IllegalArgumentException
	 */
	public Object resolve(Session session) throws UnsupportedOperationException, IllegalArgumentException {
		return predicate.perform (terms,session);
	}
	/**
	 * Set a container.
	 * @param aContainerthe new container
	 */
	public void setContainer(ClauseSet aContainer) {
		container = aContainer;
	}
	/**
	 * Set a new predicate.
	 * @param p the predicate
	 */
	public void setPredicate(org.mandarax.kernel.Predicate p) {
		Predicate oldPredicate = predicate;
		predicate = p;
		terms     = new Term[p.getStructure ().length];
		types     = p.getStructure ();
		if((oldPredicate == null)
		   ? p != null
		   : !(oldPredicate.equals (p))) {
			fireClauseSetChangeEvent (new ClauseSetChangeEvent (this,
					oldPredicate, p, ClauseSetChangeEvent.KEY_CHANGED));
		}
	}
	/**
     * Get the facts.
     * @see org.mandarax.kernel.Query
     * @return an array of facts
     */
    public Fact[] getFacts() {
    	return facts;
    }
    /**
     * Set the facts. Not supported by facts, throws an exception!
     * Please use QueryImpl for queries!
     * @see org.mandarax.kernel.Query
     * @param facts an array of facts
     */
    public void setFacts(Fact[] facts) {
    	throw new UnsupportedOperationException("FactImpl does not support setFacts(). Please use QueryImpl for queries!");
    }

    /**
     * Get the common name of this query, i.e., something like "Find the oncle of a person".
     * @return a string
     */
    public String getName() {
    	return name;
    }

    /**
     * Set the common name of this query.
     * @param a name
     */
    public void setName(String queryName) {
    	name = queryName;
    }

    /**
	 * Indicates whether the fact is negated (negation as failure)
	 * @return always false
	 * @see PrerequisiteImpl
	 */
	public boolean isNegatedAF() {
		return false;
	}
		/**
	 * Set a property.
	 * @param key the key
	 * @param value the value
	 * @return the previous value of the specified key in this property list, or null if it did not have one.
	 */
	public Object setProperty(String key,String value) {
		if (delegate==null) delegate = new Properties();
		return delegate.setProperty(key,value);
	}
	/**
	 * Get a property.
	 * @param key the property key
	 * @return the respective value. The method returns null if the property is not found.
	 */
	public String getProperty(String key) {
		if (delegate==null) delegate = new Properties();
		return delegate.getProperty(key);
	}
	/**
	 * Returns an enumeration of all the keys in this property list, including distinct
	 * keys in the default property list if a key of the same name has not already been
	 * found from the main properties list.
	 * @return an enumeration of all the keys in this property list, including the keys in
	 * the default property list
	 */
	public Enumeration propertyNames() {
		if (delegate==null) delegate = new Properties();
		return delegate.propertyNames();
	}
	/**
	 * Remove a property.
	 * @param key the property key
	 * @return the value to which the key had been mapped, or null if the key did not have a mapping.
	 */
	public Object removeProperty(String key) {
		if (delegate!=null) return delegate.remove(key);
		return null;
	}
	/**
	 * Get the properties as one "properties" instance.
	 * @return a properties instance
	 */
	public Properties getProperties() {
		if (delegate==null) delegate = new Properties();
		return delegate;
	}
	/**
	 * Set the properties. Not required by the interface, but useful for bean (introspection-) based
	 * tools.
	 * @param properties the properties
	 */
	public void setProperties(Properties properties) {
		delegate = properties;
	}
	/**
	 * Get an iterator iterating over the predicates contained in this clause set.
	 * @return an iterator
	 */
	public Iterator predicates() {
		return new SingletonIterator(predicate);
	}
	/**
	 * Get the registered derivation event listeners.
	 * @return an array of listeners
	 */
	public DerivationEventListener[] getDerivationEventListeners() {
		throw new UnsupportedOperationException("Please use QueryImpl instead");
	}
	/**
	 * Set the derivation event listeners.
	 * @param listeners listeners
	 */
	public void setDerivationEventListeners(DerivationEventListener[] listeners) {
		throw new UnsupportedOperationException("Please use QueryImpl instead");
	}
	/**
	 * Indicates whether the clause is ground (= does not have variables). 
	 * @return a boolean
	 */
	public boolean isGround() {
		if (terms==null) return true;
		for (int i=0;i<terms.length;i++) 	
			if (terms[i].containsVariables()) return false;
		return true;
	}
}

⌨️ 快捷键说明

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