Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 55EF84D44 for ; Wed, 15 Jun 2011 20:21:21 +0000 (UTC) Received: (qmail 95202 invoked by uid 500); 15 Jun 2011 20:21:21 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 95132 invoked by uid 500); 15 Jun 2011 20:21:21 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 95125 invoked by uid 99); 15 Jun 2011 20:21:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Jun 2011 20:21:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Jun 2011 20:21:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8EF0E2388A3D; Wed, 15 Jun 2011 20:20:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1136173 - in /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model: BaseGraph.java BaseMutableGraph.java Date: Wed, 15 Jun 2011 20:20:59 -0000 To: commits@commons.apache.org From: simonetripodi@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110615202059.8EF0E2388A3D@eris.apache.org> Author: simonetripodi Date: Wed Jun 15 20:20:59 2011 New Revision: 1136173 URL: http://svn.apache.org/viewvc?rev=1136173&view=rev Log: first checkin of BaseMutableGraph (it partially behaves like a directed Graph since populates the adjacency list) checkEdge() method moved in the BaseMutableGraph, not needed in the BaseGraph Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseMutableGraph.java (with props) Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java?rev=1136173&r1=1136172&r2=1136173&view=diff ============================================================================== --- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java (original) +++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java Wed Jun 15 20:20:59 2011 @@ -19,7 +19,6 @@ package org.apache.commons.graph.model; * under the License. */ -import static java.lang.String.format; import static java.util.Collections.unmodifiableSet; import java.util.HashMap; @@ -29,7 +28,6 @@ import java.util.Set; import org.apache.commons.graph.Edge; import org.apache.commons.graph.Graph; -import org.apache.commons.graph.GraphException; import org.apache.commons.graph.Vertex; /** @@ -106,21 +104,4 @@ public abstract class BaseGraph the Graph vertices type + * @param the Graph edges type + */ +public abstract class BaseMutableGraph> + extends BaseGraph + implements MutableGraph +{ + + /** + * {@inheritDoc} + */ + public void addVertex( V v ) + { + if ( v == null ) + { + throw new GraphException( "Impossible to add a null Vertex to the Graph" ); + } + + if ( getAdjacencyList().containsKey( v ) ){ + throw new GraphException( format( "Vertex '%s' already present in the Graph", v ) ); + } + + getAdjacencyList().put( v, new HashSet() ); + + decorateAddVertex( v ); + } + + /** + * + * + * @param v + */ + protected abstract void decorateAddVertex( V v ); + + /** + * {@inheritDoc} + */ + public void removeVertex( V v ) + { + if ( v == null ) + { + throw new GraphException( "Impossible to remove a null Vertex from the Graph" ); + } + + if ( !getAdjacencyList().containsKey( v ) ){ + throw new GraphException( format( "Vertex '%s' not present in the Graph", v ) ); + } + + getAdjacencyList().remove( v ); + + decorateRemoveVertex( v ); + } + + /** + * + * + * @param v + */ + protected abstract void decorateRemoveVertex( V v ); + + /** + * {@inheritDoc} + */ + public void addEdge( E e ) + { + checkEdge( e ); + + getAdjacencyList().get( e.getHead() ).add( e ); + + decorateAddEdge( e ); + } + + /** + * + * + * @param e + */ + protected abstract void decorateAddEdge( E e ); + + /** + * {@inheritDoc} + */ + public void removeEdge( E e ) + { + checkEdge( e ); + + getAdjacencyList().get( e.getHead() ).remove( e ); + + decorateRemoveEdge( e ); + } + + /** + * + * + * @param e + */ + protected abstract void decorateRemoveEdge( E e ); + + /** + * Utility method to check if Vertices in the given Edge are present in the Graph. + * + * @param e the Edge which Vertices have to be checked + */ + private final void checkEdge( E e ) + { + if ( !getAdjacencyList().containsKey( e.getHead() ) ) + { + throw new GraphException( format( "Vertex '%s' not present in the Graph", e.getHead() ) ); + } + if ( !getAdjacencyList().containsKey( e.getTail() ) ) + { + throw new GraphException( format( "Vertex '%s' not present in the Graph", e.getTail() ) ); + } + } + +} Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseMutableGraph.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseMutableGraph.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseMutableGraph.java ------------------------------------------------------------------------------ svn:mime-type = text/plain