package listFW.visitor; import listFW.*; /** * Attempt to reverse any kind of list, but requires that the factory match the list * Could have serious problems at run-time due to type erasure * @author Mathias Ricken - Copyright 2008 - All rights reserved. */ public class ReverseList3 implements IListAlgo, IListFactory> { public IMTList emptyCase(IMTList host, IListFactory ... fac) { return fac[0].makeEmptyList(); } @SuppressWarnings("unchecked") public INEList nonEmptyCase(INEList host, IListFactory ... fac) { final IListFactory f = (IListFactory)fac[0]; return host.getRest().execute(new IListAlgo, INEList>() { public INEList emptyCase(IMTList h, INEList ... acc) { return acc[0]; } public INEList nonEmptyCase(INEList h, INEList... acc) { return h.getRest().execute(this, f.makeNEList(h.getFirst(), acc[0])); } },f.makeNEList(host.getFirst(), f.makeEmptyList())); } }