Skip to content

Commit

Permalink
Merge branch 'release/0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
moaxcp committed Mar 14, 2017
2 parents ec59eac + 0029a0e commit 4defe08
Show file tree
Hide file tree
Showing 20 changed files with 455 additions and 134 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ It is designed to be groovy, using closures and metaprogramming for minimal setu

```groovy
#!/usr/bin/env groovy
@Grab(group='com.github.moaxcp', module='graph-dsl', version='0.5.0')
@Grab(group='com.github.moaxcp', module='graph-dsl', version='0.6.0')
import static graph.Graph.graph
graph {
Expand Down Expand Up @@ -86,6 +86,13 @@ Contributions are welcome. Please submit a pull request to the develop branch in

# Releases

## 0.6.0

* fixed issue with logging when optimizations are turned off
* updating gradle to 3.4.1
* fixed many codenarc issues
* added support for breadth first traversal

## 0.5.1

* Added warning when optimizations are turned off
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jacocoTestReport {
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(':jacocoTestReport') || graph.hasTask(':sonarqube')) {
compileGroovy.groovyOptions.optimizationOptions.all = false
log.warn 'all groovy optimizations are turned off for jacoco'
logger.warn 'all groovy optimizations are turned off for jacoco'
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
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
26 changes: 26 additions & 0 deletions src/main/groovy/graph/BreadthFirstTraversalSpec.groovy
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
}
}
6 changes: 5 additions & 1 deletion src/main/groovy/graph/DefaultVertexFactory.groovy
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)
}
}
32 changes: 15 additions & 17 deletions src/main/groovy/graph/DepthFirstTraversalSpec.groovy
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
}
}
18 changes: 15 additions & 3 deletions src/main/groovy/graph/DirectedEdge.groovy
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
}
}
13 changes: 12 additions & 1 deletion src/main/groovy/graph/DirectedEdgeFactory.groovy
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)
}
}
20 changes: 18 additions & 2 deletions src/main/groovy/graph/DirectedGraphPlugin.groovy
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
package graph

/**
* This plugin makes a Graph behave like a directed graph.
*/
class DirectedGraphPlugin implements Plugin {

def apply(Graph graph) {
/**
* The following modifications are made to the graph:
*
* members
* edges - converted to DirectedEdges
* edgeFactory - changed to a DirectedEdgeFactory
*
* methods
* outEdges - returns out going edges from a given vertex name
* adjacentEdges - now only returns outgoing edges from the given vertex name
* @param graph
* @return
*/
void apply(Graph graph) {
graph.@edges = graph.@edges.collect { edge ->
new DirectedEdge(one: edge.one, two: edge.two)
new DirectedEdge(one:edge.one, two:edge.two)
} as LinkedHashSet

graph.edgeFactory = new DirectedEdgeFactory()
Expand Down
53 changes: 46 additions & 7 deletions src/main/groovy/graph/Edge.groovy
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
}
}
}
9 changes: 9 additions & 0 deletions src/main/groovy/graph/EdgeFactory.groovy
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)
}
2 changes: 1 addition & 1 deletion src/main/groovy/graph/EdgeMapPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package graph

class EdgeMapPlugin implements Plugin {
@Override
def apply(Graph graph) {
void apply(Graph graph) {
graph.@edges.each { edge ->
edge.delegateAs(Mapping)
}
Expand Down
Loading

0 comments on commit 4defe08

Please sign in to comment.