Skip to content
Snippets Groups Projects
Commit 11b1e382 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman :boom:
Browse files

CHECKPOINT: some more design cleanup including changing most contains() and...

CHECKPOINT: some more design cleanup including changing most contains() and remove() parameters to Objects in the generics, or the most general relevant type
parent 1a37571f
No related branches found
No related tags found
No related merge requests found
...@@ -35,12 +35,11 @@ import java.util.*; ...@@ -35,12 +35,11 @@ import java.util.*;
*/ */
@XmlJavaTypeAdapter( com.syncleus.dann.xml.XmlSerializableAdapter.class ) @XmlJavaTypeAdapter( com.syncleus.dann.xml.XmlSerializableAdapter.class )
public abstract class AbstractAdjacencyGraph< public abstract class AbstractAdjacencyGraph<
PA, N,
N extends PA,
E extends Edge<N,? extends Edge.Endpoint<N>>, E extends Edge<N,? extends Edge.Endpoint<N>>,
NEP extends Graph.NodeEndpoint<N, E>, NEP extends Graph.NodeEndpoint<N, E>,
EEP extends Graph.EdgeEndpoint<N, E> EEP extends Graph.EdgeEndpoint<N, E>
> extends AbstractEdge<PA,Graph.Endpoint<N,E,PA>> implements Graph<PA, N, E, NEP, EEP> > extends AbstractEdge<Object,Graph.Endpoint<?,?,?>> implements Graph<N, E, NEP, EEP>
{ {
private static final Logger LOGGER = Logger.getLogger(AbstractAdjacencyGraph.class); private static final Logger LOGGER = Logger.getLogger(AbstractAdjacencyGraph.class);
// private Set<E> edges; // private Set<E> edges;
...@@ -530,7 +529,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -530,7 +529,7 @@ public abstract class AbstractAdjacencyGraph<
} }
*/ */
protected abstract Set<Graph.EdgeEndpoint<N, E>> getAdjacentEdgeEndPoint(Graph.NodeEndpoint<N, E> nodeEndPoint); protected abstract Set<EdgeEndpoint<N,E>> getAdjacentEdgeEndpoint(Graph.NodeEndpoint<? extends N,? extends E> nodeEndpoint);
protected PathFinder<N,E> getPathFinder() protected PathFinder<N,E> getPathFinder()
{ {
...@@ -556,16 +555,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -556,16 +555,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<Graph.Endpoint<N,E,PA>> getEndpoints() public Set<EEP> getEdgeEndpoints(Edge<? extends N,? extends Edge.Endpoint<? extends N>> edge)
{
final Set<Graph.Endpoint<N,E,PA>> endpoints = new HashSet<Graph.Endpoint<N,E,PA>>();
endpoints.addAll(this.getNodeEndpoints());
endpoints.addAll(this.getEdgeEndpoints());
return Collections.unmodifiableSet(endpoints);
}
@Override
public Set<EEP> getEdgeEndpoints(E edge)
{ {
Set<EEP> matchingEndpoints = new HashSet<EEP>(); Set<EEP> matchingEndpoints = new HashSet<EEP>();
for(final EEP endpoint : this.getEdgeEndpoints() ) for(final EEP endpoint : this.getEdgeEndpoints() )
...@@ -578,7 +568,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -578,7 +568,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<NEP> getNodeEndpoints(N node) public Set<NEP> getNodeEndpoints(Object node)
{ {
Set<NEP> matchingEndpoints = new HashSet<NEP>(); Set<NEP> matchingEndpoints = new HashSet<NEP>();
for(NEP endpoint : this.getNodeEndpoints() ) for(NEP endpoint : this.getNodeEndpoints() )
...@@ -591,20 +581,20 @@ public abstract class AbstractAdjacencyGraph< ...@@ -591,20 +581,20 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<N> getAdjacentNodes(N node) public Set<N> getAdjacentNodes(Object node)
{ {
final Set<N> sourceNodes = new HashSet<N>(); final Set<N> sourceNodes = new HashSet<N>();
for(NEP destinationEndpoint : this.getNodeEndpoints(node) ) for(NEP destinationEndpoint : this.getNodeEndpoints(node) )
for(Graph.EdgeEndpoint<N, E> sourceEndpoint : destinationEndpoint.getAdjacentEdges()) for(Graph.EdgeEndpoint<? extends N, ? extends E> sourceEndpoint : destinationEndpoint.getAdjacentEdges())
for(Graph.NodeEndpoint<N, E> nodeEndpoint : sourceEndpoint.getAdjacentNodes()) for(Graph.NodeEndpoint<? extends N, ? extends E> nodeEndpoint : sourceEndpoint.getAdjacentNodes())
sourceNodes.add(nodeEndpoint.getTarget()); sourceNodes.add(nodeEndpoint.getTarget());
return Collections.unmodifiableSet(sourceNodes); return Collections.unmodifiableSet(sourceNodes);
} }
@Override @Override
public Set<E> getAdjacentEdges(N node) public Set<E> getAdjacentEdges(Object node)
{ {
final Set<E> sourceEdges = new HashSet<E>(); final Set<E> sourceEdges = new HashSet<E>();
...@@ -615,6 +605,15 @@ public abstract class AbstractAdjacencyGraph< ...@@ -615,6 +605,15 @@ public abstract class AbstractAdjacencyGraph<
return Collections.unmodifiableSet(sourceEdges); return Collections.unmodifiableSet(sourceEdges);
} }
@Override
public Set<Graph.Endpoint<?, ?, ?>> getEndpoints()
{
final Set<Graph.Endpoint<?,?,?>> endpoints = new HashSet<Graph.Endpoint<?,?,?>>();
endpoints.addAll(this.getNodeEndpoints());
endpoints.addAll(this.getEdgeEndpoints());
return Collections.unmodifiableSet(endpoints);
}
@Override @Override
public boolean isTraversable(Object source, Object destination) public boolean isTraversable(Object source, Object destination)
{ {
...@@ -657,7 +656,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -657,7 +656,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<E> getTraversableEdgesFrom(N source) public Set<E> getTraversableEdgesFrom(Object source)
{ {
if( !this.getNodes().contains(source) ) if( !this.getNodes().contains(source) )
throw new IllegalArgumentException("source does not belong to this graph"); throw new IllegalArgumentException("source does not belong to this graph");
...@@ -672,7 +671,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -672,7 +671,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<E> getTraversableEdgesFrom(E source) public Set<E> getTraversableEdgesFrom(Edge<? extends N,? extends Edge.Endpoint<? extends N>> source)
{ {
if( !this.getEdges().contains(source) ) if( !this.getEdges().contains(source) )
throw new IllegalArgumentException("source does not belong to this graph"); throw new IllegalArgumentException("source does not belong to this graph");
...@@ -687,7 +686,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -687,7 +686,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<E> getTraversableEdgesTo(N destination) public Set<E> getTraversableEdgesTo(Object destination)
{ {
if( !this.getNodes().contains(destination) ) if( !this.getNodes().contains(destination) )
throw new IllegalArgumentException("source does not belong to this graph"); throw new IllegalArgumentException("source does not belong to this graph");
...@@ -702,7 +701,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -702,7 +701,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<E> getTraversableEdgesTo(E destination) public Set<E> getTraversableEdgesTo(Edge<? extends N,? extends Edge.Endpoint<? extends N>> destination)
{ {
if( !this.getEdges().contains(destination) ) if( !this.getEdges().contains(destination) )
throw new IllegalArgumentException("source does not belong to this graph"); throw new IllegalArgumentException("source does not belong to this graph");
...@@ -717,7 +716,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -717,7 +716,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<N> getTraversableNodesFrom(N source) public Set<N> getTraversableNodesFrom(Object source)
{ {
if( !this.getNodes().contains(source) ) if( !this.getNodes().contains(source) )
throw new IllegalArgumentException("source does not belong to this graph"); throw new IllegalArgumentException("source does not belong to this graph");
...@@ -732,7 +731,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -732,7 +731,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<N> getTraversableNodesFrom(E source) public Set<N> getTraversableNodesFrom(Edge<? extends N,? extends Edge.Endpoint<? extends N>> source)
{ {
if( !this.getEdges().contains(source) ) if( !this.getEdges().contains(source) )
throw new IllegalArgumentException("source does not belong to this graph"); throw new IllegalArgumentException("source does not belong to this graph");
...@@ -747,7 +746,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -747,7 +746,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<N> getTraversableNodesTo(N destination) public Set<N> getTraversableNodesTo(Object destination)
{ {
if( !this.getNodes().contains(destination) ) if( !this.getNodes().contains(destination) )
throw new IllegalArgumentException("source does not belong to this graph"); throw new IllegalArgumentException("source does not belong to this graph");
...@@ -762,7 +761,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -762,7 +761,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<N> getTraversableNodesTo(E destination) public Set<N> getTraversableNodesTo(Edge<? extends N,? extends Edge.Endpoint<? extends N>> destination)
{ {
if( !this.getEdges().contains(destination) ) if( !this.getEdges().contains(destination) )
throw new IllegalArgumentException("source does not belong to this graph"); throw new IllegalArgumentException("source does not belong to this graph");
...@@ -777,7 +776,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -777,7 +776,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<E> getTraversableAdjacentEdgesFrom(N source) public Set<E> getTraversableAdjacentEdgesFrom(Object source)
{ {
final Set<E> destinationEdges = new HashSet<E>(); final Set<E> destinationEdges = new HashSet<E>();
...@@ -789,7 +788,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -789,7 +788,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<E> getTraversableAdjacentEdgesFrom(E source) public Set<E> getTraversableAdjacentEdgesFrom(Edge<? extends N,? extends Edge.Endpoint<? extends N>> source)
{ {
final Set<E> destinationEdges = new HashSet<E>(); final Set<E> destinationEdges = new HashSet<E>();
...@@ -802,7 +801,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -802,7 +801,7 @@ public abstract class AbstractAdjacencyGraph<
@Override @Override
public Set<E> getTraversableAdjacentEdgesTo(N destination) public Set<E> getTraversableAdjacentEdgesTo(Object destination)
{ {
final Set<E> sourceEdges = new HashSet<E>(); final Set<E> sourceEdges = new HashSet<E>();
...@@ -814,7 +813,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -814,7 +813,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<E> getTraversableAdjacentEdgesTo(E destination) public Set<E> getTraversableAdjacentEdgesTo(Edge<? extends N,? extends Edge.Endpoint<? extends N>> destination)
{ {
final Set<E> destinationEdges = new HashSet<E>(); final Set<E> destinationEdges = new HashSet<E>();
...@@ -826,7 +825,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -826,7 +825,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<N> getTraversableAdjacentNodesFrom(N source) public Set<N> getTraversableAdjacentNodesFrom(Object source)
{ {
final Set<N> destinationNodes = new HashSet<N>(); final Set<N> destinationNodes = new HashSet<N>();
...@@ -839,7 +838,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -839,7 +838,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<N> getTraversableAdjacentNodesFrom(E source) public Set<N> getTraversableAdjacentNodesFrom(Edge<? extends N,? extends Edge.Endpoint<? extends N>> source)
{ {
final Set<N> destinationNodes = new HashSet<N>(); final Set<N> destinationNodes = new HashSet<N>();
...@@ -851,7 +850,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -851,7 +850,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<N> getTraversableAdjacentNodesTo(N destination) public Set<N> getTraversableAdjacentNodesTo(Object destination)
{ {
final Set<N> sourceNodes = new HashSet<N>(); final Set<N> sourceNodes = new HashSet<N>();
...@@ -864,7 +863,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -864,7 +863,7 @@ public abstract class AbstractAdjacencyGraph<
} }
@Override @Override
public Set<N> getTraversableAdjacentNodesTo(E destination) public Set<N> getTraversableAdjacentNodesTo(Edge<? extends N,? extends Edge.Endpoint<? extends N>> destination)
{ {
final Set<N> sourceNodes = new HashSet<N>(); final Set<N> sourceNodes = new HashSet<N>();
...@@ -880,9 +879,9 @@ public abstract class AbstractAdjacencyGraph< ...@@ -880,9 +879,9 @@ public abstract class AbstractAdjacencyGraph<
* @return A clone of the current object, with no changes * @return A clone of the current object, with no changes
*/ */
@Override @Override
protected AbstractAdjacencyGraph<PA, N, E, NEP, EEP> clone() protected AbstractAdjacencyGraph<N, E, NEP, EEP> clone()
{ {
return (AbstractAdjacencyGraph<PA, N, E, NEP, EEP>) super.clone(); return (AbstractAdjacencyGraph<N, E, NEP, EEP>) super.clone();
} }
/** /**
...@@ -978,13 +977,13 @@ public abstract class AbstractAdjacencyGraph< ...@@ -978,13 +977,13 @@ public abstract class AbstractAdjacencyGraph<
} }
} }
*/ */
protected abstract class AbstractNodeEndpoint extends AbstractEdge<N,Graph.Endpoint<N,E,PA>>.AbstractEndpoint implements Graph.NodeEndpoint<N,E> protected abstract class AbstractNodeEndpoint extends AbstractEdge<N,Graph.Endpoint<N,E,N>>.AbstractEndpoint implements Graph.NodeEndpoint<N,E>
{ {
@Override @Override
public Set<Graph.EdgeEndpoint<N, E>> getAdjacentEdges() public Set<Graph.EdgeEndpoint<N, E>> getAdjacentEdges()
{ {
return getAdjacentEdgeEndPoint(this); return getAdjacentEdgeEndpoint(this);
} }
@Override @Override
...@@ -1053,7 +1052,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -1053,7 +1052,7 @@ public abstract class AbstractAdjacencyGraph<
} }
}; };
protected abstract class AbstractEdgeEndpoint extends AbstractEdge<E,Graph.Endpoint<N,E,PA>>.AbstractEndpoint implements Graph.EdgeEndpoint<N,E> protected abstract class AbstractEdgeEndpoint extends AbstractEdge<E,Graph.Endpoint<N,E,? extends E>>.AbstractEndpoint implements Graph.EdgeEndpoint<N,E>
{ {
@Override @Override
public Set<Graph.NodeEndpoint<N, E>> getAdjacentNodes() public Set<Graph.NodeEndpoint<N, E>> getAdjacentNodes()
...@@ -1073,7 +1072,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -1073,7 +1072,7 @@ public abstract class AbstractAdjacencyGraph<
for(Endpoint<? extends N> sourceEndpoint : this.getTarget().getEndpoints()) for(Endpoint<? extends N> sourceEndpoint : this.getTarget().getEndpoints())
for( NEP neighborNode : AbstractAdjacencyGraph.this.getNodeEndpoints(sourceEndpoint.getTarget()) ) for( NEP neighborNode : AbstractAdjacencyGraph.this.getNodeEndpoints(sourceEndpoint.getTarget()) )
adjacentEdges.addAll(AbstractAdjacencyGraph.this.getAdjacentEdgeEndPoint(neighborNode)); adjacentEdges.addAll(AbstractAdjacencyGraph.this.getAdjacentEdgeEndpoint(neighborNode));
adjacentEdges.remove(this); adjacentEdges.remove(this);
return Collections.unmodifiableSet(adjacentEdges); return Collections.unmodifiableSet(adjacentEdges);
...@@ -1087,7 +1086,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -1087,7 +1086,7 @@ public abstract class AbstractAdjacencyGraph<
for(Endpoint<? extends N> sourceEndpoint : this.getTarget().getEndpoints()) for(Endpoint<? extends N> sourceEndpoint : this.getTarget().getEndpoints())
if( sourceEndpoint.getTraversableNeighborsFrom().size() > 0 ) if( sourceEndpoint.getTraversableNeighborsFrom().size() > 0 )
for( NEP adjacentNode : AbstractAdjacencyGraph.this.getNodeEndpoints(sourceEndpoint.getTarget())) for( NEP adjacentNode : AbstractAdjacencyGraph.this.getNodeEndpoints(sourceEndpoint.getTarget()))
for( Graph.EdgeEndpoint<N, E> adjacentEdge : AbstractAdjacencyGraph.this.getAdjacentEdgeEndPoint(adjacentNode) ) for( Graph.EdgeEndpoint<N, E> adjacentEdge : AbstractAdjacencyGraph.this.getAdjacentEdgeEndpoint(adjacentNode) )
if( adjacentEdge.getTarget().getTraversableFrom(adjacentNode.getTarget()).size() > 0 ) if( adjacentEdge.getTarget().getTraversableFrom(adjacentNode.getTarget()).size() > 0 )
adjacentEdges.add(adjacentEdge); adjacentEdges.add(adjacentEdge);
...@@ -1102,7 +1101,7 @@ public abstract class AbstractAdjacencyGraph< ...@@ -1102,7 +1101,7 @@ public abstract class AbstractAdjacencyGraph<
for(Endpoint<? extends N> sourceEndpoint : this.getTarget().getEndpoints()) for(Endpoint<? extends N> sourceEndpoint : this.getTarget().getEndpoints())
if( sourceEndpoint.getTraversableNeighborsTo().size() > 0 ) if( sourceEndpoint.getTraversableNeighborsTo().size() > 0 )
for( NEP adjacentNode : AbstractAdjacencyGraph.this.getNodeEndpoints(sourceEndpoint.getTarget())) for( NEP adjacentNode : AbstractAdjacencyGraph.this.getNodeEndpoints(sourceEndpoint.getTarget()))
for( Graph.EdgeEndpoint<N, E> adjacentEdge : AbstractAdjacencyGraph.this.getAdjacentEdgeEndPoint(adjacentNode) ) for( Graph.EdgeEndpoint<N, E> adjacentEdge : AbstractAdjacencyGraph.this.getAdjacentEdgeEndpoint(adjacentNode) )
if( adjacentEdge.getTarget().getTraversableTo(adjacentNode.getTarget()).size() > 0 ) if( adjacentEdge.getTarget().getTraversableTo(adjacentNode.getTarget()).size() > 0 )
adjacentEdges.add(adjacentEdge); adjacentEdges.add(adjacentEdge);
......
...@@ -29,13 +29,13 @@ import org.apache.log4j.Logger; ...@@ -29,13 +29,13 @@ import org.apache.log4j.Logger;
public abstract class AbstractEdge< public abstract class AbstractEdge<
PA, PA,
EP extends Edge.Endpoint<PA> EP extends Edge.Endpoint<? extends PA>
> implements Edge<PA,EP> > implements Edge<PA,EP>
{ {
private static final Logger LOGGER = Logger.getLogger(AbstractEdge.class); private static final Logger LOGGER = Logger.getLogger(AbstractEdge.class);
@Override @Override
public boolean contains(final PA node) public boolean contains(final Object node)
{ {
for( EP endpoint : this.getEndpoints() ) for( EP endpoint : this.getEndpoints() )
if( endpoint.getTarget().equals(node)) if( endpoint.getTarget().equals(node))
...@@ -43,6 +43,24 @@ public abstract class AbstractEdge< ...@@ -43,6 +43,24 @@ public abstract class AbstractEdge<
return false; return false;
} }
@Override
public boolean containsAll(final Collection<?> nodes)
{
for( Object node : nodes )
if( !this.contains(node) )
return false;
return true;
}
@Override
public boolean containsAny(final Collection<?> nodes)
{
for( Object node : nodes )
if( this.contains(node) )
return true;
return false;
}
@Override @Override
public Set<PA> getTargets() public Set<PA> getTargets()
{ {
...@@ -54,7 +72,7 @@ public abstract class AbstractEdge< ...@@ -54,7 +72,7 @@ public abstract class AbstractEdge<
} }
@Override @Override
public Set<EP> getEndpoints(PA node) public Set<EP> getEndpoints(Object node)
{ {
final Set<EP> nodesEndpoints = new HashSet<EP>(); final Set<EP> nodesEndpoints = new HashSet<EP>();
for( EP endpoint : this.getEndpoints() ) for( EP endpoint : this.getEndpoints() )
...@@ -65,33 +83,33 @@ public abstract class AbstractEdge< ...@@ -65,33 +83,33 @@ public abstract class AbstractEdge<
} }
@Override @Override
public Set<PA> getNeighbors(final PA source) public Set<PA> getNeighbors(final Object source)
{ {
final Set<PA> nodes = new HashSet<PA>(); final Set<PA> nodes = new HashSet<PA>();
for( final EP sourceEndpoint : this.getEndpoints(source) ) for( final EP sourceEndpoint : this.getEndpoints(source) )
for( final Edge.Endpoint<PA> fromEndpoint : sourceEndpoint.getNeighbors()) for( final Edge.Endpoint<? extends PA> fromEndpoint : sourceEndpoint.getNeighbors())
nodes.add(fromEndpoint.getTarget()); nodes.add(fromEndpoint.getTarget());
return Collections.unmodifiableSet(nodes); return Collections.unmodifiableSet(nodes);
} }
@Override @Override
public Set<PA> getTraversableFrom(PA source) public Set<PA> getTraversableFrom(Object source)
{ {
final Set<PA> nodes = new HashSet<PA>(); final Set<PA> nodes = new HashSet<PA>();
for( final EP sourceEndpoint : this.getEndpoints(source) ) for( final EP sourceEndpoint : this.getEndpoints(source) )
for( final Edge.Endpoint<PA> fromEndpoint : sourceEndpoint.getTraversableNeighborsFrom()) for( final Edge.Endpoint<? extends PA> fromEndpoint : sourceEndpoint.getTraversableNeighborsFrom())
nodes.add(fromEndpoint.getTarget()); nodes.add(fromEndpoint.getTarget());
return Collections.unmodifiableSet(nodes); return Collections.unmodifiableSet(nodes);
} }
@Override @Override
public Set<PA> getTraversableTo(PA destination) public Set<PA> getTraversableTo(Object destination)
{ {
final Set<PA> nodes = new HashSet<PA>(); final Set<PA> nodes = new HashSet<PA>();
for( final EP destinationEndpoint : this.getEndpoints(destination) ) for( final EP destinationEndpoint : this.getEndpoints(destination) )
for( final Edge.Endpoint<PA> fromEndpoint : destinationEndpoint.getTraversableNeighborsTo()) for( final Edge.Endpoint<? extends PA> fromEndpoint : destinationEndpoint.getTraversableNeighborsTo())
nodes.add(fromEndpoint.getTarget()); nodes.add(fromEndpoint.getTarget());
return Collections.unmodifiableSet(nodes); return Collections.unmodifiableSet(nodes);
...@@ -234,13 +252,13 @@ public abstract class AbstractEdge< ...@@ -234,13 +252,13 @@ public abstract class AbstractEdge<
} }
@Override @Override
public boolean isTraversable(Edge.Endpoint<PA> destination) public boolean isTraversable(Edge.Endpoint<?> destination)
{ {
return AbstractEdge.this.isTraversable(this.getTarget(), destination.getTarget()); return AbstractEdge.this.isTraversable(this.getTarget(), destination.getTarget());
} }
@Override @Override
public boolean isTraversable(PA destination) public boolean isTraversable(Object destination)
{ {
return AbstractEdge.this.isTraversable(this.getTarget(), destination); return AbstractEdge.this.isTraversable(this.getTarget(), destination);
} }
...@@ -359,11 +377,11 @@ public abstract class AbstractEdge< ...@@ -359,11 +377,11 @@ public abstract class AbstractEdge<
@Override @Override
public Edge.Endpoint<PA> next() public Edge.Endpoint<PA> next()
{ {
Edge.Endpoint<PA> nextEndpoint = this.iterator.next(); Edge.Endpoint<? extends PA> nextEndpoint = this.iterator.next();
this.nextLeft--; this.nextLeft--;
if( !AbstractEndpoint.this.equals(nextEndpoint) ) if( !AbstractEndpoint.this.equals(nextEndpoint) )
return nextEndpoint; return (Edge.Endpoint<PA>) nextEndpoint;
return next(); return next();
} }
......
...@@ -19,12 +19,11 @@ ...@@ -19,12 +19,11 @@
package com.syncleus.dann.graph; package com.syncleus.dann.graph;
public interface AssignableGraph< public interface AssignableGraph<
PA, N,
N extends PA,
E extends Edge<N,? extends Edge.Endpoint<N>>, E extends Edge<N,? extends Edge.Endpoint<N>>,
NEP extends AssignableGraph.NodeEndpoint<N, E>, NEP extends AssignableGraph.NodeEndpoint<N, E>,
EEP extends AssignableGraph.EdgeEndpoint<N, E> EEP extends AssignableGraph.EdgeEndpoint<N, E>
> extends Graph<PA,N,E,NEP,EEP>, MutableEdge<PA,Graph.Endpoint<N,E,PA>> > extends Graph<N,E,NEP,EEP>, MutableEdge<Object,Graph.Endpoint<?,?,?>>
//public interface AssignableGraph<P extends Edge<N>, N extends P, E extends P> extends Graph<N,E>, Edge<P>, MutableEdge<P> //public interface AssignableGraph<P extends Edge<N>, N extends P, E extends P> extends Graph<N,E>, Edge<P>, MutableEdge<P>
//public interface AssignableGraph<P extends AssignableGraph.Foo, N extends P, E extends Edge<N> & AssignableGraph.Foo> extends Graph<N,E>, Edge<P>, MutableEdge<P> //public interface AssignableGraph<P extends AssignableGraph.Foo, N extends P, E extends Edge<N> & AssignableGraph.Foo> extends Graph<N,E>, Edge<P>, MutableEdge<P>
{ {
......
...@@ -22,11 +22,12 @@ import com.syncleus.dann.graph.context.ContextReporter; ...@@ -22,11 +22,12 @@ import com.syncleus.dann.graph.context.ContextReporter;
import com.syncleus.dann.graph.xml.EdgeXml; import com.syncleus.dann.graph.xml.EdgeXml;
import com.syncleus.dann.xml.XmlSerializable; import com.syncleus.dann.xml.XmlSerializable;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collection;
import java.util.Set; import java.util.Set;
public interface Edge< public interface Edge<
T, T,
EP extends Edge.Endpoint<T> EP extends Edge.Endpoint<? extends T>
> extends Serializable, Cloneable, XmlSerializable<EdgeXml, Object>, ContextReporter > extends Serializable, Cloneable, XmlSerializable<EdgeXml, Object>, ContextReporter
{ {
interface Endpoint< interface Endpoint<
...@@ -37,18 +38,20 @@ public interface Edge< ...@@ -37,18 +38,20 @@ public interface Edge<
Set<Edge.Endpoint<T>> getTraversableNeighborsTo(); Set<Edge.Endpoint<T>> getTraversableNeighborsTo();
Set<Edge.Endpoint<T>> getTraversableNeighborsFrom(); Set<Edge.Endpoint<T>> getTraversableNeighborsFrom();
boolean isTraversable(); boolean isTraversable();
boolean isTraversable(final Edge.Endpoint<T> destination); boolean isTraversable(Edge.Endpoint<?> destination);
boolean isTraversable(final T destination); boolean isTraversable(Object destination);
T getTarget(); T getTarget();
}; };
Set<EP> getEndpoints(); Set<EP> getEndpoints();
Set<EP> getEndpoints(T node); Set<EP> getEndpoints(Object node);
boolean contains(T node); boolean contains(Object node);
boolean containsAny(Collection<?> nodes);
boolean containsAll(Collection<?> nodes);
Set<T> getTargets(); Set<T> getTargets();
Set<T> getNeighbors(T source); Set<T> getNeighbors(Object source);
Set<T> getTraversableFrom(T source); Set<T> getTraversableFrom(Object source);
Set<T> getTraversableTo(T destination); Set<T> getTraversableTo(Object destination);
boolean isTraversable(T source, T destination); boolean isTraversable(Object source, Object destination);
int getDegree(); int getDegree();
} }
...@@ -36,12 +36,11 @@ import java.util.Set; ...@@ -36,12 +36,11 @@ import java.util.Set;
* @param <E> The type of edge for the given node type * @param <E> The type of edge for the given node type
*/ */
public interface Graph< public interface Graph<
PA, N,
N extends PA,
E extends Edge<N,? extends Edge.Endpoint<N>>, E extends Edge<N,? extends Edge.Endpoint<N>>,
NEP extends Graph.NodeEndpoint<N, E>, NEP extends Graph.NodeEndpoint<N, E>,
EEP extends Graph.EdgeEndpoint<N, E> EEP extends Graph.EdgeEndpoint<N, E>
> extends Edge<PA,Graph.Endpoint<N,E,PA>>, Serializable, Cloneable, ContextReporter > extends Edge<Object,Graph.Endpoint<?,?,?>>, Serializable, Cloneable, ContextReporter
{ {
interface Endpoint< interface Endpoint<
ON, ON,
...@@ -77,10 +76,10 @@ public interface Graph< ...@@ -77,10 +76,10 @@ public interface Graph<
}; };
Set<EEP> getEdgeEndpoints(); Set<EEP> getEdgeEndpoints();
Set<EEP> getEdgeEndpoints(E edge); Set<EEP> getEdgeEndpoints(Edge<? extends N,? extends Edge.Endpoint<? extends N>> edge);
Set<NEP> getNodeEndpoints(); Set<NEP> getNodeEndpoints();
Set<NEP> getNodeEndpoints(N node); Set<NEP> getNodeEndpoints(Object node);
/** /**
* Get a set of all nodes in the graph. * Get a set of all nodes in the graph.
...@@ -110,7 +109,7 @@ public interface Graph< ...@@ -110,7 +109,7 @@ public interface Graph<
* node has no edges. * node has no edges.
* @since 2.0 * @since 2.0
*/ */
Set<N> getAdjacentNodes(N node); Set<N> getAdjacentNodes(Object node);
/** /**
* Get a set of all edges which is connected to node (adjacent). You may not be * Get a set of all edges which is connected to node (adjacent). You may not be
* able to traverse from the specified node to all of these edges returned. If * able to traverse from the specified node to all of these edges returned. If
...@@ -121,25 +120,25 @@ public interface Graph< ...@@ -121,25 +120,25 @@ public interface Graph<
* @throws IllegalArgumentException if specified node is not in the graph. * @throws IllegalArgumentException if specified node is not in the graph.
* @since 2.0 * @since 2.0
*/ */
Set<E> getAdjacentEdges(N node); Set<E> getAdjacentEdges(Object node);
Set<E> getTraversableEdgesFrom(N source); Set<E> getTraversableEdgesFrom(Object source);
Set<E> getTraversableEdgesFrom(E source); Set<E> getTraversableEdgesFrom(Edge<? extends N,? extends Edge.Endpoint<? extends N>> source);
Set<E> getTraversableEdgesTo(N destination); Set<E> getTraversableEdgesTo(Object destination);
Set<E> getTraversableEdgesTo(E destination); Set<E> getTraversableEdgesTo(Edge<? extends N,? extends Edge.Endpoint<? extends N>> destination);
Set<N> getTraversableNodesFrom(N source); Set<N> getTraversableNodesFrom(Object source);
Set<N> getTraversableNodesFrom(E source); Set<N> getTraversableNodesFrom(Edge<? extends N,? extends Edge.Endpoint<? extends N>> source);
Set<N> getTraversableNodesTo(N destination); Set<N> getTraversableNodesTo(Object destination);
Set<N> getTraversableNodesTo(E destination); Set<N> getTraversableNodesTo(Edge<? extends N,? extends Edge.Endpoint<? extends N>> destination);
Set<E> getTraversableAdjacentEdgesFrom(N source); Set<E> getTraversableAdjacentEdgesFrom(Object source);
Set<E> getTraversableAdjacentEdgesFrom(E source); Set<E> getTraversableAdjacentEdgesFrom(Edge<? extends N,? extends Edge.Endpoint<? extends N>> source);
Set<E> getTraversableAdjacentEdgesTo(N destination); Set<E> getTraversableAdjacentEdgesTo(Object destination);
Set<E> getTraversableAdjacentEdgesTo(E destination); Set<E> getTraversableAdjacentEdgesTo(Edge<? extends N,? extends Edge.Endpoint<? extends N>> destination);
Set<N> getTraversableAdjacentNodesFrom(N source); Set<N> getTraversableAdjacentNodesFrom(Object source);
Set<N> getTraversableAdjacentNodesFrom(E source); Set<N> getTraversableAdjacentNodesFrom(Edge<? extends N,? extends Edge.Endpoint<? extends N>> source);
/** /**
* Get a list of all reachable nodes adjacent to node. All edges connected to * Get a list of all reachable nodes adjacent to node. All edges connected to
...@@ -154,7 +153,7 @@ public interface Graph< ...@@ -154,7 +153,7 @@ public interface Graph<
* from the spevified node, empty set if the node has no edges. * from the spevified node, empty set if the node has no edges.
* @since 2.0 * @since 2.0
*/ */
Set<N> getTraversableAdjacentNodesTo(N destination); Set<N> getTraversableAdjacentNodesTo(Object destination);
/** /**
* Get a set of all edges which you can traverse from node. Of course node will * Get a set of all edges which you can traverse from node. Of course node will
...@@ -165,5 +164,5 @@ public interface Graph< ...@@ -165,5 +164,5 @@ public interface Graph<
* @return An unmodifiable set of all edges that can be traversed from node. * @return An unmodifiable set of all edges that can be traversed from node.
* @since 2.0 * @since 2.0
*/ */
Set<N> getTraversableAdjacentNodesTo(E destination); Set<N> getTraversableAdjacentNodesTo(Edge<? extends N,? extends Edge.Endpoint<? extends N>> destination);
} }
...@@ -20,100 +20,15 @@ package com.syncleus.dann.graph; ...@@ -20,100 +20,15 @@ package com.syncleus.dann.graph;
import java.util.*; import java.util.*;
public class MutableAdjacencyGraph< public final class MutableAdjacencyGraph<
PA, N,
N extends PA, E extends Edge<N,? extends Edge.Endpoint<N>>
E extends Edge<N,? extends Edge.Endpoint<N>>, >
NEP extends MutableGraph.NodeEndpoint<N, E>, extends AbstractMutableAdjacencyGraph<Object, N, E, MutableGraph.NodeEndpoint<N, E>, MutableGraph.EdgeEndpoint<N, E>>
EEP extends MutableGraph.EdgeEndpoint<N, E> implements MutableGraph<Object, N, E, MutableGraph.NodeEndpoint<N, E>, MutableGraph.EdgeEndpoint<N, E>>
> extends AbstractAdjacencyGraph<PA, N, E, NEP, EEP> implements MutableGraph<PA, N, E, NEP, EEP>
{ {
private static final long serialVersionUID = -4613327727609060678L; private static final long serialVersionUID = -4613327727609060678L;
@Override
protected Set<EdgeEndpoint<N, E>> getAdjacentEdgeEndPoint(Graph.NodeEndpoint<N, E> nodeEndPoint)
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public NEP joinNode(N node) throws InvalidGraphException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public Map<N, NEP> joinNodes(Set<? extends N> nodes) throws InvalidGraphException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void leaveNode(NEP endPoint) throws InvalidGraphException
{
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void leaveNodes(Set<NEP> endPoint) throws InvalidGraphException
{
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public EEP joinEdge(E edge) throws InvalidGraphException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public Map<N, EEP> joinEdges(Set<? extends E> edges) throws InvalidGraphException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void leaveEdge(EEP endPoint) throws InvalidGraphException
{
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void leaveEdges(Set<EEP> endPoint) throws InvalidGraphException
{
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void clear() throws InvalidGraphException
{
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void clearEdges() throws InvalidGraphException
{
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public Map<PA, ? extends Graph.Endpoint<N, E, PA>> reconfigure(Set<? extends N> addNodes, Set<? extends E> addEdges, Set<? extends Graph.Endpoint<N, E, ? extends PA>> disconnectEndPoints) throws InvalidGraphException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public Set<EEP> getEdgeEndpoints()
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public Set<NEP> getNodeEndpoints()
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override @Override
public boolean isContextEnabled() public boolean isContextEnabled()
{ {
......
...@@ -20,7 +20,7 @@ package com.syncleus.dann.graph; ...@@ -20,7 +20,7 @@ package com.syncleus.dann.graph;
public interface MutableEdge< public interface MutableEdge<
T, T,
EP extends Edge.Endpoint<T> EP extends Edge.Endpoint<? extends T>
> extends Edge<T, EP> > extends Edge<T, EP>
{ {
interface Endpoint<T> extends Edge.Endpoint<T> interface Endpoint<T> extends Edge.Endpoint<T>
......
...@@ -22,12 +22,11 @@ import java.util.Map; ...@@ -22,12 +22,11 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
public interface MutableGraph< public interface MutableGraph<
PA, N,
N extends PA,
E extends Edge<N,? extends Edge.Endpoint<N>>, E extends Edge<N,? extends Edge.Endpoint<N>>,
NEP extends MutableGraph.NodeEndpoint<N, E>, NEP extends MutableGraph.NodeEndpoint<N, E>,
EEP extends MutableGraph.EdgeEndpoint<N, E> EEP extends MutableGraph.EdgeEndpoint<N, E>
> extends AssignableGraph<PA,N,E,NEP,EEP> > extends AssignableGraph<N,E,NEP,EEP>
{ {
interface NodeEndpoint< interface NodeEndpoint<
ON, ON,
...@@ -45,16 +44,18 @@ public interface MutableGraph< ...@@ -45,16 +44,18 @@ public interface MutableGraph<
NEP joinNode(N node) throws InvalidGraphException; NEP joinNode(N node) throws InvalidGraphException;
Map<N, NEP> joinNodes(Set<? extends N> nodes) throws InvalidGraphException; Map<N, NEP> joinNodes(Set<? extends N> nodes) throws InvalidGraphException;
void leaveNode(NEP endPoint) throws InvalidGraphException; Map<N, Set<NEP>> joinNodes(Map<? extends N,? extends Integer> nodes) throws InvalidGraphException;
void leaveNodes(Set<NEP> endPoint) throws InvalidGraphException; Set<EEP> leaveNode(MutableGraph.NodeEndpoint<? extends N, ? extends E> endpoint) throws InvalidGraphException;
Set<EEP> leaveNodes(Set<? extends MutableGraph.NodeEndpoint<? extends N, ? extends E>> endpoint) throws InvalidGraphException;
EEP joinEdge(E edge) throws InvalidGraphException; EEP joinEdge(E edge) throws InvalidGraphException;
Map<N, EEP> joinEdges(Set<? extends E> edges) throws InvalidGraphException; Map<E, EEP> joinEdges(Set<? extends E> edges) throws InvalidGraphException;
void leaveEdge(EEP endPoint) throws InvalidGraphException; Map<E, Set<EEP>> joinEdges(Map<? extends E,? extends Integer> edges) throws InvalidGraphException;
void leaveEdges(Set<EEP> endPoint) throws InvalidGraphException; void leaveEdge(MutableGraph.EdgeEndpoint<? extends N, ? extends E> endpoint) throws InvalidGraphException;
void leaveEdges(Set<? extends MutableGraph.EdgeEndpoint<? extends N, ? extends E>> endpoints) throws InvalidGraphException;
void clear() throws InvalidGraphException; void clear() throws InvalidGraphException;
void clearEdges() throws InvalidGraphException; void clearEdges() throws InvalidGraphException;
Map<PA, ? extends Graph.Endpoint<N,E,PA>> reconfigure(Set<? extends N> addNodes, Set<? extends E> addEdges, final Set<? extends Graph.Endpoint<N,E,? extends PA>> disconnectEndPoints) throws InvalidGraphException; Map<?, Graph.Endpoint<N,E,?>> reconfigure(Set<? extends N> addNodes, Set<? extends E> addEdges, final Set<? extends Graph.Endpoint<?,?,?>> disconnectEndpoints) throws InvalidGraphException;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment