Show Rule.java syntax highlighted
/*
* Rule.java
*
* Created on October 16, 2006, 3:01 AM
*
* Description:
*
* Copyright (C) 2006 Stephen L. Reed.
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.texai.kb.ejb.entity;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import org.texai.kb.Constants;
/**
* Entity class Rule
*
* @author reed
*/
@Entity
@NamedQuery(name=Constants.QUERY_FIND_RULE_BY_FORMULA_STRING,
query="SELECT r FROM Rule r, RuleInfo ri, Formula f, FormulaInfo fi WHERE fi.formulaString = :formulaString AND fi.formula = f "
+ "AND ri.formula = f AND ri.rule = r")
public class Rule extends AbstractTerm {
/**
* Determines if a de-serialized file is compatible with this class.
*
* Maintainers must change this value if and only if the new version
* of this class is not compatible with old versions. See Sun docs
* for <a href=http://java.sun.com/products/jdk/1.1/docs/guide
* /serialization/spec/version.doc.html> details. </a>
*
* Not necessary to include in first version of the class, but
* included here as a reminder of its importance.
*/
@Transient
private static final long serialVersionUID = 1L;
/** the rule information */
@OneToOne(fetch=FetchType.LAZY, mappedBy = "rule", cascade=CascadeType.ALL)
private RuleInfo ruleInfo; // NOPMD
/** Creates a new instance of Rule. */
public Rule() {
super();
}
/** Creates a new instance of Rule.
*
* @param formula the formula
* @param context the context
* @param strength the strength
* @param creator the creator
* @param creationPurpose the creation purpose
* @param creationDate the creation date
*/
public Rule(
final Formula formula,
final AbstractReifiedTerm context,
final Double strength,
final AbstractReifiedTerm creator,
final AbstractReifiedTerm creationPurpose,
final TimePoint creationDate) {
super();
//Preconditions
assert formula != null : "formula must not be null";
ruleInfo = new RuleInfo(
this,
formula,
context,
strength,
creator,
creationPurpose,
creationDate);
}
/** Gets the rule information.
*
* @return rule information
*/
public RuleInfo getRuleInfo() {
return ruleInfo;
}
/** Returns the formula.
*
* @return the formula
*/
public Formula getFormula() {
return getRuleInfo().getFormula();
}
/** Returns the assertion context (i.e. Cyc microtheory).
*
* @return the assertion context (i.e. Cyc microtheory)
*/
public AbstractReifiedTerm getContext() {
return getRuleInfo().getContext();
}
/** Gets the assertion strength
*
* @return the assertion strength
*/
public Double getStrength() {
return getRuleInfo().getStrength();
}
/** Sets the assertion strength.
*
* @param strength the assertion strength
*/
public void setStrength(final Double strength) {
//Preconditions
assert strength != null : "strength must not be null";
getRuleInfo().setStrength(strength);
}
/** Gets the creator.
*
* @return the creator
*/
public AbstractReifiedTerm getCreator() {
return getRuleInfo().getCreator();
}
/** Gets the creation purpose.
*
* @return the creation purpose
*/
public AbstractReifiedTerm getCreationPurpose() {
return getRuleInfo().getCreationPurpose();
}
/** Gets the creation time point.
*
* @return the creation time point
*/
public TimePoint getCreationTimePoint() {
return getRuleInfo().getCreationTimePoint();
}
/**
* Returns a hash code value for the object. This implementation computes
* a hash code value based on the unchanging clobValue.
* @return a hash code value for this object
*/
@Override
public int hashCode() {
return getRuleInfo().hashCode();
}
/**
* Determines whether another object is equal to this object.
*
* @param object the reference object with which to compare
* @return <code>true</code> if this object is the same as the argument;
* <code>false</code> otherwise.
*/
@Override
public boolean equals(final Object object) {
if (!(object instanceof Rule)) {
return false;
}
final Rule that = (Rule) object;
return this.getFormula().equals(that.getFormula());
}
/** Returns a string representation of this object.
*
* @return a string representation of this object
*/
@Override
public String toString() {
return getRuleInfo().toString();
}
/** Returns a CycL representation of this object.
*
* @return a CycL representation of this object
*/
public String toCycLString() {
return getRuleInfo().toCycLString();
}
}
See more files for this project here