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 5AB5D60D1 for ; Tue, 14 Jun 2011 23:10:50 +0000 (UTC) Received: (qmail 40274 invoked by uid 500); 14 Jun 2011 23:10:50 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 40219 invoked by uid 500); 14 Jun 2011 23:10:50 -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 40212 invoked by uid 99); 14 Jun 2011 23:10:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Jun 2011 23:10:50 +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; Tue, 14 Jun 2011 23:10:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BE6332388A64; Tue, 14 Jun 2011 23:10:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1135840 - /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/InMemoryPath.java Date: Tue, 14 Jun 2011 23:10:25 -0000 To: commits@commons.apache.org From: simonetripodi@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110614231025.BE6332388A64@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: simonetripodi Date: Tue Jun 14 23:10:25 2011 New Revision: 1135840 URL: http://svn.apache.org/viewvc?rev=1135840&view=rev Log: first checkin of InMemoryPath class, an in-memory representation of WeightedPath Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/InMemoryPath.java (with props) Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/InMemoryPath.java URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/InMemoryPath.java?rev=1135840&view=auto ============================================================================== --- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/InMemoryPath.java (added) +++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/InMemoryPath.java Tue Jun 14 23:10:25 2011 @@ -0,0 +1,127 @@ +package org.apache.commons.graph.shortestpath; + +/* + * 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 java.util.Collections.unmodifiableList; + +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.graph.Vertex; +import org.apache.commons.graph.WeightedEdge; +import org.apache.commons.graph.WeightedPath; + +/** + * Support {@link WeightedPath} implementation, optimized for algorithms (such Dijkstra's) that need to rebuild the path + * traversing the predecessor list bottom-up. + * + * @param the Graph vertices type + * @param the Graph weighted edges type + */ +final class InMemoryPath> + implements WeightedPath +{ + + private final V source; + + private final V target; + + private final Double weigth; + + private final LinkedList vertices = new LinkedList(); + + private final LinkedList edges = new LinkedList(); + + public InMemoryPath( V start, V end, Double weigth ) + { + this.source = start; + this.target = end; + this.weigth = weigth; + } + + /** + * {@inheritDoc} + */ + public V getSource() + { + return source; + } + + /** + * {@inheritDoc} + */ + public V getTarget() + { + return target; + } + + public void addVertexInHead( V vertex ) + { + vertices.addFirst( vertex ); + } + + public void addVertexInTail( V vertex ) + { + vertices.addLast( vertex ); + } + + /** + * {@inheritDoc} + */ + public List getVertices() + { + return unmodifiableList( vertices ); + } + + public void addEdgeInHead( WE edge ) + { + edges.addFirst( edge ); + } + + public void addEdgeInTail( WE edge ) + { + edges.addLast( edge ); + } + + /** + * {@inheritDoc} + */ + public List getEdges() + { + return unmodifiableList( edges ); + } + + /** + * {@inheritDoc} + */ + public int size() + { + return vertices.size(); + } + + /** + * {@inheritDoc} + */ + public Double getWeight() + { + return weigth; + } + +} Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/InMemoryPath.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/InMemoryPath.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/InMemoryPath.java ------------------------------------------------------------------------------ svn:mime-type = text/plain