package lrs.visitor;
import lrs.*;
/**
* Unzips the host list so that it becomes the list that contains only the
* even-indexed elements.
* Returns the list holding the odd-indexed elements of the original host list.
* @author DXN
*/
public class Unzip implements IAlgo {
public static final Unzip Singleton = new Unzip();
private Unzip() {
}
/**
* The host stays empty. The returned list is another empty list.
* @param inp not used
* @return an empty LRStruct
*/
public Object emptyCase(LRStruct host, Object inp) {
return new LRStruct();
}
/**
* Recursively unzips the host's rest. This should return the odd-indexed
* elements of the orginal host's rest. These elements are the elements
* at index 2, 4, etc. of the orginal host list. Set the host's rest to
* this returned list. The host list will then contains only the
* even-indexed elements.
* On the other hand, when the original host's rest is unzipped, it changes
* and holds only its even-indexed elements. These elements are precisely
* the odd-indexed elements of the original host. So just return the
* original host's rest.
* The code is simpler than its English description.
* @param inp not used
* @return LRStruct
*/
public Object nonEmptyCase(LRStruct host, Object inp) {
LRStruct hostRest = host.getRest();
host.setRest((LRStruct)hostRest.execute(this, null));
return hostRest;
}
}