Author: simonetripodi
Date: Sat Jan 21 12:22:16 2012
New Revision: 1234310
URL: http://svn.apache.org/viewvc?rev=1234310&view=rev
Log:
made builder methods more fluent
Added:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java
(with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/LinkedConnectionBuilder.java
(with props)
Modified:
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/DefaultLinkedConnectionBuilder.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java?rev=1234310&view=auto
==============================================================================
---
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java
(added)
+++
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java
Sat Jan 21 12:22:16 2012
@@ -0,0 +1,49 @@
+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 DefaultLinkedConnectionBuilder<V extends Vertex, E extends Edge, G
extends MutableGraph<V, E>>
+ implements LinkedConnectionBuilder<V, E, G>
+{
+
+ private final G graph;
+
+ public DefaultLinkedConnectionBuilder( G graph )
+ {
+ this.graph = graph;
+ }
+
+ public G withConnections( GraphConnection<V, E> graphConnection )
+ {
+ graphConnection = checkNotNull( graphConnection, "Input graph cannot
be configured with null connections" );
+
+ GraphConnector<V, E> grapher = new DefaultGrapher<V, E>( graph );
+ graphConnection.connect( grapher );
+
+ return graph;
+ }
+
+}
Propchange:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
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=1234310&r1=1234309&r2=1234310&view=diff
==============================================================================
---
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java
(original)
+++
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java
Sat Jan 21 12:22:16 2012
@@ -33,35 +33,29 @@ import org.apache.commons.graph.model.Un
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 )
+ public static <V extends Vertex, E extends Edge> DirectedMutableGraph<V,
E> newDirectedMutableGraph( GraphConnection<V, E> graphConnection )
{
- return populate( new DirectedMutableGraph<V, E>(), configuration );
+ return populate( new DirectedMutableGraph<V, E>() ).withConnections(
graphConnection );
}
- public static <V extends Vertex, WE extends WeightedEdge<Double>>
DirectedMutableWeightedGraph<V, WE> newDirectedMutableWeightedGraph(
GraphConnection<V, WE> configuration )
+ public static <V extends Vertex, WE extends WeightedEdge<Double>>
DirectedMutableWeightedGraph<V, WE> newDirectedMutableWeightedGraph(
GraphConnection<V, WE> graphConnection )
{
- return populate( new DirectedMutableWeightedGraph<V, WE>(),
configuration );
+ return populate( new DirectedMutableWeightedGraph<V, WE>()
).withConnections( graphConnection );
}
- public static <V extends Vertex, E extends Edge> UndirectedMutableGraph<V,
E> newUndirectedMutableGraph( GraphConnection<V, E> configuration )
+ public static <V extends Vertex, E extends Edge> UndirectedMutableGraph<V,
E> newUndirectedMutableGraph( GraphConnection<V, E> graphConnection )
{
- return populate( new UndirectedMutableGraph<V, E>(), configuration );
+ return populate( new UndirectedMutableGraph<V, E>() ).withConnections(
graphConnection );
}
- public static <V extends Vertex, WE extends WeightedEdge<Double>>
UndirectedMutableWeightedGraph<V, WE> newUndirectedMutableWeightedGraph(
GraphConnection<V, WE> configuration )
+ public static <V extends Vertex, WE extends WeightedEdge<Double>>
UndirectedMutableWeightedGraph<V, WE> newUndirectedMutableWeightedGraph(
GraphConnection<V, WE> graphConnection )
{
- return populate( new UndirectedMutableWeightedGraph<V, WE>(),
configuration );
+ return populate( new UndirectedMutableWeightedGraph<V, WE>()
).withConnections( graphConnection );
}
- public static <V extends Vertex, E extends Edge, G extends MutableGraph<V,
E>> G populate( G graph, GraphConnection<V, E> configuration )
+ public static <V extends Vertex, E extends Edge, G extends MutableGraph<V,
E>> LinkedConnectionBuilder<V, E, G> populate( G graph )
{
- 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;
+ return new DefaultLinkedConnectionBuilder<V, E, G>( checkNotNull(
graph, "Impossible to configure null graph!" ) );
}
/**
Added:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/LinkedConnectionBuilder.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/LinkedConnectionBuilder.java?rev=1234310&view=auto
==============================================================================
---
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/LinkedConnectionBuilder.java
(added)
+++
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/LinkedConnectionBuilder.java
Sat Jan 21 12:22:16 2012
@@ -0,0 +1,31 @@
+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.MutableGraph;
+import org.apache.commons.graph.Vertex;
+
+public interface LinkedConnectionBuilder<V extends Vertex, E extends Edge, G
extends MutableGraph<V, E>>
+{
+
+ G withConnections( GraphConnection<V, E> graphConnection );
+
+}
Propchange:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/LinkedConnectionBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/LinkedConnectionBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/LinkedConnectionBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain