📄 abstractobject.java
字号:
* Get the id of current object,object id starts at 0.
*
* @return The object id.
*
*/
public int getObjectId(){
return m_objectId;
}
/**
* Get a max object id of current object,object id starts at 0.
* This action is same as getObjectId when the object is an indifidual object,
* but is different as getObjectId when the object is just a group object.
*
* @return The object id.
*
*/
public int getMaxObjectId(){
return m_objectId;
}
/**
* Set the id of current object,object id starts at 0.
*
* @param objectId The object id.
*
*/
public void setObjectId(int objectId){
m_objectId =objectId;
}
/**
* Set value by a new object.
*
* @param object A new object
*
*/
public void setValue(AbstractObject obj){
if (obj==null)
return;
m_objectType =obj.m_objectType;
m_objectId =obj.m_objectId;
m_intId =obj.m_intId;
m_strId =obj.m_strId;
m_name =obj.m_name;
m_desc =obj.m_desc;
}
/**
* Convert this AbstractObject to String
*
* @return An string represents the content of the AbstractObject
*
*/
public String toString(){
StringBuffer buf=new StringBuffer();
buf.append("objectId=");
buf.append(m_objectId);
buf.append(";objectType=");
buf.append(m_objectType);
buf.append(";intId=");
buf.append(m_intId);
buf.append(";strId=");
buf.append(m_strId);
buf.append(";name=");
buf.append(m_name);
buf.append(";desc=");
buf.append(m_desc);
return buf.toString();
}
/**
* Creates a new AbstractObject of the same class and with the same contents as this object.
* This method should be implemented by sub classes.
*
* @return A clone of this class.
*
*/
abstract protected AbstractObject cloneMe() throws CloneNotSupportedException;
/**
* Creates a new AbstractObject of the same class and with the same contents as this object.
*
* @return A clone of this instance.
*
*/
public Object clone() throws CloneNotSupportedException{
AbstractObject obj = cloneMe();
obj.setValue(this);
return obj;
}
/**
* Returns the hashcode for this AbstractObject.
*
* @return hash code for this AbstractObject.
*
*/
public int hashCode(){
return m_objectId ^ m_objectType ^
m_intId ^ m_strId.hashCode() ^ m_name.hashCode() ^ m_desc.hashCode();
}
/**
* Determines whether or not two objects are equal.
*
* @param obj an object to be compared with this object
*
* @return true if the object to be compared is an instance of Shape and has the same values; false otherwise.
*
*/
public boolean equals(Object obj){
if (obj == this)
return true;
if (!(obj instanceof AbstractObject))
return false;
AbstractObject absObj = (AbstractObject) obj;
return (absObj.m_objectId==m_objectId) &&
(absObj.m_objectType==m_objectType) &&
(absObj.m_intId==m_intId) &&
(absObj.m_strId.equals(m_strId)) &&
(absObj.m_name.equals(m_name)) &&
(absObj.m_desc.equals(m_desc))
;
}
/**
* Convert this Object to a sub element of a specified element <br>
*
* @param version A file version notification so this object can obey the rules to save data.
*
* @param element A jdom.element used to add sub content.
*
*/
public void toDOM(Element element,JFVersion version){
if (element==null)
return;
Element root =new Element(getXMLTag());
appendChildToDOM(root,version);
element.addChild(root);
}
/**
* Append necessary xml child for current element,
* this method will be called internally by toDOM.
*
* @param version A file version notification so this object can obey the rules to save data.
*
* @param element A XML element to append child xml nodes
*
*/
protected void appendChildToDOM(Element element,JFVersion version) {
if (element==null)
return;
element.addChild(new Element(XML_OBJECTTYPE, m_objectType));
element.addChild(new Element(XML_OBJECTID, m_objectId));
element.addChild(new Element(XML_INTID, m_intId));
element.addChild(new Element(XML_STRID, m_strId));
element.addChild(new Element(XML_NAME, m_name));
element.addChild(new Element(XML_DESC, m_desc));
}
/**
* Extract an Object from a xml element <br>
*
* @param version A file version notification so this object can obey the rules to fetch data.
*
* @param element A jdom element used to restore content of a BaseObject
*
*/
public void fromDOM(Element element,JFVersion version){
if (element==null)
return;
if (element.getTag().equals(getXMLTag())){
extractChildFromDOM(element,version);
}
}
/**
* Extract needed xml child from current element,
* this method will be called internally by fromDOM.
*
* @param version A file version notification so this object can obey the rules to fetch data.
*
* @param element An element used to extract needed xml child
*
*/
protected void extractChildFromDOM(Element element,JFVersion version){
if (element==null)
return;
m_objectType =Element.getIntValue(element.getChild(XML_OBJECTTYPE));
m_objectId =Element.getIntValue(element.getChild(XML_OBJECTID));
if (!version.lowerVersionOf(JFVersion.VERSIONID_180)){
m_intId =Element.getIntValue(element.getChild(XML_INTID));
m_strId =Element.getStringValue(element.getChild(XML_STRID));
m_name =Element.getStringValue(element.getChild(XML_NAME));
m_desc =Element.getStringValue(element.getChild(XML_DESC));
}
}
/**
* Save this AbstractObject to a binary stream <br>
*
* @param stream An binary output stream
*
* @param version A file version notification so this object can obey the rules to save data.
*
* @exception java.io.IOException
*
*/
public void saveToStream(com.jfimagine.utils.io.JFWriter stream,JFVersion version) throws IOException{
stream.writeInt(m_objectType);
stream.writeInt(m_objectId);
stream.writeInt(m_intId);
stream.writeUTF(m_strId);
stream.writeUTF(m_name);
stream.writeUTF(m_desc);
}
/**
* Load AbstractObject data from a binary stream <br>
*
* @param stream An binary input stream
*
* @param skipHead Skip head 'TYPE' check, an shape object should always
* has its own shape-type stored, if this shape-type has already been readed,
* this loadFromStream should/could not read the type anymore.
*
* @param version A file version notification so this object can obey the rules to fetch data.
*
* @exception java.io.IOException
*
*/
public void loadFromStream(com.jfimagine.utils.io.JFReader stream,boolean skipHead,JFVersion version) throws IOException{
if (!skipHead){
int objectType =stream.readInt();
if (objectType!=getObjectType()){
String msg ="loadFromStream: Invalid object format in stream!";
m_logger.error(msg);
throw new IOException(msg);
}
}
m_objectId =stream.readInt();
if (version!=null && !version.lowerVersionOf(JFVersion.VERSIONID_180)){
m_intId =stream.readInt();
m_strId =stream.readUTF();
m_name =stream.readUTF();
m_desc =stream.readUTF();
}
}
/**
* Free the Resource of current object used.<br>
*
* This is not trying to free the memory that current object used.
* It's only used to release some memory that the GC can not work with.
*
*/
public void freeResources(){
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -