NonAtomicTermInfo.java from Texai at Krugle
Show NonAtomicTermInfo.java syntax highlighted
/*
* NonAtomicTermInfo.java
*
* Created on October 24, 2006, 1:45 PM
*
* Description: Contains the specialized fields for NonAtomicTerm.
*
* 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 java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import org.texai.kb.Constants;
/**
* Entity class NonAtomicTermInfo
*
* @author reed
*/
@Entity
public class NonAtomicTermInfo implements Serializable {
/**
* 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 id */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long nonAtomicTermInfoId; // NOPMD
/** the non-atomic term */
@OneToOne
private NonAtomicTerm nonAtomicTerm; // NOPMD
/** the term name
* @serial
*/
@Basic
@Column(length=Constants.TERM_NAME_SIZE)
private String termName; // NOPMD
/** the pretty name
* @serial
*/
@Basic
private String prettyName; // NOPMD
/** the globally unique identifier (UUID) string
* @serial
*/
@Basic
private String uuid; // NOPMD
/** the formula
* @serial
*/
@OneToOne(cascade=CascadeType.PERSIST)
private Formula formula; // NOPMD
/** the creator of this non-atomic term */
@ManyToOne(optional=false, cascade=CascadeType.PERSIST, fetch=FetchType.LAZY)
private AbstractReifiedTerm creator;
/** the creation purpose of this non-atomic term */
@ManyToOne(optional=false, cascade=CascadeType.PERSIST, fetch=FetchType.LAZY)
private AbstractReifiedTerm creationPurpose;
/** the creation time point of this non-atomic term */
@ManyToOne(optional=false, cascade=CascadeType.PERSIST, fetch=FetchType.LAZY)
private TimePoint creationTimePoint;
/** Creates a new instance of NonAtomicTermInfo */
public NonAtomicTermInfo() {
super();
}
/**
* Creates a new instance of NonAtomicTermInfo.
*
* @param nonAtomicTerm the non-atomic term
* @param termName the term name
* @param prettyName the pretty name
* @param uuid the uuid string
* @param formula the formula
* @param creator the creator
* @param creationPurpose the creation purpose
* @param creationTimePoint the creation time point
*/
public NonAtomicTermInfo(
final NonAtomicTerm nonAtomicTerm,
final String termName,
final String prettyName,
final String uuid,
final Formula formula,
final AbstractReifiedTerm creator,
final AbstractReifiedTerm creationPurpose,
final TimePoint creationTimePoint) {
super();
//Preconditions
assert creator != null : "creator must not be null";
assert creationPurpose != null : "creationPurpose must not be null";
assert creationTimePoint != null : "creationDate must not be null";
this.nonAtomicTerm = nonAtomicTerm;
if (termName == null) {
this.termName = termNameFromFormula(formula);
} else {
this.termName = termName;
}
this.prettyName = prettyName;
this.uuid = uuid;
this.formula = formula;
this.creator = creator;
this.creationPurpose = creationPurpose;
this.creationTimePoint = creationTimePoint;
}
/** Creates a name for non-atomic term that can also be used as an symbolic identifier when exported.
*
* @param formula the non-atomic term's formula
* @return a name for non-atomic term that can also be used as an symbolic identifier when exported
*/
public static String termNameFromFormula(final Formula formula) {
//Preconditions
assert formula != null : "formula must not be null";
final String formulaString = formula.getFormulaString();
final int formulaStringLength = formulaString.length();
final StringBuilder stringBuilder = new StringBuilder(formulaStringLength);
for (int i = 0; i < formulaStringLength; i++) {
final char formulaCharacter = formulaString.charAt(i);
if (Character.isJavaIdentifierPart(formulaCharacter)) {
stringBuilder.append(formulaCharacter);
} else {
stringBuilder.append('_');
}
}
return stringBuilder.toString();
}
/**
* Gets the id of this NonAtomicTermInfo.
*
* @return the id
*/
public Long getNonAtomicTermId() {
return nonAtomicTermInfoId;
}
/** Returns term name.
*
* @return the term name
*/
public String getTermName() {
return termName;
}
/** Returns the pretty name.
*
* @return the pretty name
*/
public String getPrettyName() {
return prettyName;
}
/** Sets the pretty name.
*
* @param prettyName the pretty name
*/
public void setPrettyName(final String prettyName) {
this.prettyName = prettyName;
}
/** Returns the uuid string.
*
* @return the uuid string
*/
public String getUuid() {
return uuid;
}
/** Returns the formula.
*
* @return the formula
*/
public Formula getFormula() {
return formula;
}
/** Gets the creator.
*
* @return the creator
*/
public AbstractReifiedTerm getCreator() {
return creator;
}
/** Gets the creation purpose.
*
* @return the creation purpose
*/
public AbstractReifiedTerm getCreationPurpose() {
return creationPurpose;
}
/** Gets the creation time point.
*
* @return the creation time point
*/
public TimePoint getCreationTimePoint() {
return creationTimePoint;
}
/**
* Returns a hash code value for the object. This implementation computes
* a hash code value based on the unchanging termName.
* @return a hash code value for this object
*/
@Override
public int hashCode() {
return termName.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 NonAtomicTermInfo)) {
return false;
}
final NonAtomicTermInfo that = (NonAtomicTermInfo) 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 getFormula().toString();
}
/** Returns a CycL representation of this object.
*
* @return a CycL representation of this object
*/
public String toCycLString() {
return getFormula().toCycLString();
}
/** gets the non-atomic term
*
* @return the non-atomic term
*/
public NonAtomicTerm getNonAtomicTerm() {
return nonAtomicTerm;
}
}
See more files for this project here