Last active
August 9, 2023 21:26
-
-
Save noahlz/6fbcb66d92b50148db42 to your computer and use it in GitHub Desktop.
My Java "Rorschach Test."
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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