package clist.visitor; import clist.*; /** * Prints the host CList in the clockwise direction via System.out. */ public class PrintClockwise implements IAlgo { private CList _stop; public PrintClockwise(CList stop) { _stop = stop; } /** * Prints a new line. */ public Object emptyCase(CList host, Object input) { System.out.println(); return null; } /** * Needs to distinguish the case when the host has one element * from the case when the host has more than one element. */ public Object nonEmptyCase(CList host, Object input) { CList tail = host.getRestClockwise(); if (tail.equals(_stop)) System.out.println(host.getFirstClockwise()); else { System.out.print(host.getFirstClockwise() + " "); tail.executeClockwise(this, input); } return null; } }