package lrs.visitor; import lrs.*; /** * Removes the odd-indexed elements from the host LRStruct and retuns * an LRStruct containing these elements. * @author Dung X. Nguyen - Copyright 2005 - All rights reserved. */ public class Unzip implements IAlgo { public final static Unzip Singleton = new Unzip(); private Unzip() { } /** * @param host is empty. * @param nu not used * @return an empty LRStruct. */ public Object emptyCase(LRStruct host, Object... nu) { return new LRStruct(); } /** * @param host is not empty * @param nu not used * @return LRStruct containing the odd indexed element of the orignal host. */ public Object nonEmptyCase(LRStruct host, Object... nu) { // Hold on to the tail before setting the host's rest to a different list: LRStruct tail = host.getRest(); // Get the odd indexed elements of the tail: LRStruct other = (LRStruct)tail.execute(this); // The odd indexed elements of the tail are the even-indexed elements // of the original host: host.setRest(other); return tail; } }