Module hw06

Class ToStringAlgo

java.lang.Object
provided.listFW.visitors.ToStringAlgo
All Implemented Interfaces:
IListAlgo

public class ToStringAlgo extends Object implements IListAlgo
Computes a String representation of IList showing a left parenthesis followed by elements of the IList separated by commas, ending with with a right parenthesis. Implemented as a forward accumulation algorithm.
  • Field Details

    • Singleton

      public static final ToStringAlgo Singleton
      Singeton instance
  • Constructor Details

    • ToStringAlgo

      private ToStringAlgo()
      Private constructor for the Singleton
  • Method Details

    • emptyCase

      public Object emptyCase(MTList host, Object... nu)
      Returns "()".
      Specified by:
      emptyCase in interface IListAlgo
      Parameters:
      nu - not used
      host - the MTList that is executing this algorithm.
      Returns:
      String
    • nonEmptyCase

      public Object nonEmptyCase(NEList host, Object... nu)
      Passes "(" + first to the rest of IList and asks for help to complete the computation.
      Specified by:
      nonEmptyCase in interface IListAlgo
      Parameters:
      nu - not used
      host - the NEList that is executing this algorithm
      Returns:
      String