001 package listFW.visitor; 002 003 import listFW.*; 004 005 /** 006 * Attempt to reverse any kind of list, but requires that the factory match the list 007 * Could have serious problems at run-time due to type erasure 008 * @author Mathias Ricken - Copyright 2008 - All rights reserved. 009 */ 010 public class ReverseList3 implements IListAlgo<Object,IList<? extends Object>, IListFactory<?>> { 011 public IMTList<? extends Object> emptyCase(IMTList<? extends Object> host, IListFactory<?> ... fac) { 012 return fac[0].makeEmptyList(); 013 } 014 @SuppressWarnings("unchecked") 015 public INEList<? extends Object> nonEmptyCase(INEList<? extends Object> host, IListFactory<?> ... fac) { 016 final IListFactory<Object> f = (IListFactory<Object>)fac[0]; 017 return host.getRest().execute(new IListAlgo<Object,INEList<Object>, INEList<Object>>() { 018 public INEList<Object> emptyCase(IMTList<? extends Object> h, INEList<Object> ... acc) { 019 return acc[0]; 020 } 021 public INEList<Object> nonEmptyCase(INEList<? extends Object> h, INEList<Object>... acc) { 022 return h.getRest().execute(this, f.makeNEList(h.getFirst(), acc[0])); 023 } 024 },f.makeNEList(host.getFirst(), f.makeEmptyList())); 025 } 026 } 027 028