Class Vertex<T>

  • Type Parameters:
    T -

    public class Vertex<T>
    extends java.lang.Object
    A named graph vertex with optional data.
    Version:
    $Revision$
    • Field Detail

      • incomingEdges

        private java.util.List<Edge<T>> incomingEdges
      • outgoingEdges

        private java.util.List<Edge<T>> outgoingEdges
      • name

        private java.lang.String name
      • mark

        private boolean mark
      • markState

        private int markState
      • data

        private T data
    • Constructor Detail

      • Vertex

        public Vertex()
        Calls this(null, null).
      • Vertex

        public Vertex​(java.lang.String n)
        Create a vertex with the given name and no data
        Parameters:
        n -
      • Vertex

        public Vertex​(java.lang.String n,
                      T data)
        Create a Vertex with name n and given data
        Parameters:
        n - - name of vertex
        data - - data associated with vertex
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns:
        the possibly null name of the vertex
      • getData

        public T getData()
        Returns:
        the possibly null data of the vertex
      • setData

        public void setData​(T data)
        Parameters:
        data - The data to set.
      • addEdge

        public boolean addEdge​(Edge<T> e)
        Add an edge to the vertex. If edge.from is this vertex, its an outgoing edge. If edge.to is this vertex, its an incoming edge. If neither from or to is this vertex, the edge is not added.
        Parameters:
        e - - the edge to add
        Returns:
        true if the edge was added, false otherwise
      • addOutgoingEdge

        public void addOutgoingEdge​(Vertex<T> to,
                                    int cost)
        Add an outgoing edge ending at to.
        Parameters:
        to - - the destination vertex
        cost - the edge cost
      • addIncomingEdge

        public void addIncomingEdge​(Vertex<T> from,
                                    int cost)
        Add an incoming edge starting at from
        Parameters:
        from - - the starting vertex
        cost - the edge cost
      • hasEdge

        public boolean hasEdge​(Edge<T> e)
        Check the vertex for either an incoming or outgoing edge mathcing e.
        Parameters:
        e - the edge to check
        Returns:
        true it has an edge
      • remove

        public boolean remove​(Edge<T> e)
        Remove an edge from this vertex
        Parameters:
        e - - the edge to remove
        Returns:
        true if the edge was removed, false if the edge was not connected to this vertex
      • getIncomingEdgeCount

        public int getIncomingEdgeCount()
        Returns:
        the count of incoming edges
      • getIncomingEdge

        public Edge<T> getIncomingEdge​(int i)
        Get the ith incoming edge
        Parameters:
        i - the index into incoming edges
        Returns:
        ith incoming edge
      • getIncomingEdges

        public java.util.List getIncomingEdges()
        Get the incoming edges
        Returns:
        incoming edge list
      • getOutgoingEdgeCount

        public int getOutgoingEdgeCount()
        Returns:
        the count of incoming edges
      • getOutgoingEdge

        public Edge<T> getOutgoingEdge​(int i)
        Get the ith outgoing edge
        Parameters:
        i - the index into outgoing edges
        Returns:
        ith outgoing edge
      • getOutgoingEdges

        public java.util.List getOutgoingEdges()
        Get the outgoing edges
        Returns:
        outgoing edge list
      • findEdge

        public Edge<T> findEdge​(Vertex<T> dest)
        Search the outgoing edges looking for an edge whose's edge.to == dest.
        Parameters:
        dest - the destination
        Returns:
        the outgoing edge going to dest if one exists, null otherwise.
      • findEdge

        public Edge<T> findEdge​(Edge<T> e)
        Search the outgoing edges for a match to e.
        Parameters:
        e - - the edge to check
        Returns:
        e if its a member of the outgoing edges, null otherwise.
      • cost

        public int cost​(Vertex<T> dest)
        What is the cost from this vertext to the dest vertex.
        Parameters:
        dest - - the destination vertex.
        Returns:
        Return Integer.MAX_VALUE if we have no edge to dest, 0 if dest is this vertex, the cost of the outgoing edge otherwise.
      • hasEdge

        public boolean hasEdge​(Vertex<T> dest)
        Is there an outgoing edge ending at dest.
        Parameters:
        dest - - the vertex to check
        Returns:
        true if there is an outgoing edge ending at vertex, false otherwise.
      • visited

        public boolean visited()
        Has this vertex been marked during a visit
        Returns:
        true is visit has been called
      • mark

        public void mark()
        Set the vertex mark flag.
      • setMarkState

        public void setMarkState​(int state)
        Set the mark state to state.
        Parameters:
        state - the state
      • getMarkState

        public int getMarkState()
        Get the mark state value.
        Returns:
        the mark state
      • visit

        public void visit()
        Visit the vertex and set the mark flag to true.
      • clearMark

        public void clearMark()
        Clear the visited mark flag.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string form of the vertex with in and out edges.