package listFW.visitor; import listFW.*; /** * Reverses a particular kind of list only, but with reduced type safety due to delegating * to host instead of rest. * @author Mathias Ricken - Copyright 2008 - All rights reserved. */ public class ReverseList2 implements IListAlgo, IListFactory> { public IMTList emptyCase(IMTList host, IListFactory ... fac) { return fac[0].makeEmptyList(); } @SuppressWarnings("unchecked") public INEList nonEmptyCase(INEList host, final IListFactory ... fac) { return host.execute(new IListAlgo, IList>() { public INEList emptyCase(IMTList h, IList ... acc) { return (INEList)acc[0]; // cast required because delegating to host reduces type safety } public INEList nonEmptyCase(INEList h, IList... acc) { return h.getRest().execute(this, fac[0].makeNEList(h.getFirst(), acc[0])); } },fac[0].makeEmptyList()); } }