view src/main/java/jungle/impl/SimpleTreeGroup.java @ 1:b1fa4c494416

added tests , etc..
author shoshi <shoshi@cr.ie.u-ryukyu.ac.jp>
date Mon, 11 Jun 2012 23:45:38 +0900
parents 113050de7f69
children 761d04aecfcb
line wrap: on
line source

package jungle.impl;

import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

import jungle.core.Editor;
import jungle.core.Tree;
import jungle.core.TreeGroup;

public class SimpleTreeGroup implements TreeGroup
{
	private String id;
	private AtomicReference<Tree> latestTree;
	private AtomicLong revisionCounter;
	
	public SimpleTreeGroup(String _id)
	{
		latestTree = new AtomicReference<Tree>();
		id = _id;
		revisionCounter = new AtomicLong();
	}

	public String getID()
	{
		return id;
	}

	public Tree latestTree()
	{
		return latestTree.get();
	}
	
	public String newTreeID()
	{
		return Long.toHexString(revisionCounter.incrementAndGet());
	}
	
	public Editor newEditor(Tree _t)
	{
		TreeGroup tg = _t.getGroup();
		
		if(tg != this){
			return null;
		}
		
		SimpleEditor editor = new SimpleEditor(this,_t);
		return editor;
	}
}