update code style
This commit is contained in:
@@ -51,8 +51,9 @@ public final class AtomicObservableSubscription implements Subscription {
|
||||
* constructed)
|
||||
*
|
||||
* @param actualSubscription
|
||||
*
|
||||
* @throws IllegalStateException if trying to set more than once (or use
|
||||
* this method after setting via constructor)
|
||||
* this method after setting via constructor)
|
||||
*/
|
||||
public AtomicObservableSubscription wrap(Subscription actualSubscription) {
|
||||
if (!this.actualSubscription.compareAndSet(null, actualSubscription))
|
||||
|
||||
@@ -9,33 +9,38 @@ import rx.plugins.RxJavaPlugins;
|
||||
/**
|
||||
* Wrapper around Observer to ensure compliance with Rx contract.
|
||||
* <p>
|
||||
* The following is taken from the Rx Design Guidelines document: http://go.microsoft.com/fwlink/?LinkID=205219
|
||||
* The following is taken from the Rx Design Guidelines document:
|
||||
* http://go.microsoft.com/fwlink/?LinkID=205219
|
||||
* <pre>
|
||||
* Messages sent to instances of the IObserver interface follow the following grammar:
|
||||
*
|
||||
*
|
||||
* OnNext* (OnCompleted | OnError)?
|
||||
*
|
||||
*
|
||||
* This grammar allows observable sequences to send any amount (0 or more) of OnNext messages to the subscribed
|
||||
* observer instance, optionally followed by a single success (OnCompleted) or failure (OnError) message.
|
||||
*
|
||||
*
|
||||
* The single message indicating that an observable sequence has finished ensures that consumers of the observable
|
||||
* sequence can deterministically establish that it is safe to perform cleanup operations.
|
||||
*
|
||||
*
|
||||
* A single failure further ensures that abort semantics can be maintained for operators that work on
|
||||
* multiple observable sequences (see paragraph 6.6).
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* This wrapper will do the following:
|
||||
* <ul>
|
||||
* <li>Allow only single execution of either onError or onCompleted.</li>
|
||||
* <li>Once an onComplete or onError are performed, no further calls can be executed</li>
|
||||
* <li>If unsubscribe is called, this means we call completed() and don't allow any further onNext calls.</li>
|
||||
* <li>When onError or onComplete occur it will unsubscribe from the Observable (if executing asynchronously).</li>
|
||||
* <li>Once an onComplete or onError are performed, no further calls can be
|
||||
* executed</li>
|
||||
* <li>If unsubscribe is called, this means we call completed() and don't allow
|
||||
* any further onNext calls.</li>
|
||||
* <li>When onError or onComplete occur it will unsubscribe from the Observable
|
||||
* (if executing asynchronously).</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* It will not synchronize onNext execution. Use the {@link SynchronizedObserver} to do that.
|
||||
*
|
||||
* It will not synchronize onNext execution. Use the
|
||||
* {@link SynchronizedObserver} to do that.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class AtomicObserver<T> implements Observer<T> {
|
||||
@@ -85,9 +90,8 @@ public class AtomicObserver<T> implements Observer<T> {
|
||||
@Override
|
||||
public void onNext(T args) {
|
||||
try {
|
||||
if (!isFinished.get()) {
|
||||
if (!isFinished.get())
|
||||
actual.onNext(args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// handle errors if the onNext implementation fails, not just if the Observable fails
|
||||
onError(e);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,16 +16,16 @@
|
||||
package rx.util;
|
||||
|
||||
public class Exceptions {
|
||||
|
||||
private Exceptions() {
|
||||
|
||||
}
|
||||
|
||||
public static RuntimeException propagate(Throwable t) {
|
||||
if (t instanceof RuntimeException) {
|
||||
if (t instanceof RuntimeException)
|
||||
throw (RuntimeException) t;
|
||||
} else {
|
||||
else
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -19,6 +19,7 @@ import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public final class Range implements Iterable<Integer> {
|
||||
|
||||
private final int start;
|
||||
private final int end;
|
||||
private final int step;
|
||||
@@ -53,9 +54,8 @@ public final class Range implements Iterable<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer next() {
|
||||
if (!hasNext()) {
|
||||
if (!hasNext())
|
||||
throw new NoSuchElementException("No more elements");
|
||||
}
|
||||
int result = current;
|
||||
current += step;
|
||||
return result;
|
||||
@@ -72,4 +72,4 @@ public final class Range implements Iterable<Integer> {
|
||||
public String toString() {
|
||||
return "Range (" + start + ", " + end + "), step " + step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -22,29 +22,36 @@ import rx.Observer;
|
||||
* <p>
|
||||
* Execution rules are:
|
||||
* <ul>
|
||||
* <li>Allow only single-threaded, synchronous, ordered execution of onNext, onCompleted, onError</li>
|
||||
* <li>Once an onComplete or onError are performed, no further calls can be executed</li>
|
||||
* <li>If unsubscribe is called, this means we call completed() and don't allow any further onNext calls.</li>
|
||||
* <li>Allow only single-threaded, synchronous, ordered execution of onNext,
|
||||
* onCompleted, onError</li>
|
||||
* <li>Once an onComplete or onError are performed, no further calls can be
|
||||
* executed</li>
|
||||
* <li>If unsubscribe is called, this means we call completed() and don't allow
|
||||
* any further onNext calls.</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public final class SynchronizedObserver<T> implements Observer<T> {
|
||||
|
||||
/**
|
||||
* Intrinsic synchronized locking with double-check short-circuiting was chosen after testing several other implementations.
|
||||
*
|
||||
* The code and results can be found here:
|
||||
* - https://github.com/benjchristensen/JavaLockPerformanceTests/tree/master/results/Observer
|
||||
* - https://github.com/benjchristensen/JavaLockPerformanceTests/tree/master/src/com/benjchristensen/performance/locks/Observer
|
||||
*
|
||||
* The major characteristic that made me choose synchronized instead of Reentrant or a customer AbstractQueueSynchronizer implementation
|
||||
* is that intrinsic locking performed better when nested, and AtomicObserver will end up nested most of the time since Rx is
|
||||
* compositional by its very nature.
|
||||
*
|
||||
* // TODO composing of this class should rarely happen now with updated design so this decision should be revisited
|
||||
* Intrinsic synchronized locking with double-check short-circuiting was
|
||||
* chosen after testing several other implementations.
|
||||
*
|
||||
* The code and results can be found here: -
|
||||
* https://github.com/benjchristensen/JavaLockPerformanceTests/tree/master/results/Observer
|
||||
* -
|
||||
* https://github.com/benjchristensen/JavaLockPerformanceTests/tree/master/src/com/benjchristensen/performance/locks/Observer
|
||||
*
|
||||
* The major characteristic that made me choose synchronized instead of
|
||||
* Reentrant or a customer AbstractQueueSynchronizer implementation is that
|
||||
* intrinsic locking performed better when nested, and AtomicObserver will
|
||||
* end up nested most of the time since Rx is compositional by its very
|
||||
* nature.
|
||||
*
|
||||
* // TODO composing of this class should rarely happen now with updated
|
||||
* design so this decision should be revisited
|
||||
*/
|
||||
|
||||
private final Observer<T> observer;
|
||||
private final AtomicObservableSubscription subscription;
|
||||
private volatile boolean finishRequested = false;
|
||||
@@ -57,32 +64,28 @@ public final class SynchronizedObserver<T> implements Observer<T> {
|
||||
|
||||
@Override
|
||||
public void onNext(T arg) {
|
||||
if (finished || finishRequested || subscription.isUnsubscribed()) {
|
||||
if (finished || finishRequested || subscription.isUnsubscribed())
|
||||
// if we're already stopped, or a finish request has been received, we won't allow further onNext requests
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
// check again since this could have changed while waiting
|
||||
if (finished || finishRequested || subscription.isUnsubscribed()) {
|
||||
if (finished || finishRequested || subscription.isUnsubscribed())
|
||||
// if we're already stopped, or a finish request has been received, we won't allow further onNext requests
|
||||
return;
|
||||
}
|
||||
observer.onNext(arg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
if (finished || subscription.isUnsubscribed()) {
|
||||
if (finished || subscription.isUnsubscribed())
|
||||
// another thread has already finished us, so we won't proceed
|
||||
return;
|
||||
}
|
||||
finishRequested = true;
|
||||
synchronized (this) {
|
||||
// check again since this could have changed while waiting
|
||||
if (finished || subscription.isUnsubscribed()) {
|
||||
if (finished || subscription.isUnsubscribed())
|
||||
return;
|
||||
}
|
||||
observer.onError(e);
|
||||
finished = true;
|
||||
}
|
||||
@@ -90,19 +93,17 @@ public final class SynchronizedObserver<T> implements Observer<T> {
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
if (finished || subscription.isUnsubscribed()) {
|
||||
if (finished || subscription.isUnsubscribed())
|
||||
// another thread has already finished us, so we won't proceed
|
||||
return;
|
||||
}
|
||||
finishRequested = true;
|
||||
synchronized (this) {
|
||||
// check again since this could have changed while waiting
|
||||
if (finished || subscription.isUnsubscribed()) {
|
||||
if (finished || subscription.isUnsubscribed())
|
||||
return;
|
||||
}
|
||||
observer.onCompleted();
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Action0 extends Function {
|
||||
|
||||
public void call();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Action1<T1> extends Function {
|
||||
|
||||
public void call(T1 t1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Action2<T1, T2> extends Function {
|
||||
|
||||
public void call(T1 t1, T2 t2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Action3<T1, T2, T3> extends Function {
|
||||
|
||||
public void call(T1 t1, T2 t2, T3 t3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Func0<R> extends Function {
|
||||
|
||||
public R call();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Func1<T1, R> extends Function {
|
||||
|
||||
public R call(T1 t1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Func2<T1, T2, R> extends Function {
|
||||
|
||||
public R call(T1 t1, T2 t2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Func3<T1, T2, T3, R> extends Function {
|
||||
|
||||
public R call(T1 t1, T2 t2, T3 t3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Func4<T1, T2, T3, T4, R> extends Function {
|
||||
|
||||
public R call(T1 t1, T2 t2, T3 t3, T4 t4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Func5<T1, T2, T3, T4, T5, R> extends Function {
|
||||
|
||||
public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Func6<T1, T2, T3, T4, T5, T6, R> extends Function {
|
||||
|
||||
public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Func7<T1, T2, T3, T4, T5, T6, T7, R> extends Function {
|
||||
|
||||
public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Func8<T1, T2, T3, T4, T5, T6, T7, T8, R> extends Function {
|
||||
|
||||
public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface Func9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> extends Function {
|
||||
|
||||
public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -16,5 +16,6 @@
|
||||
package rx.util.functions;
|
||||
|
||||
public interface FuncN<R> extends Function {
|
||||
|
||||
public R call(Object... args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* 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.
|
||||
@@ -19,9 +19,10 @@ public interface FunctionLanguageAdaptor {
|
||||
|
||||
/**
|
||||
* Invoke the function and return the results.
|
||||
*
|
||||
*
|
||||
* @param function
|
||||
* @param args
|
||||
*
|
||||
* @return Object results from function execution
|
||||
*/
|
||||
Object call(Object function, Object[] args);
|
||||
@@ -32,7 +33,7 @@ public interface FunctionLanguageAdaptor {
|
||||
* Example: groovy.lang.Closure
|
||||
* <p>
|
||||
* This should not return classes of java.* packages.
|
||||
*
|
||||
*
|
||||
* @return Class[] of classes that this adaptor should be invoked for.
|
||||
*/
|
||||
public Class<?>[] getFunctionClass();
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
* Copyright 2013 Netflix, Inc.
|
||||
* <p>
|
||||
* 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
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.
|
||||
* 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.functions;
|
||||
|
||||
@@ -74,16 +74,20 @@ public class Functions {
|
||||
*
|
||||
* @param function
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes"})
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public static FuncN from(final Object function) {
|
||||
if (function == null)
|
||||
throw new RuntimeException("function is null. Can't send arguments to null function.");
|
||||
|
||||
/* check for typed Rx Function implementation first */
|
||||
/*
|
||||
* check for typed Rx Function implementation first
|
||||
*/
|
||||
if (function instanceof Function)
|
||||
return fromFunction((Function) function);
|
||||
else
|
||||
/* not an Rx Function so try language adaptors */
|
||||
/*
|
||||
* not an Rx Function so try language adaptors
|
||||
*/
|
||||
|
||||
// check for language adaptor
|
||||
for (final Class c : languageAdaptors.keySet())
|
||||
@@ -107,7 +111,7 @@ public class Functions {
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// private static <R> R executionRxFunction(Function function, Object... args) {
|
||||
// // check Func* classes
|
||||
// // check Func* classes
|
||||
// if (function instanceof Func0) {
|
||||
// Func0<R> f = (Func0<R>) function;
|
||||
// if (args.length != 0) {
|
||||
@@ -203,9 +207,9 @@ public class Functions {
|
||||
//
|
||||
// throw new RuntimeException("Unknown implementation of Function: " + function.getClass().getSimpleName());
|
||||
// }
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private static FuncN fromFunction(Function function) {
|
||||
// check Func* classes
|
||||
// check Func* classes
|
||||
if (function instanceof Func0)
|
||||
return fromFunc((Func0) function);
|
||||
else if (function instanceof Func1)
|
||||
@@ -245,6 +249,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <R> FuncN<R> fromFunc(final Func0<R> f) {
|
||||
@@ -260,6 +265,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, R> FuncN<R> fromFunc(final Func1<T0, R> f) {
|
||||
@@ -275,6 +281,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, T1, R> FuncN<R> fromFunc(final Func2<T0, T1, R> f) {
|
||||
@@ -290,6 +297,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, T1, T2, R> FuncN<R> fromFunc(final Func3<T0, T1, T2, R> f) {
|
||||
@@ -305,6 +313,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, T1, T2, T3, R> FuncN<R> fromFunc(final Func4<T0, T1, T2, T3, R> f) {
|
||||
@@ -320,6 +329,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, T1, T2, T3, T4, R> FuncN<R> fromFunc(final Func5<T0, T1, T2, T3, T4, R> f) {
|
||||
@@ -335,6 +345,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, T1, T2, T3, T4, T5, R> FuncN<R> fromFunc(final Func6<T0, T1, T2, T3, T4, T5, R> f) {
|
||||
@@ -350,6 +361,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, T1, T2, T3, T4, T5, T6, R> FuncN<R> fromFunc(final Func7<T0, T1, T2, T3, T4, T5, T6, R> f) {
|
||||
@@ -365,6 +377,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, T1, T2, T3, T4, T5, T6, T7, R> FuncN<R> fromFunc(final Func8<T0, T1, T2, T3, T4, T5, T6, T7, R> f) {
|
||||
@@ -380,6 +393,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, T1, T2, T3, T4, T5, T6, T7, T8, R> FuncN<R> fromFunc(final Func9<T0, T1, T2, T3, T4, T5, T6, T7, T8, R> f) {
|
||||
@@ -395,6 +409,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static FuncN<Void> fromAction(final Action0 f) {
|
||||
@@ -411,6 +426,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0> FuncN<Void> fromAction(final Action1<T0> f) {
|
||||
@@ -427,6 +443,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, T1> FuncN<Void> fromAction(final Action2<T0, T1> f) {
|
||||
@@ -443,6 +460,7 @@ public class Functions {
|
||||
* with different arities.
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return {@link FuncN}
|
||||
*/
|
||||
public static <T0, T1, T2> FuncN<Void> fromAction(final Action3<T0, T1, T2> f) {
|
||||
|
||||
Reference in New Issue
Block a user