package list.dl.algo; import list.dl.DLList; /** * Counts the number of elements in the host as a whole. * @dependency list.dl.algo.LeftCount * @dependency list.dl.algo.RightCount uses */ public class ElementCount implements IDLAlgo { final public static ElementCount Singleton = new ElementCount(); private ElementCount() { } /** * @param hostList * @param inputParam */ public Object visit(DLList hostList, Object inputParam) { Integer nLeft = (Integer) hostList.executeLeft (LeftCount.Singleton, null); Integer nRight = (Integer) hostList.executeRight (RightCount.Singleton, null); return new Integer (nLeft.intValue () + nRight.intValue ()); } }