view src/treecms/tree/id/AbstractNodeID.java @ 21:f3150b37f9be

commit
author shoshi
date Mon, 06 Jun 2011 21:49:04 +0900
parents 12604eb6b615
children
line wrap: on
line source

package treecms.tree.id;

import treecms.api.NodeID;

public abstract class AbstractNodeID implements NodeID
{
	public abstract NodeID create();
	public abstract NodeID update();
	public abstract String getFamilyID();
	public abstract String getVersion();
	
	public abstract boolean isFamily(NodeID _id);
	
	@Override
	public String toString()
	{
		return (new StringBuffer(getFamilyID())).append('@').append(getVersion()).toString();
	}
	
	private int m_hashCode = -1;
	
	@Override
	public int hashCode()
	{
		if(m_hashCode == -1){
			int hash = 17;
			hash = 37*hash + getFamilyID().hashCode();
			hash = 37*hash + getVersion().hashCode();
			m_hashCode = hash;
		}
		
		return m_hashCode;
	}
	
	@Override
	public boolean equals(Object _id)
	{
		if(_id instanceof NodeID){
			NodeID target = (NodeID)_id;
			if(isFamily(target) && getVersion().equals(target.getVersion())){
				return true;
			}
		}
		return false;
	}
}