Dependency was moved under the Domain package.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/sandbox/graph2/trunk@144608 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
ff2befe756
commit
b5dbebdc66
5 files changed
-292
No files matched your search
@@ -1,33 +0,0 @@
|
||||
package org.apache.commons.graph.dependency;
|
||||
|
||||
import org.apache.commons.graph.*;
|
||||
|
||||
/**
|
||||
* Description of the Class
|
||||
*/
|
||||
public class Dependency implements Edge
|
||||
{
|
||||
private Object head = null;
|
||||
private Object dep = null;
|
||||
|
||||
/**
|
||||
* Constructor for the Dependency object
|
||||
*
|
||||
* @param head
|
||||
* @param dep
|
||||
*/
|
||||
public Dependency(Object head,
|
||||
Object dep)
|
||||
{
|
||||
this.head = head;
|
||||
this.dep = dep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
public String description()
|
||||
{
|
||||
return head + " depends on " + dep;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package org.apache.commons.graph.dependency;
|
||||
|
||||
import org.apache.commons.graph.*;
|
||||
import org.apache.commons.graph.impl.*;
|
||||
import org.apache.commons.graph.contract.*;
|
||||
import org.apache.commons.graph.exception.*;
|
||||
import org.apache.commons.graph.dependency.exception.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Description of the Class
|
||||
*/
|
||||
public class DependencyGraph
|
||||
extends DirectedGraphWrapper
|
||||
{
|
||||
private GraphFactory factory = new GraphFactory();
|
||||
private AcyclicContract acyclic = new AcyclicContract();
|
||||
private DependencyVisitor visitor = new DependencyVisitor();
|
||||
|
||||
private Map vertices = new HashMap();
|
||||
|
||||
private MutableDirectedGraph DAG = null;
|
||||
|
||||
/**
|
||||
* Constructor for the DependencyGraph object
|
||||
*/
|
||||
public DependencyGraph()
|
||||
{
|
||||
super();
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
Contract[] dagContracts = new Contract[1];
|
||||
dagContracts[0] = acyclic;
|
||||
DAG = factory.makeMutableDirectedGraph(dagContracts,
|
||||
false,
|
||||
null);
|
||||
setDirGraph(DAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a feature to the Dependencies attribute of the DependencyGraph
|
||||
* object
|
||||
*/
|
||||
public void addDependencies(Object head,
|
||||
Collection deps)
|
||||
throws GraphException,
|
||||
CircularDependencyException
|
||||
{
|
||||
DependencyVertex vHead = findVertex(head);
|
||||
|
||||
if (!getVertices().contains(vHead))
|
||||
{
|
||||
DAG.addVertex(vHead);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Iterator v = deps.iterator();
|
||||
|
||||
while (v.hasNext())
|
||||
{
|
||||
DependencyVertex vDep = findVertex(v.next());
|
||||
|
||||
if (!getVertices().contains(vDep))
|
||||
{
|
||||
DAG.addVertex(vDep);
|
||||
}
|
||||
|
||||
DAG.addEdge(new Dependency(vHead.getValue(),
|
||||
vDep.getValue()),
|
||||
vHead, vDep);
|
||||
}
|
||||
}
|
||||
catch (CycleException ex)
|
||||
{
|
||||
throw new CircularDependencyException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
public DependencyVertex findVertex(Object o)
|
||||
{
|
||||
if (vertices.containsKey(o))
|
||||
{
|
||||
return (DependencyVertex) vertices.get(o);
|
||||
}
|
||||
else
|
||||
{
|
||||
DependencyVertex RC = new DependencyVertex(o);
|
||||
vertices.put(o, RC);
|
||||
return RC;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sortedDependencies attribute of the DependencyGraph object
|
||||
*/
|
||||
public List getSortedDependencies(Object head)
|
||||
{
|
||||
return visitor.getSortedDependencies(this, findVertex(head));
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package org.apache.commons.graph.dependency;
|
||||
|
||||
import org.apache.commons.graph.*;
|
||||
|
||||
/**
|
||||
* Description of the Class
|
||||
*/
|
||||
public class DependencyVertex
|
||||
implements Vertex
|
||||
{
|
||||
private Object value;
|
||||
|
||||
/**
|
||||
* Constructor for the DependencyVertex object
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public DependencyVertex(Object value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value attribute of the DependencyVertex object
|
||||
*/
|
||||
public Object getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package org.apache.commons.graph.dependency;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.apache.commons.graph.*;
|
||||
import org.apache.commons.graph.search.*;
|
||||
|
||||
/**
|
||||
* Description of the Class
|
||||
*/
|
||||
public class DependencyVisitor
|
||||
implements Visitor
|
||||
{
|
||||
private List deps = null;
|
||||
private DFS dfs = new DFS();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for the DependencyVisitor object
|
||||
*/
|
||||
public DependencyVisitor() { }
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
public void discoverGraph(Graph g) { }
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
public void discoverVertex(Vertex v) { }
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
public void discoverEdge(Edge e) { }
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
public void finishGraph(Graph g) { }
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
public void finishVertex(Vertex v)
|
||||
{
|
||||
if (v instanceof DependencyVertex)
|
||||
{
|
||||
deps.add(((DependencyVertex) v).getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
deps.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
public void finishEdge(Edge e) { }
|
||||
|
||||
/**
|
||||
* Gets the sortedDependencies attribute of the DependencyVisitor object
|
||||
*/
|
||||
public synchronized List
|
||||
getSortedDependencies(DependencyGraph dg,
|
||||
Vertex root)
|
||||
{
|
||||
deps = new LinkedList();
|
||||
dfs.visit(dg, root, this);
|
||||
return deps;
|
||||
}
|
||||
}
|
||||
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
package org.apache.commons.graph.dependency.exception;
|
||||
|
||||
import org.apache.commons.graph.exception.*;
|
||||
|
||||
/**
|
||||
* Description of the Class
|
||||
*/
|
||||
public class CircularDependencyException
|
||||
extends CycleException
|
||||
{
|
||||
/**
|
||||
* Constructor for the CircularDependencyException object
|
||||
*/
|
||||
public CircularDependencyException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the CircularDependencyException object
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public CircularDependencyException(String msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the CircularDependencyException object
|
||||
*
|
||||
* @param cause
|
||||
*/
|
||||
public CircularDependencyException(Throwable cause)
|
||||
{
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user