001 package listFW.visitor;
002
003 import listFW.*;
004
005 /**
006 * Reverses a particular kind of list only, but with reduced type safety due to delegating
007 * to host instead of rest.
008 * @author Mathias Ricken - Copyright 2008 - All rights reserved.
009 */
010 public class ReverseList2<T> implements IListAlgo<T,IList<T>, IListFactory<T>> {
011
012 public IMTList<T> emptyCase(IMTList<? extends T> host, IListFactory<T> ... fac) {
013 return fac[0].makeEmptyList();
014 }
015 @SuppressWarnings("unchecked")
016 public INEList<T> nonEmptyCase(INEList<? extends T> host, final IListFactory<T> ... fac) {
017 return host.execute(new IListAlgo<T,INEList<T>, IList<T>>() {
018 public INEList<T> emptyCase(IMTList<? extends T> h, IList<T> ... acc) {
019 return (INEList<T>)acc[0]; // cast required because delegating to host reduces type safety
020 }
021 public INEList<T> nonEmptyCase(INEList<? extends T> h, IList<T>... acc) {
022 return h.getRest().execute(this, fac[0].makeNEList(h.getFirst(), acc[0]));
023 }
024 },fac[0].makeEmptyList());
025 }
026 }
027
028