SimpleGraphElementFactory.java

  1. // $Id$
  2. /* ====================================================================
  3.  * Copyright (c) 2002-2004, Christophe Labouisse
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  *
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  *
  13.  * 2. Redistributions in binary form must reproduce the above
  14.  *    copyright notice, this list of conditions and the following
  15.  *    disclaimer in the documentation and/or other materials provided
  16.  *    with the distribution.
  17.  *
  18.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21.  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  22.  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  27.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  29.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  30.  */

  31. package net.ggtools.grand.graph;

  32. /**
  33.  * A basic implementation of {@link net.ggtools.grand.graph.GraphElementFactory}
  34.  * creating {@link net.ggtools.grand.graph.NodeImpl} &
  35.  * {@link net.ggtools.grand.graph.LinkImpl}. Instances of this class are linked
  36.  * to a specific graph.
  37.  *
  38.  * @author Christophe Labouisse
  39.  */
  40. class SimpleGraphElementFactory implements GraphElementFactory {

  41.     /**
  42.      * Field graph.
  43.      */
  44.     private final Graph graph;

  45.     /**
  46.      * Creates a factory instance linked to a specific graph.
  47.      * @param graph Graph
  48.      */
  49.     SimpleGraphElementFactory(final Graph graph) {
  50.         this.graph = graph;
  51.     }

  52.     /**
  53.      * Method createNode.
  54.      * @param nodeName String
  55.      * @return Node
  56.      * @see net.ggtools.grand.graph.GraphElementFactory#createNode(java.lang.String)
  57.      */
  58.     public Node createNode(final String nodeName) {
  59.         return new NodeImpl(nodeName, graph);
  60.     }

  61.     /**
  62.      * Method createLink.
  63.      * @param linkName String
  64.      * @param startNode Node
  65.      * @param endNode Node
  66.      * @return Link
  67.      * @see net.ggtools.grand.graph.GraphElementFactory#createLink(java.lang.String,
  68.      *      net.ggtools.grand.graph.Node, net.ggtools.grand.graph.Node)
  69.      */
  70.     public Link createLink(final String linkName, final Node startNode,
  71.             final Node endNode) {
  72.         return new LinkImpl(linkName, graph, startNode, endNode);
  73.     }

  74. }