Module hw06

Class ToStringHelper

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

class ToStringHelper extends Object implements IListAlgo
Helps ToStringAlgo compute the String representation of the rest of the list. This is the recursive part of the forward accumulation algorithm.
  • Field Details

    • Singleton

      public static final ToStringHelper Singleton
      Singleton instance of helper algo
  • Constructor Details

    • ToStringHelper

      private ToStringHelper()
      Private constructor for Singleton
  • Method Details

    • emptyCase

      public Object emptyCase(MTList host, Object... acc)
      Returns the accumulated String + ")". At end of list: done!
      Specified by:
      emptyCase in interface IListAlgo
      Parameters:
      acc - acc[0] is the accumulated String representation of the preceding list.
      host - the MTList that is executing this algorithm.
      Returns:
      String
    • nonEmptyCase

      public Object nonEmptyCase(NEList host, Object... acc)
      Continues accumulating the String representation by appending ", " + first to acc and recurse!
      Specified by:
      nonEmptyCase in interface IListAlgo
      Parameters:
      acc - acc[0] is the accumulated String representation of the preceding list.
      host - the NEList that is executing this algorithm
      Returns:
      the String representation of the list.