Mercurial > hg > Members > shoshi > TreeCMS > TreeCMSPrototype1
changeset 42:ba136d01f304
added DecrementalNodeID,SimpleDecNodeID
author | shoshi |
---|---|
date | Fri, 21 Jan 2011 03:03:54 +0900 |
parents | 1214cf906f1e |
children | 7392f7ed45d2 |
files | src/treecms/proto/id/DecrementalNodeID.java src/treecms/proto/simple/SimpleDecNodeID.java src/treecms/proto/simple/test/SimpleDecNodeIDTest.java |
diffstat | 3 files changed, 133 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/id/DecrementalNodeID.java Fri Jan 21 03:03:54 2011 +0900 @@ -0,0 +1,47 @@ +package treecms.proto.id; + +import treecms.proto.api.NodeID; + +public abstract class DecrementalNodeID implements NodeID +{ + @Override + public abstract NodeID create(); + + @Override + public abstract NodeID getTip(); + + @Override + public abstract NodeID update(); + + @Override + public abstract String getUUID(); + + @Override + public abstract String getVersion(); + + @Override + public boolean isFamily(NodeID id) + { + return id.getUUID().equals(getUUID()); + } + + @Override + public boolean isOrderThen(NodeID _id) + { + if(Long.parseLong(_id.getVersion()) >= Long.parseLong(getVersion())){ + return true; + } + return false; + } + + @Override + public boolean equals(NodeID _id) + { + if(isFamily(_id)){ + if(Long.parseLong(getVersion()) == Long.parseLong(_id.getVersion())){ + return true; + } + } + return false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/simple/SimpleDecNodeID.java Fri Jan 21 03:03:54 2011 +0900 @@ -0,0 +1,67 @@ +package treecms.proto.simple; + +import java.util.UUID; +import java.util.concurrent.atomic.AtomicLong; + +import treecms.proto.api.NodeID; +import treecms.proto.id.DecrementalNodeID; + +public class SimpleDecNodeID extends DecrementalNodeID +{ + private String m_uuid; + private AtomicLong m_tip; + private long m_version; + + public SimpleDecNodeID() + { + m_uuid = UUID.randomUUID().toString(); + m_tip = new AtomicLong(); + m_tip.set(10000); + + m_version = m_tip.getAndDecrement(); + } + + private SimpleDecNodeID(String _uuid,AtomicLong _tip,boolean _doUpdate) + { + m_uuid = _uuid; + m_tip = _tip; + + if(_doUpdate){ + m_version = m_tip.getAndDecrement(); + return; + } + + m_version = m_tip.get(); + } + + @Override + public NodeID create() + { + return new SimpleDecNodeID(); + } + + @Override + public NodeID getTip() + { + return new SimpleDecNodeID(m_uuid,m_tip,false); + } + + @Override + public String getUUID() + { + return m_uuid; + } + + @Override + public String getVersion() + { + return Long.toString(m_version); + } + + @Override + public NodeID update() + { + return new SimpleDecNodeID(m_uuid,m_tip,false); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/simple/test/SimpleDecNodeIDTest.java Fri Jan 21 03:03:54 2011 +0900 @@ -0,0 +1,19 @@ +package treecms.proto.simple.test; + +import org.junit.runner.JUnitCore; + +import treecms.proto.simple.SimpleDecNodeID; +import treecms.proto.test.NodeIDTest; + +public class SimpleDecNodeIDTest extends NodeIDTest +{ + public static void main(String _args[]) + { + JUnitCore.main(SimpleDecNodeIDTest.class.getName()); + } + + public SimpleDecNodeIDTest() + { + super(new SimpleDecNodeID()); + } +}