PStringInfo.java from Texai at Krugle
Show PStringInfo.java syntax highlighted
/*
* PStringInfo.java
*
* Created on October 24, 2006, 1:44 PM
*
* Description: Contains the specialized fields for PString.
*
* 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.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import org.texai.kb.Constants;
/**
* Entity class PStringInfo
*
* @author reed
*/
@Entity
public class PStringInfo 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 pStringInfoId; // NOPMD
/** the persistent string */
@OneToOne
private PString pString; // NOPMD
/** the string value */
@Column(length=Constants.STRING_VALUE_SIZE)
@Basic
private String stringValue; // NOPMD
/** Creates a new instance of PStringInfo */
public PStringInfo() {
super();
}
/** Creates a new instance of PStringInfo.
*
* @param pString the persistent string
* @param stringValue the string value
*/
public PStringInfo(final PString pString, final String stringValue) {
super();
//Preconditions
assert pString != null : "pString must not be null";
assert stringValue != null : "stringValue must not be null";
this.pString = pString;
this.stringValue = stringValue;
}
/**
* Gets the pStringInfoId of this PStringInfo.
*
* @return the pStringInfoId
*/
public Long getId() {
return this.pStringInfoId;
}
/** gets the persistent string
*
* @return the persistent string
*/
public PString getPString() {
return pString;
}
/** Gets the string value
*
* @return the string value
*/
public String getStringValue() {
return stringValue;
}
/**
* Returns a hash code value for the object. This implementation computes
* a hash code value based on the unchanging stringValue.
* @return a hash code value for this object
*/
@Override
public int hashCode() {
return stringValue.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 PStringInfo)) {
return false;
}
final PStringInfo that = (PStringInfo) object;
return this.stringValue.equals(that.stringValue);
}
/** Returns a string representation of this object.
*
* @return a string representation of this object
*/
@Override
public String toString() {
return "\"" + stringValue + "\"";
}
/** 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