Skip to content

Instantly share code, notes, and snippets.

@noahlz
Last active August 9, 2023 21:26
Show Gist options
  • Save noahlz/6fbcb66d92b50148db42 to your computer and use it in GitHub Desktop.
Save noahlz/6fbcb66d92b50148db42 to your computer and use it in GitHub Desktop.
My Java "Rorschach Test."
package com.transacttools.imaginary;
import com.transacttools.imaginary.util.ActionUtils;
import java.util.Date;
import java.text.SimpleDateFormat;
/**
* This class processes actions from the User Interface.
*
* TODO: Get this ready for production!
*/
class ActionProcessor {
public static SimpleDateFormat FORMAT = new SimpleDateFormat("YYYYMMdd");
// TODO: set this to true before compile!
private static final boolean PRODUCTION = false;
/** Process the action */
public Object doAction(String action, Object data) throws Exception {
if(action.equals("verify")) {
if(PRODUCTION) {
System.out.println("verified: " + data);
return ActionUtils.doVerify(data);
} else {
System.out.println("disabled");
return null;
}
} else if(action.equals("summarize")) {
return ActionUtils.doSumrz(data); // summarize the data...
} else if(action.equals("negate")) {
System.out.println("negated: " + data);
return ActionUtils.doNegt(data);
} else if(action.equals("format")){
String date = FORMAT.format((Date)data);
System.out.println("formatted date: " + date);
return date;
} else if(action.equals("add")) {
String[] nums = (String[])data;
int x = Integer.parseInt(nums[0]);
int y = Integer.parseInt(nums[1]);
// Add x and y
Integer sum = new Integer(x + y);
System.out.println("sum: " + sum);
return sum;
} else if (action.equals("replace")){
data = "new data";
return null;
} else {
throw new IllegalArgumentException("unknown action.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment