Class DefaultEdge

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Edge
    Direct Known Subclasses:
    DirectedEdge, UndirectedEdge

    public class DefaultEdge
    extends java.lang.Object
    implements Edge, java.lang.Cloneable, java.io.Serializable
    A skeletal implementation of the Edge interface, to minimize the effort required to implement the interface.
    Since:
    Jul 14, 2003
    Author:
    Barak Naveh
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultEdge​(java.lang.Object sourceVertex, java.lang.Object targetVertex)
      Constructor for DefaultEdge.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()
      Creates and returns a shallow copy of this edge.
      boolean containsVertex​(java.lang.Object v)
      Returns true if this edge contains the specified vertex.
      java.lang.Object getSource()
      Returns the source vertex of this edge.
      java.lang.Object getTarget()
      Returns the target vertex of this edge.
      double getWeight()
      Returns the weight of this edge.
      java.lang.Object oppositeVertex​(java.lang.Object v)
      Returns the vertex opposite to the specified vertex.
      void setWeight​(double weight)
      Sets the weight of this edge.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultEdge

        public DefaultEdge​(java.lang.Object sourceVertex,
                           java.lang.Object targetVertex)
        Constructor for DefaultEdge.
        Parameters:
        sourceVertex - source vertex of the edge.
        targetVertex - target vertex of the edge.
    • Method Detail

      • getSource

        public java.lang.Object getSource()
        Description copied from interface: Edge
        Returns the source vertex of this edge.
        Specified by:
        getSource in interface Edge
        Returns:
        the source vertex of this edge.
        See Also:
        Edge.getSource()
      • getTarget

        public java.lang.Object getTarget()
        Description copied from interface: Edge
        Returns the target vertex of this edge.
        Specified by:
        getTarget in interface Edge
        Returns:
        the target vertex of this edge.
        See Also:
        Edge.getTarget()
      • setWeight

        public void setWeight​(double weight)
        Description copied from interface: Edge
        Sets the weight of this edge. If this edge is unweighted an UnsupportedOperationException is thrown.
        Specified by:
        setWeight in interface Edge
        Parameters:
        weight - new weight.
        See Also:
        Edge.setWeight(double)
      • getWeight

        public double getWeight()
        Description copied from interface: Edge
        Returns the weight of this edge. If this edge is unweighted the value 1.0 is returned.
        Specified by:
        getWeight in interface Edge
        Returns:
        the weight of this element.
        See Also:
        Edge.getWeight()
      • clone

        public java.lang.Object clone()
        Description copied from interface: Edge
        Creates and returns a shallow copy of this edge. The vertices of this edge are not cloned.
        Specified by:
        clone in interface Edge
        Overrides:
        clone in class java.lang.Object
        Returns:
        a shallow copy of this edge.
        See Also:
        Edge.clone()
      • containsVertex

        public boolean containsVertex​(java.lang.Object v)
        Description copied from interface: Edge
        Returns true if this edge contains the specified vertex. More formally, returns true if and only if the following condition holds:
              this.getSource().equals(v) || this.getTarget().equals(v)
         
        Specified by:
        containsVertex in interface Edge
        Parameters:
        v - vertex whose presence in this edge is to be tested.
        Returns:
        true if this edge contains the specified vertex.
        See Also:
        Edge.containsVertex(java.lang.Object)
      • oppositeVertex

        public java.lang.Object oppositeVertex​(java.lang.Object v)
        Description copied from interface: Edge
        Returns the vertex opposite to the specified vertex.
        Specified by:
        oppositeVertex in interface Edge
        Parameters:
        v - the vertex whose opposite is required.
        Returns:
        the vertex opposite to the specified vertex.
        See Also:
        Edge.oppositeVertex(java.lang.Object)