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 2012/01/20 17:41:37 UTC
svn commit: r1233995 - in /commons/sandbox/graph/trunk/src: changes/
main/java/org/apache/commons/graph/builder/
test/java/org/apache/commons/graph/builder/
Author: simonetripodi
Date: Fri Jan 20 16:41:36 2012
New Revision: 1233995
URL: http://svn.apache.org/viewvc?rev=1233995&view=rev
Log:
[SANDBOX-361] Add fluent APIs to build mutable Graphes
Added:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/AbstractGraphConnection.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultGrapher.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultHeadVertexConnector.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultTailVertexConnector.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnection.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnector.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/HeadVertexConnector.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/TailVertexConnector.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/package-info.java (with props)
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/
commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java (with props)
Modified:
commons/sandbox/graph/trunk/src/changes/changes.xml
Modified: commons/sandbox/graph/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/changes/changes.xml?rev=1233995&r1=1233994&r2=1233995&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/changes/changes.xml (original)
+++ commons/sandbox/graph/trunk/src/changes/changes.xml Fri Jan 20 16:41:36 2012
@@ -23,6 +23,9 @@
</properties>
<body>
<release version="0.1" date="201?-??-??" description="First release.">
+ <action dev="simonetripodi" type="update" issue="SANDBOX-361">
+ Add fluent APIs to build mutable Graphes
+ </action>
<action dev="simonetripodi" type="update" issue="SANDBOX-356" due-to="Claudio Squarcella">
Generic weight types and algorithms implementations based on wighted graphes.
</action>
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/AbstractGraphConnection.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/AbstractGraphConnection.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/AbstractGraphConnection.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/AbstractGraphConnection.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,60 @@
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.commons.graph.utils.Assertions.checkState;
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Vertex;
+
+public abstract class AbstractGraphConnection<V extends Vertex, E extends Edge>
+ implements GraphConnection<V, E>
+{
+
+ private GraphConnector<V, E> connector;
+
+ public final void connect( GraphConnector<V, E> connector )
+ {
+ checkState( this.connector == null, "Re-entry not allowed!" );
+ this.connector = connector;
+
+ try
+ {
+ connect();
+ }
+ finally
+ {
+ this.connector = null;
+ }
+ }
+
+ protected final V addVertex( V vertex )
+ {
+ return connector.addVertex( vertex );
+ }
+
+ protected final HeadVertexConnector<V, E> addEdge( E edge )
+ {
+ return connector.addEdge( edge );
+ }
+
+ public abstract void connect();
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/AbstractGraphConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/AbstractGraphConnection.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/AbstractGraphConnection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultGrapher.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultGrapher.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultGrapher.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultGrapher.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,52 @@
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.commons.graph.utils.Assertions.checkNotNull;
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.MutableGraph;
+import org.apache.commons.graph.Vertex;
+
+final class DefaultGrapher<V extends Vertex, E extends Edge>
+ implements GraphConnector<V, E>
+{
+
+ private final MutableGraph<V, E> graph;
+
+ public DefaultGrapher( MutableGraph<V, E> graph )
+ {
+ this.graph = graph;
+ }
+
+ public V addVertex( V vertex )
+ {
+ vertex = checkNotNull( vertex, "Null vertex not admitted" );
+ graph.addVertex( vertex );
+ return vertex;
+ }
+
+ public HeadVertexConnector<V, E> addEdge( E edge )
+ {
+ edge = checkNotNull( edge, "Null edge not admitted" );
+ return new DefaultHeadVertexConnector<V, E>( graph, edge );
+ }
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultGrapher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultGrapher.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultGrapher.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultHeadVertexConnector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultHeadVertexConnector.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultHeadVertexConnector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultHeadVertexConnector.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,48 @@
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.commons.graph.utils.Assertions.checkNotNull;
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.MutableGraph;
+import org.apache.commons.graph.Vertex;
+
+final class DefaultHeadVertexConnector<V extends Vertex, E extends Edge>
+ implements HeadVertexConnector<V, E>
+{
+
+ private final MutableGraph<V, E> graph;
+
+ private final E edge;
+
+ public DefaultHeadVertexConnector( MutableGraph<V, E> graph, E edge )
+ {
+ this.graph = graph;
+ this.edge = edge;
+ }
+
+ public TailVertexConnector<V, E> from( V head )
+ {
+ head = checkNotNull( head, "Null head vertex not admitted" );
+ return new DefaultTailVertexConnector<V, E>( graph, edge, head );
+ }
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultHeadVertexConnector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultHeadVertexConnector.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultHeadVertexConnector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultTailVertexConnector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultTailVertexConnector.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultTailVertexConnector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultTailVertexConnector.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,51 @@
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.commons.graph.utils.Assertions.checkNotNull;
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.MutableGraph;
+import org.apache.commons.graph.Vertex;
+
+final class DefaultTailVertexConnector<V extends Vertex, E extends Edge>
+ implements TailVertexConnector<V, E>
+{
+
+ private final MutableGraph<V, E> graph;
+
+ private final E edge;
+
+ private final V head;
+
+ public DefaultTailVertexConnector( MutableGraph<V, E> graph, E edge, V head )
+ {
+ this.graph = graph;
+ this.edge = edge;
+ this.head = head;
+ }
+
+ public void to( V tail )
+ {
+ tail = checkNotNull( tail, "Null tail vertex not admitted" );
+ graph.addEdge( head, edge, tail );
+ }
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultTailVertexConnector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultTailVertexConnector.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultTailVertexConnector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,75 @@
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.commons.graph.utils.Assertions.checkNotNull;
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.MutableGraph;
+import org.apache.commons.graph.Vertex;
+import org.apache.commons.graph.WeightedEdge;
+import org.apache.commons.graph.model.DirectedMutableGraph;
+import org.apache.commons.graph.model.DirectedMutableWeightedGraph;
+import org.apache.commons.graph.model.UndirectedMutableGraph;
+import org.apache.commons.graph.model.UndirectedMutableWeightedGraph;
+
+public final class GraphBuilder<V extends Vertex, E extends Edge>
+{
+
+ public static <V extends Vertex, E extends Edge> DirectedMutableGraph<V, E> newDirectedMutableGraph( GraphConnection<V, E> configuration )
+ {
+ return populate( new DirectedMutableGraph<V, E>(), configuration );
+ }
+
+ public static <V extends Vertex, WE extends WeightedEdge<Double>> DirectedMutableWeightedGraph<V, WE> newDirectedMutableWeightedGraph( GraphConnection<V, WE> configuration )
+ {
+ return populate( new DirectedMutableWeightedGraph<V, WE>(), configuration );
+ }
+
+ public static <V extends Vertex, E extends Edge> UndirectedMutableGraph<V, E> newUndirectedMutableGraph( GraphConnection<V, E> configuration )
+ {
+ return populate( new UndirectedMutableGraph<V, E>(), configuration );
+ }
+
+ public static <V extends Vertex, WE extends WeightedEdge<Double>> UndirectedMutableWeightedGraph<V, WE> newUndirectedMutableWeightedGraph( GraphConnection<V, WE> configuration )
+ {
+ return populate( new UndirectedMutableWeightedGraph<V, WE>(), configuration );
+ }
+
+ public static <V extends Vertex, E extends Edge, G extends MutableGraph<V, E>> G populate( G graph, GraphConnection<V, E> configuration )
+ {
+ graph = checkNotNull( graph, "Impossible to configure null graph!" );
+ configuration = checkNotNull( configuration, "Input graph cannot be configured with null configuration" );
+
+ GraphConnector<V, E> grapher = new DefaultGrapher<V, E>( graph );
+ configuration.connect( grapher );
+
+ return graph;
+ }
+
+ /**
+ * hidden constructor, this class cannot be instantiated directly.
+ */
+ private GraphBuilder()
+ {
+ // do nothing
+ }
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnection.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnection.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnection.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnection.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,30 @@
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Vertex;
+
+public interface GraphConnection<V extends Vertex, E extends Edge>
+{
+
+ void connect( GraphConnector<V, E> grapher );
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnection.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnector.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnector.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,32 @@
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Vertex;
+
+public interface GraphConnector<V extends Vertex, E extends Edge>
+{
+
+ V addVertex( V vertex );
+
+ HeadVertexConnector<V, E> addEdge( E edge );
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnector.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphConnector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/HeadVertexConnector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/HeadVertexConnector.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/HeadVertexConnector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/HeadVertexConnector.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,30 @@
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Vertex;
+
+public interface HeadVertexConnector<V extends Vertex, E extends Edge>
+{
+
+ TailVertexConnector<V, E> from( V head );
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/HeadVertexConnector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/HeadVertexConnector.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/HeadVertexConnector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/TailVertexConnector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/TailVertexConnector.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/TailVertexConnector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/TailVertexConnector.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,30 @@
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Vertex;
+
+public interface TailVertexConnector<V extends Vertex, E extends Edge>
+{
+
+ void to( V tail );
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/TailVertexConnector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/TailVertexConnector.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/TailVertexConnector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/package-info.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/package-info.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/package-info.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/package-info.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,23 @@
+/**
+ * EDSL to build Graph instances using fluent APIs.
+ */
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/package-info.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/package-info.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java?rev=1233995&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java (added)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java Fri Jan 20 16:41:36 2012
@@ -0,0 +1,100 @@
+package org.apache.commons.graph.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.commons.graph.builder.GraphBuilder.newUndirectedMutableWeightedGraph;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.commons.graph.model.BaseLabeledVertex;
+import org.apache.commons.graph.model.BaseLabeledWeightedEdge;
+import org.apache.commons.graph.model.UndirectedMutableWeightedGraph;
+import org.junit.Test;
+
+public final class GraphBuilderTestCase
+{
+
+ @Test
+ public void verifyProducedGraphesAreEquals()
+ {
+ UndirectedMutableWeightedGraph<BaseLabeledVertex, BaseLabeledWeightedEdge> expected =
+ new UndirectedMutableWeightedGraph<BaseLabeledVertex, BaseLabeledWeightedEdge>();
+
+ // building Graph with traditional APIs...
+
+ BaseLabeledVertex start = new BaseLabeledVertex( "start" );
+ BaseLabeledVertex a = new BaseLabeledVertex( "a" );
+ BaseLabeledVertex b = new BaseLabeledVertex( "b" );
+ BaseLabeledVertex c = new BaseLabeledVertex( "c" );
+ BaseLabeledVertex d = new BaseLabeledVertex( "d" );
+ BaseLabeledVertex e = new BaseLabeledVertex( "e" );
+ BaseLabeledVertex goal = new BaseLabeledVertex( "goal" );
+
+ expected.addVertex( start );
+ expected.addVertex( a );
+ expected.addVertex( b );
+ expected.addVertex( c );
+ expected.addVertex( d );
+ expected.addVertex( e );
+ expected.addVertex( goal );
+
+ expected.addEdge( start, new BaseLabeledWeightedEdge( "start <-> a", 1.5D ), a );
+ expected.addEdge( start, new BaseLabeledWeightedEdge( "start <-> d", 2D ), d );
+
+ expected.addEdge( a, new BaseLabeledWeightedEdge( "a <-> b", 2D ), b );
+ expected.addEdge( b, new BaseLabeledWeightedEdge( "b <-> c", 3D ), c );
+ expected.addEdge( c, new BaseLabeledWeightedEdge( "c <-> goal", 3D ), goal );
+
+ expected.addEdge( d, new BaseLabeledWeightedEdge( "d <-> e", 3D ), e );
+ expected.addEdge( e, new BaseLabeledWeightedEdge( "e <-> goal", 2D ), goal );
+
+ // ... and using the EDSL :)
+
+ UndirectedMutableWeightedGraph<BaseLabeledVertex, BaseLabeledWeightedEdge> actual =
+ newUndirectedMutableWeightedGraph( new AbstractGraphConnection<BaseLabeledVertex, BaseLabeledWeightedEdge>()
+ {
+
+ public void connect()
+ {
+ BaseLabeledVertex start = addVertex( new BaseLabeledVertex( "start" ) );
+ BaseLabeledVertex a = addVertex( new BaseLabeledVertex( "a" ) );
+ BaseLabeledVertex b = addVertex( new BaseLabeledVertex( "b" ) );
+ BaseLabeledVertex c = addVertex( new BaseLabeledVertex( "c" ) );
+ BaseLabeledVertex d = addVertex( new BaseLabeledVertex( "d" ) );
+ BaseLabeledVertex e = addVertex( new BaseLabeledVertex( "e" ) );
+ BaseLabeledVertex goal = addVertex( new BaseLabeledVertex( "goal" ) );
+
+ addEdge( new BaseLabeledWeightedEdge( "start <-> a", 1.5D ) ).from( start ).to( a );
+ addEdge( new BaseLabeledWeightedEdge( "start <-> d", 2D ) ).from( start ).to( d );
+
+ addEdge( new BaseLabeledWeightedEdge( "a <-> b", 2D ) ).from( a ).to( b );
+ addEdge( new BaseLabeledWeightedEdge( "b <-> c", 3D ) ).from( b ).to( c );
+ addEdge( new BaseLabeledWeightedEdge( "c <-> goal", 3D ) ).from( c ).to( goal );
+
+ addEdge( new BaseLabeledWeightedEdge( "d <-> e", 3D ) ).from( d ).to( e );
+ addEdge( new BaseLabeledWeightedEdge( "e <-> goal", 2D ) ).from( e ).to( goal );
+ }
+
+ } );
+
+ assertEquals( expected, actual );
+ }
+
+}
Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain