package com.github.xeranic.blacksmith.deferred;

public class Deferred<T> extends AbstractPromise<T> {

	public static <T> Deferred<T> createResolved(T result) {
		return new Deferred<T>().resolve(result);
	}
	
	public static <T> Deferred<T> createRejected(Throwable failure) {
		return new Deferred<T>().reject(failure);
	}
		
	public final synchronized Deferred<T> resolve(T result) {
		if (!isPending()) {
			throw new IllegalStateException("already resolved or rejected");
		}
		this.state = State.RESOLVED;
		this.result = result;
		triggerDone();
		triggerAlways();
		return this;
	}

	public final synchronized Deferred<T> reject(Throwable failure) {
		if (!isPending()) {
			throw new IllegalStateException("already resolved or rejected");
		}
		this.state = State.REJECTED;
		this.failure = failure;
		triggerFail();
		triggerAlways();
		return this;
	}

    public final synchronized Deferred<T> notify(Progress progress) {
    	if (!isPending()) {
    		throw new IllegalStateException("already resolved or rejected");
    	}
    	this.progress = progress;
    	triggerProgress();
    	return this;
    }

	public final Promise<T> promise() {
		return this;
	}

}

@@ -202,17 +202,16 @@
 lt);%0A%09%7D%0A
-%09
 %0A%09public
@@ -317,18 +317,16 @@
 re);%0A%09%7D%0A
-%09%09
 %0A%09public
@@ -854,20 +854,17 @@
 is;%0A%09%7D%0A%0A
-    
+%09
 public f
@@ -921,20 +921,17 @@
 ress) %7B%0A
-    
+%09
 %09if (!is
@@ -943,20 +943,17 @@
 ng()) %7B%0A
-    
+%09
 %09%09throw 
@@ -1015,19 +1015,13 @@
 %22);%0A
-    %09%7D%0A    
+%09%09%7D%0A%09
 %09thi
@@ -1043,20 +1043,17 @@
 ogress;%0A
-    
+%09
 %09trigger
@@ -1064,20 +1064,17 @@
 ress();%0A
-    
+%09
 %09return 
@@ -1083,12 +1083,9 @@
 is;%0A
-    
+%09
 %7D%0A%0A%09

fix code style