Class Walk

All Implemented Interfaces:
Serializable, Cloneable, Iterable<Node>, Collection<Node>, List<Node>, RandomAccess, NodeSequence
Direct Known Subclasses:
Cycle, Path

public class Walk extends ArrayList<Node> implements NodeSequence
Represents a walk in a graph. A walk W is defined as an ordered set of nodes that two adjacenct nodes in the set share an edge. More precisley:

G = {N,E} W = { n(i) in N | (n(i-1),n(i)) in E }
Author:
Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
See Also:
  • Constructor Details

  • Method Details

    • isValid

      public boolean isValid()
      A valid walk is one in which each pair of adjacent nodes in the sequence share an edge. Note,
      Specified by:
      isValid in interface NodeSequence
      Returns:
      True if valid, otherwise false.
    • getEdges

      public List<Edge> getEdges()
      Calculates the edges in the walk. If the edges of the walk cannot be calculated (due to an invalid walk), null is returned, otherwise the list of edges is returned.
      Returns:
      The edges of the walk, otherwise null if the edges cannot be calculated.
    • add

      public boolean add(Node node)
      Adds a node to the walk. Adding a node clears the edge list which will be recalculated on the next call to getEdges().
      Specified by:
      add in interface Collection<Node>
      Specified by:
      add in interface List<Node>
      Overrides:
      add in class ArrayList<Node>
      Parameters:
      node - Node to add to the walk.
    • add

      public void add(int index, Node element)
      Specified by:
      add in interface List<Node>
      Overrides:
      add in class ArrayList<Node>
    • addAll

      public boolean addAll(Collection<? extends Node> c)
      Specified by:
      addAll in interface Collection<Node>
      Specified by:
      addAll in interface List<Node>
      Overrides:
      addAll in class ArrayList<Node>
    • addAll

      public boolean addAll(int index, Collection<? extends Node> c)
      Specified by:
      addAll in interface List<Node>
      Overrides:
      addAll in class ArrayList<Node>
    • addEdge

      public boolean addEdge(Edge e)
    • addEdges

      public void addEdges(Collection<Edge> edges)
    • remove

      public void remove(Node node)
      Removes a node from the walk. Removing a node clears the edge list which will be recalculated on the next call to getEdges().
      Parameters:
      node - Node to remove from the walk.
    • remove

      public Node remove(int index)
      Specified by:
      remove in interface List<Node>
      Overrides:
      remove in class ArrayList<Node>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<Node>
      Specified by:
      remove in interface List<Node>
      Overrides:
      remove in class ArrayList<Node>
    • removeAll

      public boolean removeAll(Collection c)
      Specified by:
      removeAll in interface Collection<Node>
      Specified by:
      removeAll in interface List<Node>
      Overrides:
      removeAll in class ArrayList<Node>
    • isClosed

      public boolean isClosed()
      Determines if the walk is closed. A closed walk is one in which the first and last nodes are the same.
      Returns:
      True if closed, otherwise false.
    • getFirst

      public Node getFirst()
      Description copied from interface: NodeSequence
      Returns the first node in the sequence.
      Specified by:
      getFirst in interface NodeSequence
      Returns:
      Object of tupe Node.
      See Also:
    • getLast

      public Node getLast()
      Description copied from interface: NodeSequence
      Returns the last node in the sequence.
      Specified by:
      getLast in interface NodeSequence
      Returns:
      Object of type node.
      See Also:
    • buildEdges

      protected List<Edge> buildEdges()
      Internal method for building the edge set of the walk. This method calculated the edges upon every call.
      Returns:
      The list of edges for the walk, or null if the edge set could not be calculated due to an invalid walk.
    • reverse

      public void reverse()
      Reverses the path.
    • truncate

      public void truncate(int index)
      Truncates the path at the specified index. Nodes in the path whose index is >= the specified index are removed.
      Parameters:
      index - The index of first node to be removed.
    • riterator

      public Iterator<Node> riterator()
      Returns an iterator that iterates over the path in reverse. The iterator does not support the remove operation.
      Returns:
      the reverse iterator.
    • duplicate

      public Path duplicate()
    • equals

      public boolean equals(Object other)
      Specified by:
      equals in interface Collection<Node>
      Specified by:
      equals in interface List<Node>
      Overrides:
      equals in class ArrayList<Node>
    • equals

      public boolean equals(Walk other)
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<Node>
      Specified by:
      hashCode in interface List<Node>
      Overrides:
      hashCode in class ArrayList<Node>