-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
455 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Sat Feb 04 14:13:34 EST 2017 | ||
#Sat Mar 11 14:54:25 EST 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package graph | ||
|
||
/** | ||
* Specification for a BreadFirstTraversal. Contains actions that are called | ||
* when an event happens during the traversal. | ||
*/ | ||
class BreadthFirstTraversalSpec extends TraversalSpec { | ||
private Closure visitClosure | ||
|
||
/** | ||
* Returns the visit closure | ||
* @return | ||
*/ | ||
Closure getVisit() { | ||
visitClosure | ||
} | ||
|
||
/** | ||
* sets the visit closure | ||
* @param visitClosure | ||
* @return | ||
*/ | ||
void visit(Closure visitClosure) { | ||
this.visitClosure = visitClosure | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package graph | ||
|
||
/** | ||
* Factory for creating vertices. This factory returns instances of the | ||
* base class Vertex. | ||
*/ | ||
class DefaultVertexFactory implements VertexFactory { | ||
@Override | ||
Vertex newVertex(String name) { | ||
return new Vertex(name: name) | ||
new Vertex(name:name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,44 @@ | ||
package graph | ||
|
||
/** | ||
* Specification for a DepthFirstSearch. Contains actions that are called when and | ||
* even happens during the search. | ||
* Specification for a DepthFirstTraversal. Contains actions that are called when an | ||
* event happens during the traversal. | ||
*/ | ||
class DepthFirstTraversalSpec { | ||
String root | ||
Map colors | ||
private Closure preorder | ||
private Closure postorder | ||
class DepthFirstTraversalSpec extends TraversalSpec { | ||
private Closure preorderClosure | ||
private Closure postorderClosure | ||
|
||
/** | ||
* returns the preorder event. | ||
* @return | ||
*/ | ||
def getPreorder() { | ||
return preorder | ||
Closure getPreorder() { | ||
preorderClosure | ||
} | ||
|
||
/** | ||
* returns the postorder event. | ||
* @return | ||
*/ | ||
def getPostorder() { | ||
return postorder | ||
Closure getPostorder() { | ||
postorderClosure | ||
} | ||
|
||
/** | ||
* method to set the preorder event | ||
* @param preorder | ||
* @param preorderClosure | ||
* @return | ||
*/ | ||
def preorder(Closure preorder) { | ||
this.preorder = preorder | ||
void preorder(Closure preorderClosure) { | ||
this.preorderClosure = preorderClosure | ||
} | ||
|
||
/** | ||
* method to set the postorder event | ||
* @param postorder | ||
* @param postorderClosure | ||
* @return | ||
*/ | ||
def postorder(Closure postorder) { | ||
this.postorder = postorder | ||
void postorder(Closure postorderClosure) { | ||
this.postorderClosure = postorderClosure | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
package graph | ||
|
||
/** | ||
* Represents a directed edge in a grpah. Since these should be soted in a | ||
* Set the equals method is overridden to allow edges in both directions between | ||
* two vertices. | ||
*/ | ||
@SuppressWarnings('EqualsAndHashCode') //equals still meets contract with hashCode (I think) | ||
class DirectedEdge extends Edge { | ||
|
||
public boolean equals(Object o) { | ||
/** | ||
* overridden to allow edges in both directions between two vertices. | ||
* @param o | ||
* @return true if two edges are equal. | ||
*/ | ||
@SuppressWarnings('Instanceof') | ||
boolean equals(Object o) { | ||
if (!(o instanceof DirectedEdge)) { | ||
return false | ||
} | ||
if (this.is(o)) { | ||
return true | ||
} | ||
DirectedEdge rhs = (DirectedEdge) o; | ||
return one == rhs.one && two == rhs.two | ||
DirectedEdge rhs = (DirectedEdge) o | ||
one == rhs.one && two == rhs.two | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
package graph | ||
|
||
/** | ||
* Factory for creating edges. This class returns instances of | ||
* Directed Edge. | ||
*/ | ||
class DirectedEdgeFactory implements EdgeFactory { | ||
|
||
/** | ||
* Returns a new DirectedEdge with the given parameters. | ||
* @param one | ||
* @param two | ||
* @return a new DirectedEdge | ||
*/ | ||
@Override | ||
Edge newEdge(String one, String two) { | ||
return new DirectedEdge(one: one, two: two) | ||
new DirectedEdge(one:one, two:two) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,80 @@ | ||
package graph | ||
|
||
/** | ||
* An edge between two vertices. This class uses a delegate when methods | ||
* and properties are missing. Traits should be applied to the delegate | ||
* using delegateAs(). | ||
*/ | ||
@SuppressWarnings('NoDef') | ||
class Edge { | ||
String one | ||
String two | ||
def delegate = new Object() | ||
|
||
def delegateAs(Class<?>... traits) { | ||
/** | ||
* applies traits to the delegate. | ||
* @param traits | ||
* @return | ||
*/ | ||
Edge delegateAs(Class<?>... traits) { | ||
delegate = delegate.withTraits(traits) | ||
this | ||
} | ||
|
||
/** | ||
* two edges are equal when they connect to the same vertices | ||
* regardless of ordering of one and two. | ||
* @param o | ||
* @return | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
@SuppressWarnings('Instanceof') | ||
boolean equals(Object o) { | ||
if (!(o instanceof Edge)) { | ||
return false | ||
} | ||
if (this.is(o)) { | ||
return true | ||
} | ||
Edge rhs = (Edge) o; | ||
return (one == rhs.one || one == rhs.two) && (two == rhs.two || two == rhs.one) | ||
Edge rhs = (Edge) o | ||
(one == rhs.one || one == rhs.two) && (two == rhs.two || two == rhs.one) | ||
} | ||
|
||
/** | ||
* returns one.hashCode() + two.hashCode() | ||
* @return | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
int hashCode() { | ||
one.hashCode() + two.hashCode() | ||
} | ||
|
||
def methodMissing(String name, def args) { | ||
/** | ||
* calls method on delegate. | ||
* @param name | ||
* @param args | ||
* @return | ||
*/ | ||
def methodMissing(String name, args) { | ||
delegate.invokeMethod(name, args) | ||
} | ||
|
||
/** | ||
* returns property from delegate. | ||
* @param name | ||
* @return | ||
*/ | ||
def propertyMissing(String name) { | ||
delegate[name] | ||
} | ||
|
||
/** | ||
* sets property on delegate. | ||
* @param name | ||
* @param value | ||
* @return | ||
*/ | ||
def propertyMissing(String name, value) { | ||
delegate[name] = value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
package graph | ||
|
||
/** | ||
* Used to create edges. | ||
*/ | ||
interface EdgeFactory { | ||
/** | ||
* returns a new Edge | ||
* @param one | ||
* @param two | ||
* @return | ||
*/ | ||
Edge newEdge(String one, String two) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.