001 package lrs.visitor;
002 import lrs.*;
003 // This visitor appends a value to the end of a list
004 public class LRSAppend implements IAlgo
005 {
006 public static LRSAppend Singleton = new LRSAppend();
007
008 private LRSAppend()
009 {
010 }
011
012 public Object emptyCase(LRStruct host, Object... param)
013 {
014 // The empty node is the end of the list, so insert the new data here.
015 host.insertFront(param[0]);
016 return(null);
017 }
018
019 public Object nonEmptyCase(LRStruct host, Object... param)
020 {
021 // The non-empty node is not the end of the list, so recurse.
022 return host.getRest().execute(this,param);
023 }
024 }