Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rxjava-core/src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import rx.observers.SafeSubscriber;
import rx.operators.OnSubscribeFromIterable;
import rx.operators.OnSubscribeRange;
import rx.operators.OperationAll;
import rx.operators.OperatorAll;
import rx.operators.OperationAny;
import rx.operators.OperationAsObservable;
import rx.operators.OperationBuffer;
Expand Down Expand Up @@ -2941,7 +2941,7 @@ public final static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Observable<R> zip(Ob
* @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#wiki-all">RxJava Wiki: all()</a>
*/
public final Observable<Boolean> all(Func1<? super T, Boolean> predicate) {
return create(OperationAll.all(this, predicate));
return lift(new OperatorAll<T>(predicate));
}

/**
Expand Down
90 changes: 0 additions & 90 deletions rxjava-core/src/main/java/rx/operators/OperationAll.java

This file was deleted.

66 changes: 66 additions & 0 deletions rxjava-core/src/main/java/rx/operators/OperatorAll.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright 2014 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.operators;

import rx.Observable.Operator;
import rx.Subscriber;
import rx.functions.Func1;

/**
* Returns an Observable that emits a Boolean that indicates whether all items emitted by an
* Observable satisfy a condition.
* <p>
* <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/all.png">
*/
public final class OperatorAll<T> implements Operator<Boolean, T> {
private final Func1<? super T, Boolean> predicate;

public OperatorAll(Func1<? super T, Boolean> predicate) {
this.predicate = predicate;
}

@Override
public Subscriber<? super T> call(final Subscriber<? super Boolean> child) {
return new Subscriber<T>(child) {
boolean done;

@Override
public void onNext(T t) {
boolean result = predicate.call(t);
if (!result && !done) {
done = true;
child.onNext(false);
child.onCompleted();
unsubscribe();
}
}

@Override
public void onError(Throwable e) {
child.onError(e);
}

@Override
public void onCompleted() {
if (!done) {
done = true;
child.onNext(true);
child.onCompleted();
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static rx.operators.OperationAll.all;

import org.junit.Test;

import rx.Observable;
import rx.Observer;
import rx.functions.Func1;

public class OperationAllTest {
public class OperatorAllTest {

@Test
@SuppressWarnings("unchecked")
public void testAll() {
Observable<String> obs = Observable.from("one", "two", "six");

Observer<Boolean> observer = mock(Observer.class);
Observable.create(all(obs, new Func1<String, Boolean>() {
obs.all(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
return s.length() == 3;
}
})).subscribe(observer);
}).subscribe(observer);

verify(observer).onNext(true);
verify(observer).onCompleted();
Expand All @@ -52,12 +51,12 @@ public void testNotAll() {
Observable<String> obs = Observable.from("one", "two", "three", "six");

Observer<Boolean> observer = mock(Observer.class);
Observable.create(all(obs, new Func1<String, Boolean>() {
obs.all(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
return s.length() == 3;
}
})).subscribe(observer);
}).subscribe(observer);

verify(observer).onNext(false);
verify(observer).onCompleted();
Expand All @@ -70,12 +69,12 @@ public void testEmpty() {
Observable<String> obs = Observable.empty();

Observer<Boolean> observer = mock(Observer.class);
Observable.create(all(obs, new Func1<String, Boolean>() {
obs.all(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
return s.length() == 3;
}
})).subscribe(observer);
}).subscribe(observer);

verify(observer).onNext(true);
verify(observer).onCompleted();
Expand All @@ -89,12 +88,12 @@ public void testError() {
Observable<String> obs = Observable.error(error);

Observer<Boolean> observer = mock(Observer.class);
Observable.create(all(obs, new Func1<String, Boolean>() {
obs.all(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
return s.length() == 3;
}
})).subscribe(observer);
}).subscribe(observer);

verify(observer).onError(error);
verifyNoMoreInteractions(observer);
Expand Down