You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/06/12 00:21:25 UTC
svn commit: r1134798 -
/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/domain/basic/DirectedGraphImpl.java
Author: simonetripodi
Date: Sat Jun 11 22:21:25 2011
New Revision: 1134798
URL: http://svn.apache.org/viewvc?rev=1134798&view=rev
Log:
minor code format
Modified:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/domain/basic/DirectedGraphImpl.java
Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/domain/basic/DirectedGraphImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/domain/basic/DirectedGraphImpl.java?rev=1134798&r1=1134797&r2=1134798&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/domain/basic/DirectedGraphImpl.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/domain/basic/DirectedGraphImpl.java Sat Jun 11 22:21:25 2011
@@ -45,21 +45,22 @@ import org.apache.commons.graph.contract
* Description of the Class
*/
public class DirectedGraphImpl<V extends Vertex, WE extends WeightedEdge>
- implements DirectedGraph<V, WE>,
- WeightedGraph<V, WE>,
- MutableDirectedGraph<V, WE>,
- InvocationHandler
+ implements DirectedGraph<V, WE>, WeightedGraph<V, WE>, MutableDirectedGraph<V, WE>, InvocationHandler
{
private Vertex root = null;
private Set<V> vertices = new HashSet<V>();
+
private Set<WE> edges = new HashSet<WE>();
+
private List<Contract> contracts = new ArrayList<Contract>();
private Map<V, Set<WE>> inbound = new HashMap<V, Set<WE>>();// VERTEX X SET( EDGE )
+
private Map<V, Set<WE>> outbound = new HashMap<V, Set<WE>>();// - " " -
private Map<WE, V> edgeSource = new HashMap<WE, V>();// EDGE X VERTEX
+
private Map<WE, V> edgeTarget = new HashMap<WE, V>();// EDGE X TARGET
private Map<WE, Number> edgeWeights = new HashMap<WE, Number>();// EDGE X WEIGHT
@@ -67,35 +68,36 @@ public class DirectedGraphImpl<V extends
/**
* Constructor for the DirectedGraphImpl object
*/
- public DirectedGraphImpl() { }
+ public DirectedGraphImpl()
+ {
+ }
/**
* Constructor for the DirectedGraphImpl object
- *
+ *
* @param dg
*/
- public DirectedGraphImpl(DirectedGraph<V, WE> dg)
+ public DirectedGraphImpl( DirectedGraph<V, WE> dg )
{
Iterator<V> v = dg.getVertices().iterator();
- while (v.hasNext())
+ while ( v.hasNext() )
{
- addVertexI(v.next());
+ addVertexI( v.next() );
}
Iterator<WE> e = dg.getEdges().iterator();
- while (e.hasNext())
+ while ( e.hasNext() )
{
WE edge = e.next();
- addEdgeI(edge,
- dg.getSource(edge),
- dg.getTarget(edge));
+ addEdgeI( edge, dg.getSource( edge ), dg.getTarget( edge ) );
- if (dg instanceof WeightedGraph)
+ if ( dg instanceof WeightedGraph )
{
- @SuppressWarnings( "unchecked" ) // it is a DirectedGraph<V, WE>
+ @SuppressWarnings( "unchecked" )
+ // it is a DirectedGraph<V, WE>
WeightedGraph<V, WE> weightedGraph = (WeightedGraph<V, WE>) dg;
- setWeight(edge, weightedGraph.getWeight(edge));
+ setWeight( edge, weightedGraph.getWeight( edge ) );
}
}
}
@@ -103,32 +105,32 @@ public class DirectedGraphImpl<V extends
/**
* Adds a feature to the Contract attribute of the DirectedGraphImpl object
*/
- public void addContract(Contract c)
+ public void addContract( Contract c )
throws GraphException
{
- c.setImpl(this);
+ c.setImpl( this );
c.verify();
- contracts.add(c);
+ contracts.add( c );
}
/**
* Description of the Method
*/
- public void removeContract(Contract c)
+ public void removeContract( Contract c )
{
- contracts.remove(c);
+ contracts.remove( c );
}
/**
* Sets the weight attribute of the DirectedGraphImpl object
*/
- public void setWeight(WE e, Number value)
+ public void setWeight( WE e, Number value )
{
- if (edgeWeights.containsKey(e))
+ if ( edgeWeights.containsKey( e ) )
{
- edgeWeights.remove(e);
+ edgeWeights.remove( e );
}
- edgeWeights.put(e, value);
+ edgeWeights.put( e, value );
}
// Interface Methods
@@ -138,23 +140,23 @@ public class DirectedGraphImpl<V extends
*/
public Set<V> getVertices()
{
- return unmodifiableSet(vertices);
+ return unmodifiableSet( vertices );
}
/**
* Gets the vertices attribute of the DirectedGraphImpl object
*/
- public Set<V> getVertices(WE e)
+ public Set<V> getVertices( WE e )
{
Set<V> RC = new HashSet<V>();
- if (edgeSource.containsKey(e))
+ if ( edgeSource.containsKey( e ) )
{
- RC.add(edgeSource.get(e));
+ RC.add( edgeSource.get( e ) );
}
- if (edgeTarget.containsKey(e))
+ if ( edgeTarget.containsKey( e ) )
{
- RC.add(edgeTarget.get(e));
+ RC.add( edgeTarget.get( e ) );
}
return RC;
@@ -165,23 +167,23 @@ public class DirectedGraphImpl<V extends
*/
public Set<WE> getEdges()
{
- return unmodifiableSet(edges);
+ return unmodifiableSet( edges );
}
/**
* Gets the edges attribute of the DirectedGraphImpl object
*/
- public Set<WE> getEdges(V v)
+ public Set<WE> getEdges( V v )
{
Set<WE> RC = new HashSet<WE>();
- if (inbound.containsKey(v))
+ if ( inbound.containsKey( v ) )
{
- RC.addAll(inbound.get(v));
+ RC.addAll( inbound.get( v ) );
}
- if (outbound.containsKey(v))
+ if ( outbound.containsKey( v ) )
{
- RC.addAll(outbound.get(v));
+ RC.addAll( outbound.get( v ) );
}
return RC;
@@ -191,27 +193,27 @@ public class DirectedGraphImpl<V extends
/**
* Gets the source attribute of the DirectedGraphImpl object
*/
- public V getSource(WE e)
+ public V getSource( WE e )
{
- return edgeSource.get(e);
+ return edgeSource.get( e );
}
/**
* Gets the target attribute of the DirectedGraphImpl object
*/
- public V getTarget(WE e)
+ public V getTarget( WE e )
{
- return edgeTarget.get(e);
+ return edgeTarget.get( e );
}
/**
* Gets the inbound attribute of the DirectedGraphImpl object
*/
- public Set<WE> getInbound(Vertex v)
+ public Set<WE> getInbound( Vertex v )
{
- if (inbound.containsKey(v))
+ if ( inbound.containsKey( v ) )
{
- return unmodifiableSet(inbound.get(v));
+ return unmodifiableSet( inbound.get( v ) );
}
return new HashSet<WE>();
}
@@ -219,186 +221,182 @@ public class DirectedGraphImpl<V extends
/**
* Gets the outbound attribute of the DirectedGraphImpl object
*/
- public Set<WE> getOutbound(Vertex v)
+ public Set<WE> getOutbound( Vertex v )
{
- if (outbound.containsKey(v))
+ if ( outbound.containsKey( v ) )
{
- return unmodifiableSet(outbound.get(v));
+ return unmodifiableSet( outbound.get( v ) );
}
return new HashSet<WE>();
}
-
// MutableDirectedGraph
/**
* Adds a feature to the VertexI attribute of the DirectedGraphImpl object
*/
- private void addVertexI(V v)
+ private void addVertexI( V v )
throws GraphException
{
- if (root == null) root = v;
+ if ( root == null )
+ root = v;
- vertices.add(v);
+ vertices.add( v );
}
/**
* Adds a feature to the Vertex attribute of the DirectedGraphImpl object
*/
- public void addVertex(V v)
+ public void addVertex( V v )
throws GraphException
{
Iterator<Contract> conts = contracts.iterator();
- while (conts.hasNext())
+ while ( conts.hasNext() )
{
- conts.next().addVertex(v);
+ conts.next().addVertex( v );
}
- addVertexI(v);
+ addVertexI( v );
}
/**
* Description of the Method
*/
- private void removeVertexI(Vertex v)
+ private void removeVertexI( Vertex v )
throws GraphException
{
try
{
- vertices.remove(v);
+ vertices.remove( v );
}
- catch (Exception ex)
+ catch ( Exception ex )
{
- throw new GraphException(ex);
+ throw new GraphException( ex );
}
}
/**
* Description of the Method
*/
- public void removeVertex(Vertex v)
+ public void removeVertex( Vertex v )
throws GraphException
{
Iterator<Contract> conts = contracts.iterator();
- while (conts.hasNext())
+ while ( conts.hasNext() )
{
- conts.next().removeVertex(v);
+ conts.next().removeVertex( v );
}
- removeVertexI(v);
+ removeVertexI( v );
}
-
/**
* Adds a feature to the EdgeI attribute of the DirectedGraphImpl object
*/
- private void addEdgeI(WE e, V start, V end)
+ private void addEdgeI( WE e, V start, V end )
throws GraphException
{
- edges.add(e);
+ edges.add( e );
- edgeWeights.put(e, e.getWeight());
+ edgeWeights.put( e, e.getWeight() );
- edgeSource.put(e, start);
- edgeTarget.put(e, end);
+ edgeSource.put( e, start );
+ edgeTarget.put( e, end );
- if (!outbound.containsKey(start))
+ if ( !outbound.containsKey( start ) )
{
Set<WE> edgeSet = new HashSet<WE>();
- edgeSet.add(e);
+ edgeSet.add( e );
- outbound.put(start, edgeSet);
+ outbound.put( start, edgeSet );
}
else
{
- outbound.get(start).add(e);
+ outbound.get( start ).add( e );
}
- if (!inbound.containsKey(end))
+ if ( !inbound.containsKey( end ) )
{
Set<WE> edgeSet = new HashSet<WE>();
- edgeSet.add(e);
+ edgeSet.add( e );
- inbound.put(end, edgeSet);
+ inbound.put( end, edgeSet );
}
else
{
- inbound.get(end).add(e);
+ inbound.get( end ).add( e );
}
}
/**
* Adds a feature to the Edge attribute of the DirectedGraphImpl object
*/
- public void addEdge(WE e,
- V start,
- V end)
+ public void addEdge( WE e, V start, V end )
throws GraphException
{
- Iterator<Contract> conts = contracts.iterator();
- while (conts.hasNext())
- {
- Contract cont = conts.next();
-
- cont.addEdge(e, start, end);
- }
-
- addEdgeI(e, start, end);
- }
+ Iterator<Contract> conts = contracts.iterator();
+ while ( conts.hasNext() )
+ {
+ Contract cont = conts.next();
+ cont.addEdge( e, start, end );
+ }
+
+ addEdgeI( e, start, end );
+ }
/**
* Description of the Method
*/
- private void removeEdgeI(Edge e)
+ private void removeEdgeI( Edge e )
throws GraphException
{
try
{
Set<WE> edgeSet = null;
- V source = edgeSource.get(e);
- edgeSource.remove(e);
- edgeSet = outbound.get(source);
- edgeSet.remove(e);
-
- V target = edgeTarget.get(e);
- edgeTarget.remove(e);
- edgeSet = inbound.get(target);
- edgeSet.remove(e);
+ V source = edgeSource.get( e );
+ edgeSource.remove( e );
+ edgeSet = outbound.get( source );
+ edgeSet.remove( e );
+
+ V target = edgeTarget.get( e );
+ edgeTarget.remove( e );
+ edgeSet = inbound.get( target );
+ edgeSet.remove( e );
- if (edgeWeights.containsKey(e))
+ if ( edgeWeights.containsKey( e ) )
{
- edgeWeights.remove(e);
+ edgeWeights.remove( e );
}
}
- catch (Exception ex)
+ catch ( Exception ex )
{
- throw new GraphException(ex);
+ throw new GraphException( ex );
}
}
/**
* Description of the Method
*/
- public void removeEdge(WE e)
+ public void removeEdge( WE e )
throws GraphException
{
Iterator<Contract> conts = contracts.iterator();
- while (conts.hasNext())
+ while ( conts.hasNext() )
{
- conts.next().removeEdge(e);
+ conts.next().removeEdge( e );
}
- removeEdgeI(e);
+ removeEdgeI( e );
}
// WeightedGraph
/**
* Gets the weight attribute of the DirectedGraphImpl object
*/
- public Number getWeight(WE e)
+ public Number getWeight( WE e )
{
- if (edgeWeights.containsKey(e))
+ if ( edgeWeights.containsKey( e ) )
{
- return edgeWeights.get(e);
+ return edgeWeights.get( e );
}
return 1.0;
}
@@ -406,16 +404,17 @@ public class DirectedGraphImpl<V extends
/**
* Description of the Method
*/
- public Object invoke(Object proxy,
- Method method,
- Object args[])
+ public Object invoke( Object proxy, Method method, Object args[] )
throws Throwable
{
- try {
- return method.invoke(this, args);
- } catch (InvocationTargetException ex) {
- throw ex.getTargetException();
- }
+ try
+ {
+ return method.invoke( this, args );
+ }
+ catch ( InvocationTargetException ex )
+ {
+ throw ex.getTargetException();
+ }
}
}