-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
867df14
commit 4154c0f
Showing
6 changed files
with
152 additions
and
143 deletions.
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
rxjava-core/src/main/java/rx/operators/OnSubscribeRange.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,44 @@ | ||
/** | ||
* 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.OnSubscribe; | ||
import rx.Subscriber; | ||
|
||
/** | ||
*/ | ||
public final class OnSubscribeRange implements OnSubscribe<Integer> { | ||
|
||
private final int start; | ||
private final int end; | ||
|
||
public OnSubscribeRange(int start, int end) { | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
@Override | ||
public void call(Subscriber<? super Integer> o) { | ||
for (int i = start; i < end; i++) { | ||
if (o.isUnsubscribed()) { | ||
return; | ||
} | ||
o.onNext(i); | ||
} | ||
o.onCompleted(); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
rxjava-core/src/perf/java/rx/operators/OperatorRangePerformance.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,59 @@ | ||
package rx.operators; | ||
|
||
import rx.Observable; | ||
import rx.perf.AbstractPerformanceTester; | ||
import rx.perf.IntegerSumObserver; | ||
import rx.util.functions.Action0; | ||
|
||
public class OperatorRangePerformance extends AbstractPerformanceTester { | ||
|
||
static int reps = Integer.MAX_VALUE / 8; | ||
|
||
OperatorRangePerformance() { | ||
super(reps); | ||
} | ||
|
||
public static void main(String args[]) { | ||
|
||
final OperatorRangePerformance spt = new OperatorRangePerformance(); | ||
try { | ||
spt.runTest(new Action0() { | ||
|
||
@Override | ||
public void call() { | ||
spt.timeRange(); | ||
} | ||
}); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* | ||
* -- 0.17 | ||
* | ||
* Run: 10 - 271,147,198 ops/sec | ||
* Run: 11 - 274,821,481 ops/sec | ||
* Run: 12 - 271,632,295 ops/sec | ||
* Run: 13 - 277,876,014 ops/sec | ||
* Run: 14 - 274,821,763 ops/sec | ||
* | ||
* -- 0.16.1 | ||
* | ||
* Run: 10 - 222,104,280 ops/sec | ||
* Run: 11 - 224,311,761 ops/sec | ||
* Run: 12 - 222,999,339 ops/sec | ||
* Run: 13 - 222,344,174 ops/sec | ||
* Run: 14 - 225,247,983 ops/sec | ||
* | ||
* @return | ||
*/ | ||
public long timeRange() { | ||
IntegerSumObserver o = new IntegerSumObserver(); | ||
Observable.range(1, reps).subscribe(o); | ||
return o.sum; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
rxjava-core/src/test/java/rx/operators/OnSubscribeRangeTest.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,40 @@ | ||
/** | ||
* 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 static org.mockito.Mockito.*; | ||
|
||
import org.junit.Test; | ||
|
||
import rx.Observable; | ||
import rx.Observer; | ||
|
||
public class OnSubscribeRangeTest { | ||
|
||
@Test | ||
public void testRangeStartAt2Count3() { | ||
@SuppressWarnings("unchecked") | ||
Observer<Integer> observer = mock(Observer.class); | ||
Observable.range(2, 3).subscribe(observer); | ||
|
||
verify(observer, times(1)).onNext(2); | ||
verify(observer, times(1)).onNext(3); | ||
verify(observer, times(1)).onNext(4); | ||
verify(observer, never()).onNext(5); | ||
verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); | ||
verify(observer, times(1)).onCompleted(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.