Skip to content

Commit

Permalink
Provide aliases for filter/pipe (#166)
Browse files Browse the repository at this point in the history
* Provide aliases for filter/pipe. Fix for #165
* Fully rename pipe/filter methods instead of providing aliases
  • Loading branch information
aalmiray authored and saturnism committed Nov 14, 2018
1 parent 2db9cde commit f2c2ab1
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 268 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ If you are using JDeferred 1.x, see [JDeferred 1.x Documentation](http://jdeferr
* Deferred object and Promise
* Promise callbacks
* ```.then(…)```
* ```.filter(…)```
* ```.pipe(…)```
* ```.done(…)```
* ```.fail(…)```
* ```.progress(…)```
* ```.always(…)```
* ```.pipeAlways(…)```
* Multiple promises
* ```.when(p1, p2, p3, …).then(…)```
* ```.race(p1, p2, p3, …).then(…)```
Expand Down Expand Up @@ -113,7 +116,7 @@ deferred.notify("100%");
```java
Deferred d = …;
Promise p = d.promise();
Promise filtered = p.then(new DoneFilter<Integer, Integer>() {
Promise filtered = p.filter(new DoneFilter<Integer, Integer>() {
public Integer filterDone(Integer result)
return result * 10;
}
Expand All @@ -137,7 +140,7 @@ d.resolve(3) -> 30.
Deferred d = ...;
Promise p = d.promise();

p.then(new DonePipe<Integer, Integer, Exception, Void>() {
p.pipe(new DonePipe<Integer, Integer, Exception, Void>() {
public Deferred<Integer, Exception, Void> pipeDone(Integer result) {
if (result < 100) {
return new DeferredObject<Integer, Void, Void>().resolve(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
*
* @author Stephan Classen
* @since 2.0
* @see Promise#always(AlwaysPipe)
* @see Promise#pipeAlways(AlwaysPipe)
*/
public interface AlwaysPipe<D, F, D_OUT, F_OUT, P> {

/**
* Invoked when the {@code Promise} resolves or rejects a value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
* @param <D_OUT> Type of the output from this filter
*
* @author Ray Tsang
* @see Promise#then(DoneFilter)
* @see Promise#then(DoneFilter, FailFilter)
* @see Promise#then(DoneFilter, FailFilter, ProgressFilter)
* @see Promise#filter(DoneFilter)
* @see Promise#filter(DoneFilter, FailFilter)
* @see Promise#filter(DoneFilter, FailFilter, ProgressFilter)
*/
public interface DoneFilter<D, D_OUT> {
D_OUT filterDone(final D result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
* @param <P_OUT> Type of the progress output from this pipe
*
* @author Ray Tsang
* @see Promise#then(DonePipe)
* @see Promise#then(DonePipe, FailPipe)
* @see Promise#then(DonePipe, FailPipe, ProgressPipe)
* @see Promise#pipe(DonePipe)
* @see Promise#pipe(DonePipe, FailPipe)
* @see Promise#pipe(DonePipe, FailPipe, ProgressPipe)
*/
public interface DonePipe<D, D_OUT, F_OUT, P_OUT> {
Promise<D_OUT, F_OUT, P_OUT> pipeDone(final D result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* @param <F_OUT> Type of the failure output from this filter
*
* @author Ray Tsang
* @see Promise#then(DoneFilter, FailFilter)
* @see Promise#then(DoneFilter, FailFilter, ProgressFilter)
* @see Promise#filter(DoneFilter, FailFilter)
* @see Promise#filter(DoneFilter, FailFilter, ProgressFilter)
*/
public interface FailFilter<F, F_OUT> {
F_OUT filterFail(final F result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
* @param <P_OUT> Type of the progress output from this pipe
*
* @author Ray Tsang
* @see Promise#then(DonePipe, FailPipe)
* @see Promise#then(DonePipe, FailPipe, ProgressPipe)
* @see Promise#pipe(DonePipe, FailPipe)
* @see Promise#pipe(DonePipe, FailPipe, ProgressPipe)
*/
public interface FailPipe<F, D_OUT, F_OUT, P_OUT> {
Promise<D_OUT, F_OUT, P_OUT> pipeFail(final F result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @param <P_OUT> Type of the progress output from this filter
*
* @author Ray Tsang
* @see Deferred#then(DoneFilter, FailFilter, ProgressFilter)
* @see Deferred#filter(DoneFilter, FailFilter, ProgressFilter)
*/
public interface ProgressFilter<P, P_OUT> {
P_OUT filterProgress(final P progress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @param <P_OUT> Type of the progress output from this pipe
*
* @author Ray Tsang
* @see Promise#then(DonePipe, FailPipe, ProgressPipe)
* @see Promise#pipe(DonePipe, FailPipe, ProgressPipe)
*/
public interface ProgressPipe<P, D_OUT, F_OUT, P_OUT> {
Promise<D_OUT, F_OUT, P_OUT> pipeProgress(final P result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,25 @@ Promise<D, F, P> then(DoneCallback<? super D> doneCallback,
FailCallback<? super F> failCallback, ProgressCallback<? super P> progressCallback);

/**
* Equivalent to {@code then(doneFilter, null, null)}
* Equivalent to {@code filter(doneFilter, null, null)}
*
* @see #then(DoneFilter, FailFilter, ProgressFilter)
* @see #filter(DoneFilter, FailFilter, ProgressFilter)
* @param doneFilter the filter to execute when a result is available
* @return a new promise for the filtered result
*/
<D_OUT> Promise<D_OUT, F, P> then(DoneFilter<? super D, ? extends D_OUT> doneFilter);
<D_OUT> Promise<D_OUT, F, P> filter(DoneFilter<? super D, ? extends D_OUT> doneFilter);

/**
* Equivalent to {@code then(doneFilter, failFilter, null)}
* Equivalent to {@code filter(doneFilter, failFilter, null)}
*
* @see #then(DoneFilter, FailFilter, ProgressFilter)
* @see #filter(DoneFilter, FailFilter, ProgressFilter)
* @param doneFilter the filter to execute when a result is available
* @param failFilter the filter to execute when a failure is available
* @return a new promise for the filtered result and failure.
*/
<D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> then(
DoneFilter<? super D, ? extends D_OUT> doneFilter,
FailFilter<? super F, ? extends F_OUT> failFilter);
<D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> filter(
DoneFilter<? super D, ? extends D_OUT> doneFilter,
FailFilter<? super F, ? extends F_OUT> failFilter);

/**
* This method will register filters such that when a Deferred object is either
Expand All @@ -166,13 +166,13 @@ <D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> then(
* to the map() method of the java stream API.
*
* If any of the filter is not specified ({@code null}), a default No Op filter is used.
* If your filter is returning a {@link Promise} consider using {@link #then(DonePipe, FailPipe, ProgressPipe)}.
* If your filter is returning a {@link Promise} consider using {@link #pipe(DonePipe, FailPipe, ProgressPipe)}.
*
* <pre>
* <code>
* Deferred deferred = new DeferredObject();
* Promise promise = deferred.promise();
* Promise filtered = promise.then(new DoneFilter<Integer, Integer>() {
* Promise filtered = promise.filter(new DoneFilter<Integer, Integer>() {
* Integer filterDone(Integer result) {
* return result * 10;
* }
Expand All @@ -196,31 +196,31 @@ <D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> then(
* If {@code null}, use {@link org.jdeferred2.impl.FilteredPromise.NoOpProgressFilter}
* @return a new promise for the filtered result, failure and progress.
*/
<D_OUT, F_OUT, P_OUT> Promise<D_OUT, F_OUT, P_OUT> then(
DoneFilter<? super D, ? extends D_OUT> doneFilter,
FailFilter<? super F, ? extends F_OUT> failFilter,
ProgressFilter<? super P, ? extends P_OUT> progressFilter);
<D_OUT, F_OUT, P_OUT> Promise<D_OUT, F_OUT, P_OUT> filter(
DoneFilter<? super D, ? extends D_OUT> doneFilter,
FailFilter<? super F, ? extends F_OUT> failFilter,
ProgressFilter<? super P, ? extends P_OUT> progressFilter);

/**
* Equivalent to {#code then(DonePipe, null, null)}
* Equivalent to {#code pipe(DonePipe, null, null)}
*
* @see #then(DonePipe, FailPipe, ProgressPipe)
* @see #pipe(DonePipe, FailPipe, ProgressPipe)
* @param donePipe the pipe to invoke when a result is available
* @return a new promise for the piped result.
*/
<D_OUT> Promise<D_OUT, F, P> then(DonePipe<? super D, ? extends D_OUT, ? extends F, ? extends P> donePipe);
<D_OUT> Promise<D_OUT, F, P> pipe(DonePipe<? super D, ? extends D_OUT, ? extends F, ? extends P> donePipe);

/**
* Equivalent to {@code then(DonePipe, FailPipe, null)}
* Equivalent to {@code pipe(DonePipe, FailPipe, null)}
*
* @see #then(DonePipe, FailPipe, ProgressPipe)
* @see #pipe(DonePipe, FailPipe, ProgressPipe)
* @param donePipe the pipe to invoke when a result is available
* @param failPipe the pipe to invoke when a failure is available
* @return a new promise for the piped result and failure.
*/
<D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> then(
DonePipe<? super D, ? extends D_OUT, ? extends F_OUT, ? extends P> donePipe,
FailPipe<? super F, ? extends D_OUT, ? extends F_OUT, ? extends P> failPipe);
<D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> pipe(
DonePipe<? super D, ? extends D_OUT, ? extends F_OUT, ? extends P> donePipe,
FailPipe<? super F, ? extends D_OUT, ? extends F_OUT, ? extends P> failPipe);

/**
* This method will register pipes such that when a Deferred object is either
Expand All @@ -238,11 +238,11 @@ <D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> then(
*
* Pipes start a new {@link Deferred} object. This allows to chain asynchronous calls.
*
* If your pipe does not do any asynchronous work consider using {@link #then(DoneFilter, FailFilter, ProgressFilter)}
* If your pipe does not do any asynchronous work consider using {@link #filter(DoneFilter, FailFilter, ProgressFilter)}
*
* <pre>
* <code>
* promise.then(new DonePipe<Integer, Integer, String, Void>() {
* promise.pipe(new DonePipe<Integer, Integer, String, Void>() {
* {@literal @}Override
* Deferred<Integer, Void, Void> pipeDone(Integer result) {
* // Reject values greater than 100
Expand All @@ -265,10 +265,10 @@ <D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> then(
* If {@code null}, progress is piped unchanged
* @return a new promise for the piped result, failure and progress.
*/
<D_OUT, F_OUT, P_OUT> Promise<D_OUT, F_OUT, P_OUT> then(
DonePipe<? super D, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> donePipe,
FailPipe<? super F, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> failPipe,
ProgressPipe<? super P, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> progressPipe);
<D_OUT, F_OUT, P_OUT> Promise<D_OUT, F_OUT, P_OUT> pipe(
DonePipe<? super D, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> donePipe,
FailPipe<? super F, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> failPipe,
ProgressPipe<? super P, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> progressPipe);

/**
* This method will register a pipe such that when a Deferred object is either
Expand All @@ -287,7 +287,7 @@ <D_OUT, F_OUT, P_OUT> Promise<D_OUT, F_OUT, P_OUT> then(
*
* <pre>
* <code>
* promise.always(new AlwaysPipe<Integer, Integer, String, String, Void>() {
* promise.pipeAlways(new pipe<Integer, Integer, String, String, Void>() {
* {@literal @}Override
* Promise<Integer, Void, Void> pipeAlways(State state, Integer resolved, Integer rejected) {
* if (state == State.RESOLVED) {
Expand All @@ -305,8 +305,8 @@ <D_OUT, F_OUT, P_OUT> Promise<D_OUT, F_OUT, P_OUT> then(
* @param alwaysPipe the pipe to invoke when a result or failure is available.
* @return a new promise for the piped result or failure.
*/
<D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> always(
AlwaysPipe<? super D, ? super F, ? extends D_OUT, ? extends F_OUT, ? extends P> alwaysPipe);
<D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> pipeAlways(
AlwaysPipe<? super D, ? super F, ? extends D_OUT, ? extends F_OUT, ? extends P> alwaysPipe);

/**
* This method will register {@link DoneCallback} so that when a Deferred object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,48 +185,48 @@ public Promise<D, F, P> then(DoneCallback<? super D> doneCallback, FailCallback<
}

@Override
public <D_OUT> Promise<D_OUT, F, P> then(
DoneFilter<? super D, ? extends D_OUT> doneFilter) {
public <D_OUT> Promise<D_OUT, F, P> filter(
DoneFilter<? super D, ? extends D_OUT> doneFilter) {
return new FilteredPromise<D, F, P, D_OUT, F, P>(this, doneFilter, null, null);
}

@Override
public <D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> then(
DoneFilter<? super D, ? extends D_OUT> doneFilter, FailFilter<? super F, ? extends F_OUT> failFilter) {
public <D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> filter(
DoneFilter<? super D, ? extends D_OUT> doneFilter, FailFilter<? super F, ? extends F_OUT> failFilter) {
return new FilteredPromise<D, F, P, D_OUT, F_OUT, P>(this, doneFilter, failFilter, null);
}

@Override
public <D_OUT, F_OUT, P_OUT> Promise<D_OUT, F_OUT, P_OUT> then(
DoneFilter<? super D, ? extends D_OUT> doneFilter, FailFilter<? super F, ? extends F_OUT> failFilter,
ProgressFilter<? super P, ? extends P_OUT> progressFilter) {
public <D_OUT, F_OUT, P_OUT> Promise<D_OUT, F_OUT, P_OUT> filter(
DoneFilter<? super D, ? extends D_OUT> doneFilter, FailFilter<? super F, ? extends F_OUT> failFilter,
ProgressFilter<? super P, ? extends P_OUT> progressFilter) {
return new FilteredPromise<D, F, P, D_OUT, F_OUT, P_OUT>(this, doneFilter, failFilter, progressFilter);
}

@Override
public <D_OUT> Promise<D_OUT, F, P> then(
DonePipe<? super D, ? extends D_OUT, ? extends F, ? extends P> doneFilter) {
return new PipedPromise<D, F, P, D_OUT, F, P>(this, doneFilter, null, null);
public <D_OUT> Promise<D_OUT, F, P> pipe(
DonePipe<? super D, ? extends D_OUT, ? extends F, ? extends P> donePipe) {
return new PipedPromise<D, F, P, D_OUT, F, P>(this, donePipe, null, null);
}

@Override
public <D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> then(
DonePipe<? super D, ? extends D_OUT, ? extends F_OUT, ? extends P> doneFilter,
FailPipe<? super F, ? extends D_OUT, ? extends F_OUT, ? extends P> failFilter) {
return new PipedPromise<D, F, P, D_OUT, F_OUT, P>(this, doneFilter, failFilter, null);
public <D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> pipe(
DonePipe<? super D, ? extends D_OUT, ? extends F_OUT, ? extends P> donePipe,
FailPipe<? super F, ? extends D_OUT, ? extends F_OUT, ? extends P> failPipe) {
return new PipedPromise<D, F, P, D_OUT, F_OUT, P>(this, donePipe, failPipe, null);
}

@Override
public <D_OUT, F_OUT, P_OUT> Promise<D_OUT, F_OUT, P_OUT> then(
DonePipe<? super D, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> doneFilter,
FailPipe<? super F, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> failFilter,
ProgressPipe<? super P, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> progressFilter) {
return new PipedPromise<D, F, P, D_OUT, F_OUT, P_OUT>(this, doneFilter, failFilter, progressFilter);
public <D_OUT, F_OUT, P_OUT> Promise<D_OUT, F_OUT, P_OUT> pipe(
DonePipe<? super D, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> donePipe,
FailPipe<? super F, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> failPipe,
ProgressPipe<? super P, ? extends D_OUT, ? extends F_OUT, ? extends P_OUT> progressPipe) {
return new PipedPromise<D, F, P, D_OUT, F_OUT, P_OUT>(this, donePipe, failPipe, progressPipe);
}

@Override
public <D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> always(AlwaysPipe<? super D, ? super F, ? extends D_OUT, ? extends F_OUT, ? extends P> alwaysFilter) {
return new PipedPromise<D, F, P, D_OUT, F_OUT, P>(this, alwaysFilter);
public <D_OUT, F_OUT> Promise<D_OUT, F_OUT, P> pipeAlways(AlwaysPipe<? super D, ? super F, ? extends D_OUT, ? extends F_OUT, ? extends P> alwaysPipe) {
return new PipedPromise<D, F, P, D_OUT, F_OUT, P>(this, alwaysPipe);
}

@Override
Expand Down
Loading

0 comments on commit f2c2ab1

Please sign in to comment.