PVariable.java from Texai at Krugle
Show PVariable.java syntax highlighted
/*
* PVariable.java
*
* Created on October 16, 2006, 1:46 AM
*
* Description: PVariable is a variable in the Texai logical representation language.
*
* 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 PVariable
*
*
* @author reed
*/
@Entity
@NamedQuery(name=Constants.QUERY_FIND_PVARIABLE_BY_NAME_VALUE,
query="SELECT v FROM PVariable v, PVariableInfo vi WHERE vi.nameValue = :nameValue AND vi.pVariable = v")
public class PVariable 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 persistent variable information */
@OneToOne(fetch=FetchType.LAZY, mappedBy = "pVariable", cascade=CascadeType.ALL)
private PVariableInfo pVariableInfo; // NOPMD
/**
* Creates a new instance of PVariable
*/
public PVariable() {
super();
}
/**
* Creates a new instance of PVariable
*
* @param nameValue the name value
*/
public PVariable(final String nameValue) {
super();
//Preconditions
assert nameValue != null : "nameValue must not be null";
assert nameValue.length() > 1 : "nameValue must be at least two characters long";
assert nameValue.charAt(0) == '?' : "variable must have a question mark as its first character " + nameValue;
pVariableInfo = new PVariableInfo(this, nameValue);
}
/**
* Returns a hash code value for the object.
*
* @return a hash code value for this object.
*/
@Override
public int hashCode() {
return getTermId().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 PVariable)) {
return false;
}
final PVariable that = (PVariable) object;
return this.pVariableInfo.equals(that.pVariableInfo);
}
/** Returns a string representation of this object.
*
* @return a string representation of this object
*/
@Override
public String toString() {
return pVariableInfo.toString();
}
/** Returns a CycL representation of this object.
*
* @return a CycL representation of this object
*/
public String toCycLString() {
return toString();
}
}
See more files for this project here