package br.com.caelum.vraptor.util;

import java.util.concurrent.Callable;

public abstract class Try {
	public static Try run(Callable<Void> callable) {
		try {
			Void call = callable.call();
			return new Success(call);
		} catch (Exception e) {
			return new Failed(e);
		}
	}

	public abstract boolean failed();

	public abstract Exception getException();

	public static class Success<T> extends Try {
		private final T result;

		public Success(T result) {
			this.result = result;
		}

		@Override
		public boolean failed() {
			return false;
		}

		@Override
		public Exception getException() {
			throw new UnsupportedOperationException();
		}
	}

	public static class Failed<T> extends Try {
		private final Exception e;

		public Failed(Exception e) {
			this.e = e;
		}

		@Override
		public boolean failed() {
			return true;
		}

		@Override
		public Exception getException() {
			return e;
		}
	}


}

@@ -90,24 +90,27 @@
 ct class Try
+%3CT%3E
  %7B%0A%09public s
@@ -114,16 +114,20 @@
 c static
+ %3CT%3E
  Try run
@@ -136,20 +136,17 @@
 allable%3C
-Void
+T
 %3E callab
@@ -166,12 +166,9 @@
 %0A%09%09%09
-Void
+T
  cal
@@ -308,24 +308,53 @@
  failed();%0A%0A
+%09public abstract T value();%0A%0A
 %09public abst
@@ -571,32 +571,93 @@
 urn false;%0A%09%09%7D%0A%0A
+%09%09@Override%0A%09%09public Object value() %7B%0A%09%09%09return result;%0A%09%09%7D%0A%0A
 %09%09@Override%0A%09%09pu
@@ -921,32 +921,121 @@
 turn true;%0A%09%09%7D%0A%0A
+%09%09@Override%0A%09%09public Object value() %7B%0A%09%09%09throw new UnsupportedOperationException();%0A%09%09%7D%0A%0A
 %09%09@Override%0A%09%09pu

Try should be generic