Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- AuthenticateMethod();
- } catch (AuthenticateError ae) {
- // Display ae.getMessage() to user..
- System.out.println(ae.getMessage());
- //ae.printStackTrace();
- }
- class Tuple<L, R> {
- public final L left;
- public final R right;
- public Tuple( L left, R right) {
- this.left = left;
- this.right = right;
- }
- }
- public Option<String> authenticate(String arg) {
- if (success(arg))
- return Option.some("Just an example");
- else
- return Option.none();
- }
- ...
- for(String s : authenticate(secret)) {
- privilegedMethod();
- }
- public Either<Fail, String> authenticate(String arg) {
- if (success(arg))
- return Either.right("Just an example");
- else
- return Either.left(Fail.authenticationFailure());
- }
- ...
- Either<Fail, String> auth = authenticate(secret);
- for(String s : auth.rightProjection()) {
- privilegedMethod();
- }
- for(Fail f : auth.leftProjection()) {
- System.out.println("FAIL");
- }
- class SomeClass {
- public int authenticate (Client client) {
- //returns 0 if success otherwise one value per possible failure
- }
- public String getAuthenticationResultMessage (int authenticateResult) {}
- //returns message associated to authenticateResult
- }
- if (authenticate()) {
- // normal behaviour...
- }
- else {
- // error case...
- }
- authenticate();
- // normal behaviour...
- if (isAuthenticated()) {
- //...
- }
- public boolean authenticate(Client client, final StringBuilder sb) {
- if (sb == null)
- throw new IllegalArgumentException();
- if (isOK()) {
- sb.append("info message");
- return true;
- } else {
- sb.append("error message");
- return false;
- }
- }
- public static void main(String[] args)
- {
- Object[] result = methodReturningStatus();
- if(!(Boolean)result[0])
- System.out.println("Method return: "+ result[1]);
- }
- static Object[] methodReturningStatus()
- {
- Object[] result = new Object[2];
- result[0] = false;
- result[1] = "Error happened";
- return result;
- }
Add Comment
Please, Sign In to add comment