forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge with master, added future operators
- Loading branch information
Showing
13 changed files
with
2,627 additions
and
724 deletions.
There are no files selected for viewing
1,744 changes: 1,145 additions & 599 deletions
1,744
rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/Async.java
Large diffs are not rendered by default.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/Functionals.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* Copyright 2013 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package rx.util.async.operators; | ||
|
||
import rx.util.functions.Action0; | ||
import rx.util.functions.Action1; | ||
|
||
/** | ||
* Utility methods convert between functional interfaces of actions and functions. | ||
*/ | ||
public final class Functionals { | ||
private Functionals() { | ||
throw new IllegalStateException("No instances!"); | ||
} | ||
/** | ||
* Return an action which takes a Throwable and does nothing. | ||
* <p>(To avoid casting from the generic empty1().) | ||
* @return the action | ||
*/ | ||
public static Action1<Throwable> emptyThrowable() { | ||
return EMPTY_THROWABLE; | ||
} | ||
/** | ||
* An action that takes a Throwable and does nothing. | ||
*/ | ||
private static final Action1<Throwable> EMPTY_THROWABLE = new EmptyThrowable(); | ||
/** An empty throwable class. */ | ||
private static final class EmptyThrowable implements Action1<Throwable> { | ||
@Override | ||
public void call(Throwable t1) { | ||
} | ||
} | ||
/** | ||
* Return an Action0 instance which does nothing. | ||
* @return an Action0 instance which does nothing | ||
*/ | ||
public static Action0 empty() { | ||
return EMPTY; | ||
} | ||
/** A single empty instance. */ | ||
private static final Action0 EMPTY = new EmptyAction(); | ||
/** An empty action class. */ | ||
private static final class EmptyAction implements Action0 { | ||
@Override | ||
public void call() { | ||
} | ||
} | ||
|
||
/** | ||
* Converts a runnable instance into an Action0 instance. | ||
* @param run the Runnable to run when the Action0 is called | ||
* @return the Action0 wrapping the Runnable | ||
*/ | ||
public static Action0 fromRunnable(Runnable run) { | ||
if (run == null) { | ||
throw new NullPointerException("run"); | ||
} | ||
return new ActionWrappingRunnable(run); | ||
} | ||
/** An Action0 which wraps and calls a Runnable. */ | ||
private static final class ActionWrappingRunnable implements Action0 { | ||
final Runnable run; | ||
|
||
public ActionWrappingRunnable(Runnable run) { | ||
this.run = run; | ||
} | ||
|
||
@Override | ||
public void call() { | ||
run.run(); | ||
} | ||
|
||
} | ||
/** | ||
* Converts an Action0 instance into a Runnable instance. | ||
* @param action the Action0 to call when the Runnable is run | ||
* @return the Runnable wrapping the Action0 | ||
*/ | ||
public static Runnable toRunnable(Action0 action) { | ||
if (action == null) { | ||
throw new NullPointerException("action"); | ||
} | ||
return new RunnableAction(action); | ||
} | ||
/** An Action0 which wraps and calls a Runnable. */ | ||
private static final class RunnableAction implements Runnable { | ||
final Action0 action; | ||
|
||
public RunnableAction(Action0 action) { | ||
this.action = action; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
action.call(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.