All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.biopax.paxtools.query.model.AbstractGraph Maven / Gradle / Ivy

Go to download

BioPAX graph-theoretic querying - for finding paths between molecules, or identifying molecules that are reachable through specific paths, using the BioPAX pathway data model.

There is a newer version: 6.0.0
Show newest version
package org.biopax.paxtools.query.model;

import java.util.HashMap;
import java.util.Map;

/**
 * Adapter class for a graph that is queried.
 *
 * @author Ozgun Babur
 */
public abstract class AbstractGraph implements Graph
{
	/**
	 * Objects are stored in this map. getKey method of objects is used for generating the key.
	 */
	protected Map objectMap;

	/**
	 * Empty constructor that initializes the object map.
	 */
	protected AbstractGraph()
	{
		this.objectMap = new HashMap();
	}

	/**
	 * Gets the related wrapper for the given object, creates the wrapper if not created before.
	 * @param obj Object to wrap
	 * @return wrapper
	 */
	public GraphObject getGraphObject(Object obj)
	{
		String key = getKey(obj);
		GraphObject go = objectMap.get(key);

//		if (obj instanceof Conversion && go == null)
//		{
//			go = objectMap.get(key + ConversionWrapper.LEFT_TO_RIGHT);
//			if (go == null)
//				go = objectMap.get(key + ConversionWrapper.RIGHT_TO_LEFT);
//		}

		if (go == null)
		{
			Node node = wrap(obj);

			if (node != null)
			{
				objectMap.put(key, node);
				node.init();
			}
		}

		return objectMap.get(key);
	}

	/**
	 * Gets the wrapper object with its id (key).
	 * @param id Whatever getKey method return for the wrapped object.
	 * @return Wrapper
	 */
	public GraphObject getGraphObject(String id)
	{
		return objectMap.get(id);
	}

	/**
	 * @return The object map
	 */
	public Map getObjectMap()
	{
		return objectMap;
	}

	/**
	 * Clears memory of all wrapper in the object map.
	 */
	public void clear()
	{
		for (GraphObject go : objectMap.values())
		{
			go.clear();
		}
	}

	/**
	 * @param wrapped Object to wrap
	 * @return A key for the object to map it to its wrapper
	 */
	public abstract String getKey(Object wrapped);

	/**
	 * Creates the wrapper for the given object.
	 * @param obj Object to wrap
	 * @return The wrapper
	 */
	public abstract Node wrap(Object obj);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy