package lrs.visitor; import lrs.*; public class Unzip2 implements IAlgo { public Object emptyCase(LRStruct host, Object... inp) { return new LRStruct(); } /** * Returns the odd-indexed elements. * Mutates the host to contain only the original even-indexed elements */ public Object nonEmptyCase(LRStruct host, Object... inp) { /* * host.getRest().execute(this): * returns the list that contains the remaining of the even indexed elements of host * mutates the host's rest to contain the odd-indexed elements of the original host list. */ LRStruct rest = host.getRest(); LRStruct remainingEvenOfHost = (LRStruct)rest.execute(this); // rest has now mutated to contain the odd indexed elements of the original host. host.setRest(remainingEvenOfHost); return rest; // to do } }