You are here

Anonymous Helpers

6 June, 2016 - 14:35
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/402b20ad-c01f-45f1-9743-05eadb1f710e@37.6

Anonymous Helper Visitor inside of ToString1

Comments

package listFW.visitor;
import listFW.*;
public class ToString1WithAnonymousHelper implements IListAlgo { 
public static final
ToString1WithAnonymousHelper Singleton = new ToString1WithAnonymousHelper();
private ToString1WithAnonymousHelper() {
}
 
 
private static final IListAlgo AnonymousHelper = new IListAlgo() {
public Object emptyCase(IMTList host, Object... acc) {
return acc[0] + ")";
}
public Object nonEmptyCase(INEList host, Object... acc) {
return host.getRest().execute(this, acc[0] + ", " + host.getFirst());
}
}; // PAY ATTENTION TO THE SEMI-COLON HERE!
 
 
public Object emptyCase(IMTList host, Object... nu) {
return "()";
}
public Object nonEmptyCase(INEList host, Object... nu) {
return host.getRest().execute(AnonymousHelper, "(" + host.getFirst());
}
}
 
 
 

Anonymous Helper Visitor inside of ToString2

Comments

package listFW.visitor;
import listFW.*;
public class ToString2WithAnonymousHelper implements IListAlgo { 
public static final
ToString2WithAnonymousHelper Singleton = new ToString2WithAnonymousHelper();
private ToString2WithAnonymousHelper() {
}
 
 
private static final IListAlgo AnonymousHelper = new IListAlgo() {
public Object emptyCase(IMTList host, Object... acc) {
return "(" + acc[0] + ")";
}
public Object nonEmptyCase(INEList host, Object... acc) {
return host.getRest().execute(this, acc[0] + ", " + host.getFirst());
}
}; // PAY ATTENTION TO THE SEMI-COLON HERE!
 
 
public Object emptyCase(IMTList host, Object... nu) {
return "()";
}
public Object nonEmptyCase(INEList host, Object... nu) {
return host.getRest().execute(AnonymousHelper, host.getFirst().toString());
}
}
 
 
 

Anonymous Helper Visitor inside of ToString3

Comments

package listFW.visitor;
import listFW.*;
public class ToString3WithAnonymousHelper implements IListAlgo { 
public static final
ToString3WithAnonymousHelper Singleton = new ToString3WithAnonymousHelper();
private ToString3WithAnonymousHelper() {
}
 
 
private static final IListAlgo AnonymousHelper = new IListAlgo() {
public Object emptyCase(IMTList host, Object... nu) {
return ")";
}
public Object nonEmptyCase(INEList host, Object... nu) {
return ", " + host.getFirst() + host.getRest().execute(this);
}
}; // PAY ATTENTION TO THE SEMI-COLON HERE!
 
 
public Object emptyCase(IMTList host, Object... nu) {
return "()";
}
public Object nonEmptyCase(INEList host, Object... nu) {
return "(" + host.getFirst() + host.getRest().execute(AnonymousHelper);
}
}