view src/main/java/jungle/core/graph/simple/SimpleVertex.java @ 7:c3c65308a11b

removed some package and added Graph API
author shoshi <shoshi@cr.ie.u-ryukyu.ac.jp>
date Fri, 29 Jun 2012 00:03:12 +0900
parents 07b26b4b21e0
children abed5bd92fcb
line wrap: on
line source

package jungle.core.graph.simple;

import java.util.concurrent.ConcurrentHashMap;

import jungle.core.graph.Graph;
import jungle.core.graph.Vertex;
import jungle.core.graph.Vertexes;

public class SimpleVertex implements Vertex
{
	private String id;
	private final SimpleGraph parent;
	private final ConcurrentHashMap<String,String> properties;
	private final ConcurrentHashMap<String,SimpleVertexes> relations;
	
	public SimpleVertex(SimpleGraph _parent,String _id)
	{
		id = _id;
		parent = _parent;
		properties = new ConcurrentHashMap<String,String>();
		relations = new ConcurrentHashMap<String,SimpleVertexes>();
	}
	
	void setID(String _id)
	{
		id = _id;
	}
	
	@Override
	public String setPropertyIfAbsent(String _key,String _value)
	{
		String previousValue = properties.putIfAbsent(_key,_value);
		return previousValue;
	}
	
	@Override
	public String toString()
	{
		return id;
	}
	
	@Override
	public String getID()
	{
		return id;
	}

	@Override
	public String getProperty(String _key)
	{
		return properties.get(_key);
	}

	@Override
	public void setProperty(String _key, String _value)
	{
		properties.put(_key,_value);
	}

	@Override
	public String removeProperty(String _key)
	{
		return properties.remove(_key);
	}

	@Override
	public Vertexes getVertexes(String _key)
	{
		return relations.get(_key);
	}
	
	@Override
	public Vertexes removeVertexes(String _type)
	{
		SimpleVertexes vertexes = relations.remove(_type);
		return vertexes;
	}

	@Override
	public boolean compareAndSwapProprety(String _key, String _except,String _value)
	{
		return properties.replace(_key,_except,_value);
	}
	
	@Override
	public Graph getGraph()
	{
		return parent;
	}

	@Override
	public Vertexes createVertexes(String _type)
	{
		SimpleVertexes vertexes = new SimpleVertexes(_type,parent);
		SimpleVertexes result = relations.putIfAbsent(_type,vertexes);
		return result == null ? vertexes : null;
	}
}