From 7d0487ac9ce46551772d501bbec2283adee8b008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Karnok?= Date: Wed, 14 Sep 2016 23:46:10 +0200 Subject: [PATCH] Don't depend on RxJava 1 anymore, some cleanup --- .idea/compiler.xml | 27 + .idea/copyright/profiles_settings.xml | 3 + .idea/dictionaries/akarnokd.xml | 8 + .idea/gradle.xml | 17 + .idea/inspectionProfiles/Project_Default.xml | 14 + .../inspectionProfiles/profiles_settings.xml | 7 + .idea/libraries/Gradle__junit_junit_4_12.xml | 11 + ...le__net_sf_jopt_simple_jopt_simple_4_6.xml | 11 + ...__org_apache_commons_commons_math3_3_2.xml | 11 + ...Gradle__org_hamcrest_hamcrest_core_1_3.xml | 11 + .../Gradle__org_openjdk_jmh_jmh_core_1_14.xml | 11 + ...njdk_jmh_jmh_generator_annprocess_1_14.xml | 11 + .idea/misc.xml | 19 + .idea/modules.xml | 11 + .idea/modules/ixjava.iml | 12 + .idea/modules/ixjava_jmh.iml | 18 + .idea/modules/ixjava_main.iml | 13 + .idea/modules/ixjava_test.iml | 17 + .idea/workspace.xml | 1719 +++++++++++++++++ README.md | 2 +- build.gradle | 4 +- src/jmh/java/ix/FlattenIterableArrayPerf.java | 26 +- src/jmh/java/ix/FlattenIterablePerf.java | 24 +- src/jmh/java/ix/IxPerf.java | 4 +- src/jmh/java/ix/RangePerf.java | 24 +- src/jmh/java/ix/ReducePerf.java | 6 +- src/main/java/ix/EqualityHelper.java | 4 +- src/main/java/ix/GroupedIx.java | 4 +- src/main/java/ix/IdentityHelper.java | 14 +- src/main/java/ix/Ix.java | 519 +++-- src/main/java/ix/IxAggregate.java | 24 +- src/main/java/ix/IxAll.java | 26 +- src/main/java/ix/IxAny.java | 26 +- src/main/java/ix/IxAverageDouble.java | 10 +- src/main/java/ix/IxAverageFloat.java | 10 +- src/main/java/ix/IxBaseIterator.java | 14 +- .../ix/{Pred0.java => IxBooleanSupplier.java} | 8 +- src/main/java/ix/IxBuffer.java | 20 +- src/main/java/ix/IxBufferOverlap.java | 36 +- src/main/java/ix/IxBufferSkip.java | 30 +- src/main/java/ix/IxCharacters.java | 20 +- src/main/java/ix/IxCollect.java | 32 +- src/main/java/ix/IxCompose.java | 10 +- src/main/java/ix/IxConsumer.java | 29 + src/main/java/ix/IxConsumer2.java | 31 + src/main/java/ix/IxContains.java | 14 +- src/main/java/ix/IxCount.java | 10 +- src/main/java/ix/IxCountLong.java | 10 +- src/main/java/ix/IxDefer.java | 12 +- src/main/java/ix/IxDistinct.java | 26 +- src/main/java/ix/IxDistinctUntilChanged.java | 54 +- src/main/java/ix/IxDoOn.java | 24 +- src/main/java/ix/IxEmitter.java | 36 + src/main/java/ix/IxEmpty.java | 6 +- src/main/java/ix/IxEmptyAction.java | 18 +- src/main/java/ix/IxExcept.java | 26 +- src/main/java/ix/IxFilter.java | 14 +- src/main/java/ix/IxFlattenArrayIterable.java | 22 +- src/main/java/ix/IxFlattenIterable.java | 32 +- src/main/java/ix/IxForloop.java | 54 +- src/main/java/ix/IxFromArray.java | 8 +- src/main/java/ix/IxFunction.java | 31 + src/main/java/ix/IxFunction2.java | 33 + src/main/java/ix/IxFunction3.java | 35 + src/main/java/ix/IxFunction4.java | 37 + src/main/java/ix/IxGenerate.java | 64 +- src/main/java/ix/IxGenerateStateless.java | 44 +- src/main/java/ix/IxGroupBy.java | 72 +- src/main/java/ix/IxHasElements.java | 6 +- src/main/java/ix/IxIgnoreElements.java | 10 +- src/main/java/ix/IxIntersect.java | 16 +- src/main/java/ix/IxJoin.java | 20 +- src/main/java/ix/IxJust.java | 20 +- src/main/java/ix/IxLift.java | 10 +- src/main/java/ix/IxMap.java | 20 +- src/main/java/ix/IxMaxInt.java | 8 +- src/main/java/ix/IxMaxLong.java | 8 +- src/main/java/ix/IxMinInt.java | 8 +- src/main/java/ix/IxMinLong.java | 8 +- src/main/java/ix/IxMinMax.java | 26 +- src/main/java/ix/IxOrderBy.java | 48 +- .../java/ix/{Pred.java => IxPredicate.java} | 13 +- .../java/ix/{Pred2.java => IxPredicate2.java} | 17 +- src/main/java/ix/IxPublish.java | 4 +- src/main/java/ix/IxPublishSelector.java | 18 +- src/main/java/ix/IxRange.java | 20 +- src/main/java/ix/IxReduce.java | 32 +- src/main/java/ix/IxRemove.java | 18 +- src/main/java/ix/IxRepeat.java | 16 +- src/main/java/ix/IxRepeatCount.java | 20 +- src/main/java/ix/IxRepeatPredicate.java | 26 +- src/main/java/ix/IxReplay.java | 20 +- src/main/java/ix/IxReplaySelector.java | 12 +- src/main/java/ix/IxReplaySize.java | 38 +- src/main/java/ix/IxReplaySizeSelector.java | 16 +- src/main/java/ix/IxRetain.java | 18 +- src/main/java/ix/IxReverse.java | 14 +- src/main/java/ix/IxScan.java | 30 +- src/main/java/ix/IxScanSeed.java | 34 +- src/main/java/ix/IxSequenceEqual.java | 40 +- src/main/java/ix/IxSkip.java | 13 +- src/main/java/ix/IxSkipLast.java | 20 +- src/main/java/ix/IxSkipWhile.java | 26 +- src/main/java/ix/IxSource.java | 8 +- src/main/java/ix/IxSourceIterator.java | 2 +- src/main/java/ix/IxSourceQueuedIterator.java | 40 +- src/main/java/ix/IxSplit.java | 14 +- src/main/java/ix/IxSumInt.java | 8 +- src/main/java/ix/IxSumLong.java | 8 +- src/main/java/ix/IxSupplier.java | 29 + src/main/java/ix/IxSwitchIfEmpty.java | 10 +- src/main/java/ix/IxTake.java | 17 +- src/main/java/ix/IxTakeLast.java | 14 +- src/main/java/ix/IxTakeUntil.java | 14 +- src/main/java/ix/IxTakeWhile.java | 14 +- src/main/java/ix/IxToMap.java | 44 +- src/main/java/ix/IxToMultimap.java | 46 +- src/main/java/ix/IxToSet.java | 12 +- src/main/java/ix/IxTransform.java | 10 +- src/main/java/ix/IxTransformer.java | 18 +- src/main/java/ix/IxUnion.java | 20 +- src/main/java/ix/IxWindow.java | 52 +- src/main/java/ix/IxWindowOverlap.java | 68 +- src/main/java/ix/IxWindowSkip.java | 62 +- src/main/java/ix/IxWrapper.java | 4 +- src/main/java/ix/IxZip2.java | 26 +- src/main/java/ix/IxZip3.java | 28 +- src/main/java/ix/IxZip4.java | 28 +- src/main/java/ix/IxZipArray.java | 48 +- src/main/java/ix/IxZipIterable.java | 23 +- src/main/java/ix/NumberToLongHelper.java | 8 +- src/main/java/ix/SelfComparator.java | 2 +- src/main/java/ix/ToListHelper.java | 24 +- src/test/java/ix/AggregateTest.java | 14 +- src/test/java/ix/AnyAllTest.java | 40 +- src/test/java/ix/AsComposeTest.java | 22 +- src/test/java/ix/AverageTest.java | 26 +- src/test/java/ix/BufferTest.java | 94 +- src/test/java/ix/CharactersTest.java | 26 +- src/test/java/ix/CollectTest.java | 16 +- src/test/java/ix/ConcatArrayTest.java | 54 +- src/test/java/ix/ContainsTest.java | 40 +- src/test/java/ix/CountTest.java | 28 +- src/test/java/ix/DeferTest.java | 8 +- src/test/java/ix/DistinctTest.java | 16 +- .../java/ix/DistinctUntilChangedTest.java | 30 +- src/test/java/ix/DoOnTest.java | 20 +- src/test/java/ix/EmptyActionTest.java | 6 +- src/test/java/ix/EmptyTest.java | 10 +- src/test/java/ix/EqualityHelperTest.java | 10 +- src/test/java/ix/ExceptTest.java | 36 +- src/test/java/ix/FilterTest.java | 20 +- src/test/java/ix/FirstTest.java | 14 +- src/test/java/ix/FlattenIterableTest.java | 42 +- src/test/java/ix/ForeachTest.java | 28 +- src/test/java/ix/ForloopTest.java | 32 +- src/test/java/ix/FromArrayTest.java | 22 +- src/test/java/ix/FromTest.java | 8 +- src/test/java/ix/GenerateStatelessTest.java | 53 +- src/test/java/ix/GenerateTest.java | 80 +- src/test/java/ix/GroupByTest.java | 150 +- src/test/java/ix/HasElementsTest.java | 4 +- src/test/java/ix/HelperTest.java | 4 +- src/test/java/ix/HideTest.java | 2 +- src/test/java/ix/IgnoreElementsTest.java | 8 +- src/test/java/ix/IntersectTest.java | 24 +- .../ix/IxOperatorsArePackageFinalTest.java | 65 + src/test/java/ix/IxTest.java | 20 +- src/test/java/ix/IxTestHelper.java | 28 +- src/test/java/ix/JoinTest.java | 24 +- src/test/java/ix/JustTest.java | 4 +- src/test/java/ix/LastTest.java | 14 +- src/test/java/ix/LeavingTest.java | 280 +-- src/test/java/ix/LiftTest.java | 14 +- src/test/java/ix/MapTest.java | 18 +- src/test/java/ix/MaxTest.java | 12 +- src/test/java/ix/MinMaxTest.java | 34 +- src/test/java/ix/MinTest.java | 12 +- src/test/java/ix/OrderByTest.java | 44 +- src/test/java/ix/PublishTest.java | 38 +- src/test/java/ix/RangeTest.java | 16 +- src/test/java/ix/ReduceTest.java | 32 +- src/test/java/ix/RemoveRetainTest.java | 72 +- src/test/java/ix/RepeatTest.java | 102 +- src/test/java/ix/ReplayTest.java | 86 +- src/test/java/ix/ReverseTest.java | 8 +- src/test/java/ix/ScanTest.java | 72 +- src/test/java/ix/SelfComparatorTest.java | 10 +- src/test/java/ix/SequenceEqualTest.java | 16 +- src/test/java/ix/SkipLastTest.java | 18 +- src/test/java/ix/SkipTest.java | 10 +- src/test/java/ix/SkipWhileTest.java | 18 +- .../java/ix/SourceQueuedIteratorTest.java | 34 +- src/test/java/ix/SplitTest.java | 28 +- src/test/java/ix/SumTest.java | 12 +- src/test/java/ix/SwitchIfEmptyTest.java | 22 +- src/test/java/ix/TakeLastTest.java | 18 +- src/test/java/ix/TakeTest.java | 18 +- src/test/java/ix/TakeUntilTest.java | 18 +- src/test/java/ix/TakeWhileTest.java | 18 +- src/test/java/ix/ToArrayTest.java | 2 +- src/test/java/ix/ToListTest.java | 7 +- src/test/java/ix/ToMapTest.java | 64 +- src/test/java/ix/ToSetTest.java | 14 +- src/test/java/ix/ToXTest.java | 50 +- src/test/java/ix/TransformTest.java | 40 +- src/test/java/ix/UnionTest.java | 46 +- src/test/java/ix/WindowTest.java | 106 +- src/test/java/ix/Zip2Test.java | 38 +- src/test/java/ix/Zip3Test.java | 40 +- src/test/java/ix/Zip4Test.java | 46 +- src/test/java/ix/ZipArrayTest.java | 40 +- src/test/java/ix/ZipIterableTest.java | 50 +- 213 files changed, 4826 insertions(+), 2903 deletions(-) create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/dictionaries/akarnokd.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/libraries/Gradle__junit_junit_4_12.xml create mode 100644 .idea/libraries/Gradle__net_sf_jopt_simple_jopt_simple_4_6.xml create mode 100644 .idea/libraries/Gradle__org_apache_commons_commons_math3_3_2.xml create mode 100644 .idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 .idea/libraries/Gradle__org_openjdk_jmh_jmh_core_1_14.xml create mode 100644 .idea/libraries/Gradle__org_openjdk_jmh_jmh_generator_annprocess_1_14.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/modules/ixjava.iml create mode 100644 .idea/modules/ixjava_jmh.iml create mode 100644 .idea/modules/ixjava_main.iml create mode 100644 .idea/modules/ixjava_test.iml create mode 100644 .idea/workspace.xml rename src/main/java/ix/{Pred0.java => IxBooleanSupplier.java} (78%) create mode 100644 src/main/java/ix/IxConsumer.java create mode 100644 src/main/java/ix/IxConsumer2.java create mode 100644 src/main/java/ix/IxEmitter.java create mode 100644 src/main/java/ix/IxFunction.java create mode 100644 src/main/java/ix/IxFunction2.java create mode 100644 src/main/java/ix/IxFunction3.java create mode 100644 src/main/java/ix/IxFunction4.java rename src/main/java/ix/{Pred.java => IxPredicate.java} (70%) rename src/main/java/ix/{Pred2.java => IxPredicate2.java} (64%) create mode 100644 src/main/java/ix/IxSupplier.java create mode 100644 src/test/java/ix/IxOperatorsArePackageFinalTest.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..8cbd3f4 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/dictionaries/akarnokd.xml b/.idea/dictionaries/akarnokd.xml new file mode 100644 index 0000000..0e1ac72 --- /dev/null +++ b/.idea/dictionaries/akarnokd.xml @@ -0,0 +1,8 @@ + + + + forloop + karnok + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..77e9972 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..fd947e6 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..3b31283 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__junit_junit_4_12.xml b/.idea/libraries/Gradle__junit_junit_4_12.xml new file mode 100644 index 0000000..04c10dd --- /dev/null +++ b/.idea/libraries/Gradle__junit_junit_4_12.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__net_sf_jopt_simple_jopt_simple_4_6.xml b/.idea/libraries/Gradle__net_sf_jopt_simple_jopt_simple_4_6.xml new file mode 100644 index 0000000..d1405f7 --- /dev/null +++ b/.idea/libraries/Gradle__net_sf_jopt_simple_jopt_simple_4_6.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_apache_commons_commons_math3_3_2.xml b/.idea/libraries/Gradle__org_apache_commons_commons_math3_3_2.xml new file mode 100644 index 0000000..75cc803 --- /dev/null +++ b/.idea/libraries/Gradle__org_apache_commons_commons_math3_3_2.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..8262f72 --- /dev/null +++ b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_openjdk_jmh_jmh_core_1_14.xml b/.idea/libraries/Gradle__org_openjdk_jmh_jmh_core_1_14.xml new file mode 100644 index 0000000..47c0ab7 --- /dev/null +++ b/.idea/libraries/Gradle__org_openjdk_jmh_jmh_core_1_14.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_openjdk_jmh_jmh_generator_annprocess_1_14.xml b/.idea/libraries/Gradle__org_openjdk_jmh_jmh_generator_annprocess_1_14.xml new file mode 100644 index 0000000..e8189c8 --- /dev/null +++ b/.idea/libraries/Gradle__org_openjdk_jmh_jmh_generator_annprocess_1_14.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b29bc37 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..63705b8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/ixjava.iml b/.idea/modules/ixjava.iml new file mode 100644 index 0000000..fac74e1 --- /dev/null +++ b/.idea/modules/ixjava.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/ixjava_jmh.iml b/.idea/modules/ixjava_jmh.iml new file mode 100644 index 0000000..30f5371 --- /dev/null +++ b/.idea/modules/ixjava_jmh.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/ixjava_main.iml b/.idea/modules/ixjava_main.iml new file mode 100644 index 0000000..29a46d3 --- /dev/null +++ b/.idea/modules/ixjava_main.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/ixjava_test.iml b/.idea/modules/ixjava_test.iml new file mode 100644 index 0000000..7ec8692 --- /dev/null +++ b/.idea/modules/ixjava_test.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..8e90062 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,1719 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1473888618399 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + ixjava + + + + + + + + 1.8 + + + + + + + + Gradle: junit:junit:4.12 + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 4e60710..f9db33f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ixjava [![codecov.io](http://codecov.io/github/akarnokd/ixjava/coverage.svg?branch=1.x)](http://codecov.io/github/akarnokd/ixjava?branch=1.x) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.akarnokd/ixjava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.akarnokd/ixjava) -Interactive Extensions for Java, the dual of RxJava. Originally implemented in the Reactive4Java framework, now converted to work with RxJava. +Iterable Extensions for Java, the dual of RxJava. Originally implemented in the Reactive4Java framework, now converted to work with RxJava. The aim is to provide, lazily evaluated, pull-based datastream support with the same naming as in RxJava mainly for the pre-Java-8 world. The Stream API in Java 8 is not exactly the same thing because Streams can be only consumed once while `Iterable`s can be consumed many times. Google Guava features a lot of Iterable operators, plus now they have the `FluentIterable` with similar setup but far less operators available (and as of v19, their performance is 2x worse than Ix'). diff --git a/build.gradle b/build.gradle index 11a0e1e..e17625a 100644 --- a/build.gradle +++ b/build.gradle @@ -44,8 +44,6 @@ apply plugin: 'osgi' dependencies { signature 'org.codehaus.mojo.signature:java16:1.1@signature' - compile "io.reactivex:rxjava:1.1.9" - testCompile group: 'junit', name: 'junit', version: '4.12' } @@ -89,7 +87,7 @@ publishing { } jmh { - jmhVersion = '1.13' + jmhVersion = '1.14' humanOutputFile = null if (project.hasProperty('jmh')) { include = ".*" + project.jmh + ".*" diff --git a/src/jmh/java/ix/FlattenIterableArrayPerf.java b/src/jmh/java/ix/FlattenIterableArrayPerf.java index 1c997c8..e58efff 100644 --- a/src/jmh/java/ix/FlattenIterableArrayPerf.java +++ b/src/jmh/java/ix/FlattenIterableArrayPerf.java @@ -22,8 +22,6 @@ import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; -import rx.functions.Func1; - /** * Example benchmark. Run from command line as *
@@ -35,45 +33,45 @@ @OutputTimeUnit(TimeUnit.SECONDS) @Fork(value = 1) @State(Scope.Thread) -public class FlattenIterableArrayPerf implements Func1> { +public class FlattenIterableArrayPerf implements IxFunction> { @Param({"1", "10", "100", "1000", "10000", "100000", "1000000"}) public int count; - + Ix source; - + Ix inner; Ix flatMapJust; @Override - public Iterable call(Integer t) { + public Iterable apply(Integer t) { return inner; } - + @Setup public void setup(Blackhole bh) { int d = 1000000 / count; - + Integer[] countArray = new Integer[count]; Arrays.fill(countArray, 777); - + inner = Ix.fromArray(countArray); Integer[] sourceArray = new Integer[d]; Arrays.fill(sourceArray, 777); - + source = Ix.fromArray(sourceArray).flatMap(this); - - flatMapJust = inner.flatMap(new Func1>() { + + flatMapJust = inner.flatMap(new IxFunction>() { @Override - public Iterable call(Integer v) { + public Iterable apply(Integer v) { return Ix.just(v); } }); } - + @Benchmark public Object xrangeLast() { return source.last(); diff --git a/src/jmh/java/ix/FlattenIterablePerf.java b/src/jmh/java/ix/FlattenIterablePerf.java index 5fa5275..cbc4cf9 100644 --- a/src/jmh/java/ix/FlattenIterablePerf.java +++ b/src/jmh/java/ix/FlattenIterablePerf.java @@ -21,8 +21,6 @@ import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; -import rx.functions.Func1; - /** * Example benchmark. Run from command line as *
@@ -34,39 +32,39 @@ @OutputTimeUnit(TimeUnit.SECONDS) @Fork(value = 1) @State(Scope.Thread) -public class FlattenIterablePerf implements Func1> { +public class FlattenIterablePerf implements IxFunction> { @Param({"1", "10", "100", "1000", "10000", "100000", "1000000"}) public int count; - + Ix source; - + Ix inner; Ix flatMapJust; @Override - public Iterable call(Integer t) { + public Iterable apply(Integer t) { return inner; } - + @Setup public void setup(Blackhole bh) { int d = 1000000 / count; - + inner = Ix.range(1, count); - + source = Ix.range(1, d).flatMap(this); - - flatMapJust = Ix.range(1, count).flatMap(new Func1>() { + + flatMapJust = Ix.range(1, count).flatMap(new IxFunction>() { @Override - public Iterable call(Integer v) { + public Iterable apply(Integer v) { return Ix.just(v); } }); } - + @Benchmark public Object xrangeLast() { return source.last(); diff --git a/src/jmh/java/ix/IxPerf.java b/src/jmh/java/ix/IxPerf.java index 0efd963..a15b697 100644 --- a/src/jmh/java/ix/IxPerf.java +++ b/src/jmh/java/ix/IxPerf.java @@ -36,12 +36,12 @@ public class IxPerf { // @Param({"1", "10", "100", "1000", "10000", "100000", "1000000"}) // public int count; - + @Setup public void setup(Blackhole bh) { } - + @Benchmark public Object just() { return new IxJust(1).iterator().next(); diff --git a/src/jmh/java/ix/RangePerf.java b/src/jmh/java/ix/RangePerf.java index 7eb7ee2..985d01a 100644 --- a/src/jmh/java/ix/RangePerf.java +++ b/src/jmh/java/ix/RangePerf.java @@ -21,8 +21,6 @@ import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; -import rx.functions.Func1; - /** * Example benchmark. Run from command line as *
@@ -34,39 +32,39 @@ @OutputTimeUnit(TimeUnit.SECONDS) @Fork(value = 1) @State(Scope.Thread) -public class RangePerf implements Func1> { +public class RangePerf implements IxFunction> { @Param({"1", "10", "100", "1000", "10000", "100000", "1000000"}) public int count; - + Ix source; - + Ix inner; Ix flatMapJust; @Override - public Iterable call(Integer t) { + public Iterable apply(Integer t) { return inner; } - + @Setup public void setup(Blackhole bh) { int d = 1000000 / count; - + inner = Ix.range(1, count); - + source = Ix.range(1, d).flatMap(this); - - flatMapJust = Ix.range(1, count).flatMap(new Func1>() { + + flatMapJust = Ix.range(1, count).flatMap(new IxFunction>() { @Override - public Iterable call(Integer v) { + public Iterable apply(Integer v) { return Ix.just(v); } }); } - + @Benchmark public Object rangeLast() { return inner.last(); diff --git a/src/jmh/java/ix/ReducePerf.java b/src/jmh/java/ix/ReducePerf.java index c6efe16..40947a7 100644 --- a/src/jmh/java/ix/ReducePerf.java +++ b/src/jmh/java/ix/ReducePerf.java @@ -39,15 +39,15 @@ public class ReducePerf { public int count; Ix sum; - + @Setup public void setup(Blackhole bh) { Integer[] array = new Integer[count]; Arrays.fill(array, 1); - + sum = Ix.fromArray(array).sumInt(); } - + @Benchmark public Object sumLast() { return sum.last(); diff --git a/src/main/java/ix/EqualityHelper.java b/src/main/java/ix/EqualityHelper.java index 9d51f0a..d901495 100644 --- a/src/main/java/ix/EqualityHelper.java +++ b/src/main/java/ix/EqualityHelper.java @@ -16,9 +16,9 @@ package ix; -enum EqualityHelper implements Pred2 { +enum EqualityHelper implements IxPredicate2 { INSTANCE; - + @Override public boolean test(Object t, Object u) { return (t == u) || (t != null && t.equals(u)); diff --git a/src/main/java/ix/GroupedIx.java b/src/main/java/ix/GroupedIx.java index 18672e2..c6681fe 100644 --- a/src/main/java/ix/GroupedIx.java +++ b/src/main/java/ix/GroupedIx.java @@ -26,11 +26,11 @@ public abstract class GroupedIx extends Ix { protected final K key; - + public GroupedIx(K key) { this.key = key; } - + public final K key() { return key; } diff --git a/src/main/java/ix/IdentityHelper.java b/src/main/java/ix/IdentityHelper.java index ff5e680..f3358b9 100644 --- a/src/main/java/ix/IdentityHelper.java +++ b/src/main/java/ix/IdentityHelper.java @@ -16,19 +16,17 @@ package ix; -import rx.functions.Func1; - -enum IdentityHelper implements Func1 { +enum IdentityHelper implements IxFunction { INSTANCE ; - + @SuppressWarnings("unchecked") - public static Func1 instance() { - return (Func1)INSTANCE; + public static IxFunction instance() { + return (IxFunction)INSTANCE; } - + @Override - public Object call(Object t) { + public Object apply(Object t) { return t; } } \ No newline at end of file diff --git a/src/main/java/ix/Ix.java b/src/main/java/ix/Ix.java index 718a11a..46432ca 100644 --- a/src/main/java/ix/Ix.java +++ b/src/main/java/ix/Ix.java @@ -19,11 +19,6 @@ import java.util.*; import java.util.concurrent.Callable; -import rx.Observer; -import rx.Subscriber; -import rx.exceptions.Exceptions; -import rx.functions.*; - /** * Base class and entry point for fluent Iterables. *

@@ -48,7 +43,7 @@ public abstract class Ix implements Iterable { public static Ix characters(CharSequence cs) { return new IxCharacters(cs, 0, cs.length()); } - + /** * Emits a range of characters from the given CharSequence as integer values. *

@@ -85,7 +80,7 @@ public static Ix characters(CharSequence cs, int start, int end) { @SuppressWarnings({ "unchecked", "rawtypes" }) public static Ix concat(Iterable> sources) { return new IxFlattenIterable, T>( - (Iterable)nullCheck(sources, "sources is null"), + (Iterable)nullCheck(sources, "sources is null"), IdentityHelper.>instance()); } @@ -124,7 +119,7 @@ public static Ix concat(Iterable source1, Iterable Ix concat(Iterable source1, Iterable source2, Iterable source3) { - return concatArray(nullCheck(source1, "source1 is null"), + return concatArray(nullCheck(source1, "source1 is null"), nullCheck(source2, "source2 is null"), nullCheck(source3, "source3 is null")); } @@ -146,7 +141,7 @@ public static Ix concat(Iterable source1, Iterable Ix concat(Iterable source1, Iterable source2, Iterable source3, Iterable source4) { - return concatArray(nullCheck(source1, "source1 is null"), nullCheck(source2, "source2 is null"), + return concatArray(nullCheck(source1, "source1 is null"), nullCheck(source2, "source2 is null"), nullCheck(source3, "source3 is null"), nullCheck(source4, "source4 is null")); } @@ -186,10 +181,10 @@ public static Ix concatArray(Iterable... sources) { * @throws NullPointerException if factory is null * @since 1.0 */ - public static Ix defer(Func0> factory) { + public static Ix defer(IxSupplier> factory) { return new IxDefer(nullCheck(factory, "factory is null")); } - + /** * No elements are emitted. *

@@ -201,7 +196,7 @@ public static Ix defer(Func0> factory) { public static Ix empty() { return IxEmpty.instance(); } - + /** * Wraps the given Iterable source into an Ix instance (if * not already an Ix subclass). @@ -220,9 +215,9 @@ public static Ix from(Iterable source) { } return new IxWrapper(nullCheck(source, "source")); } - + /** - * Emits all the elements of the given array. + * Emits all the elements of the given array. *

* The result's iterator() doesn't support remove(). * @param the value type @@ -280,15 +275,15 @@ public static Ix fromArrayRange(int start, int end, T... values) { * @throws NullPointerException if condition, next or selector is null * @since 1.0 */ - public static Ix forloop(T seed, Pred condition, - Func1 next, - Func1 selector) { + public static Ix forloop(T seed, IxPredicate condition, + IxFunction next, + IxFunction selector) { return new IxForloop(seed, nullCheck(condition, "condition is null"), nullCheck(selector, "selector is null"), nullCheck(next, "next is null")); } /** - * Calls the given action to generate a value or terminate whenever the next() + * Calls the given action to generate a value or terminate whenever the next() * is called on the resulting Ix.iterator(). *

* The result's iterator() doesn't support remove(). @@ -296,19 +291,19 @@ public static Ix forloop(T seed, Pred condition, * The action may call {@code onNext} at most once to signal the next value per action invocation. * The {@code onCompleted} should be called to indicate no further values will be generated (may be * called with an onNext in the same action invocation). Calling {@code onError} will immediately - * throw the given exception (as is if it's a RuntimeException or Error; or wrapped into a RuntimeException). + * throw the given exception (as is if it's a RuntimeException or Error; or wrapped into a RuntimeException). * @param the value type - * @param nextSupplier the action called with an Observer API to receive value, not null + * @param nextSupplier the action called with an IxEmitter API to receive value, not null * @return the new Ix instance * @throws NullPointerException if nextSupplier is null * @since 1.0 */ - public static Ix generate(Action1> nextSupplier) { + public static Ix generate(IxConsumer> nextSupplier) { return new IxGenerateStateless(nullCheck(nextSupplier, "nextSupplier is null")); } /** - * Calls the given function (with per-iterator state) to generate a value or terminate + * Calls the given function (with per-iterator state) to generate a value or terminate * whenever the next() is called on the resulting Ix.iterator(). *

* The result's iterator() doesn't support remove(). @@ -316,21 +311,21 @@ public static Ix generate(Action1> nextSupplier) { * The action may call {@code onNext} at most once to signal the next value per action invocation. * The {@code onCompleted} should be called to indicate no further values will be generated (may be * called with an onNext in the same action invocation). Calling {@code onError} will immediately - * throw the given exception (as is if it's a RuntimeException or Error; or wrapped into a RuntimeException). + * throw the given exception (as is if it's a RuntimeException or Error; or wrapped into a RuntimeException). * @param the value type * @param the state type supplied to and returned by the nextSupplier function * @param stateSupplier the function that returns a state for each invocation of iterator() - * @param nextSupplier the action called with an Observer API to receive value, not null + * @param nextSupplier the action called with an IxEmitter API to receive value, not null * @return the new Ix instance * @throws NullPointerException if stateSupplier or nextSupplier is null * @since 1.0 */ - public static Ix generate(Func0 stateSupplier, Func2, S> nextSupplier) { + public static Ix generate(IxSupplier stateSupplier, IxFunction2, S> nextSupplier) { return generate(stateSupplier, nextSupplier, IxEmptyAction.instance1()); } /** - * Calls the given function (with per-iterator state) to generate a value or terminate + * Calls the given function (with per-iterator state) to generate a value or terminate * whenever the next() is called on the resulting Ix.iterator(). *

* The result's iterator() doesn't support remove(). @@ -341,18 +336,18 @@ public static Ix generate(Func0 stateSupplier, Func2 * throw the given exception (as is if it's a RuntimeException or Error; or wrapped into a RuntimeException). *

* Note that since there is no direct way to cancel an Iterator, the stateDisposer is only invoked - * when the nextSupplier calls a terminal method. + * when the nextSupplier calls a terminal method. * @param the value type * @param the state type supplied to and returned by the nextSupplier function * @param stateSupplier the function that returns a state for each invocation of iterator() - * @param nextSupplier the action called with an Observer API to receive value, not null + * @param nextSupplier the action called with an IxEmitter API to receive value, not null * @param stateDisposer the action called when the nextSupplier signals an {@code onError} or {@code onCompleted}. * @return the new Ix instance * @throws NullPointerException if stateSupplier, nextSupplier or stateDisposer is null * @since 1.0 */ - public static Ix generate(Func0 stateSupplier, Func2, S> nextSupplier, Action1 stateDisposer) { - return new IxGenerate(nullCheck(stateSupplier, "stateSupplier is null"), + public static Ix generate(IxSupplier stateSupplier, IxFunction2, S> nextSupplier, IxConsumer stateDisposer) { + return new IxGenerate(nullCheck(stateSupplier, "stateSupplier is null"), nullCheck(nextSupplier, "nextSupplier is null"), nullCheck(stateDisposer, "stateDisposer is null")); } @@ -385,7 +380,7 @@ public static Ix just(T value) { public static Ix merge(Iterable> sources) { return concat(sources); } - + /** * Concatenates the elements of Iterable sources, provided as an array, sequentially. *

@@ -402,7 +397,7 @@ public static Ix merge(Iterable> sources) public static Ix mergeArray(Iterable... sources) { return concatArray(sources); // concat and merge are the same in the Iterable world } - + /** * Emits a range of incrementing integer values, starting from {@code start} and * up to {@code count} times. @@ -471,7 +466,7 @@ public static Ix repeatValue(T value, long count) { * @throws NullPointerException if stopPredicate is null * @since 1.0 */ - public static Ix repeatValue(T value, Pred0 stopPredicate) { + public static Ix repeatValue(T value, IxBooleanSupplier stopPredicate) { return repeatValue(value, Long.MAX_VALUE, stopPredicate); } @@ -492,10 +487,10 @@ public static Ix repeatValue(T value, Pred0 stopPredicate) { * @throws NullPointerException if stopPredicate is null * @since 1.0 */ - public static Ix repeatValue(T value, long count, Pred0 stopPredicate) { + public static Ix repeatValue(T value, long count, IxBooleanSupplier stopPredicate) { return new IxRepeatPredicate(value, nonNegative(count, "count"), nullCheck(stopPredicate, "stopPredicate is null")); } - + /** * Emits a sequence of substring of a string split by the given separator. *

@@ -509,14 +504,14 @@ public static Ix repeatValue(T value, long count, Pred0 stopPredicate) { public static Ix split(String string, String by) { return new IxSplit(nullCheck(string, "string is null"), nullCheck(by, "by is null")); } - + /** * Combines the next element from each source Iterable via a zipper function. *

* If one of the source Iterables is sorter the sequence terminates eagerly. *

* The result's iterator() doesn't support remove(). - * + * * @param the common element type of the sources * @param the result value type * @param sources the array of Iterable sources, not null @@ -526,18 +521,18 @@ public static Ix split(String string, String by) { * @throws NullPointerException if sources or zipper is null * @since 1.0 */ - public static Ix zip(Iterable[] sources, FuncN zipper) { + public static Ix zip(Iterable[] sources, IxFunction zipper) { return new IxZipArray(nullCheck(sources, "sources is null"), nullCheck(zipper, "zipper is null")); } /** - * Combines the next element from each source Iterable, provided as an Iterable itself, + * Combines the next element from each source Iterable, provided as an Iterable itself, * via a zipper function. *

* If one of the source Iterables is sorter the sequence terminates eagerly. *

* The result's iterator() doesn't support remove(). - * + * * @param the common element type of the sources * @param the result value type * @param sources the Iterable of Iterable sources, not null @@ -547,7 +542,7 @@ public static Ix zip(Iterable[] sources, FuncN zipper) * @throws NullPointerException if sources or zipper is null * @since 1.0 */ - public static Ix zip(Iterable> sources, FuncN zipper) { + public static Ix zip(Iterable> sources, IxFunction zipper) { return new IxZipIterable(nullCheck(sources, "sources is null"), nullCheck(zipper, "zipper is null")); } @@ -557,21 +552,21 @@ public static Ix zip(Iterable> sources * If one of the source Iterables is sorter the sequence terminates eagerly. *

* The result's iterator() doesn't support remove(). - * + * * @param the first source's element type * @param the second source's element type * @param the result value type * @param source1 the first source Iterable * @param source2 the second source Iterable - * @param zipper the function that takesone from each source, not null + * @param zipper the function that takes one from each source, not null * @return the new Ix instance * @throws NullPointerException if any of the sources or zipper is null * @since 1.0 */ public static Ix zip( - Iterable source1, Iterable source2, - Func2 zipper) { - return new IxZip2(nullCheck(source1, "source1 is null"), + Iterable source1, Iterable source2, + IxFunction2 zipper) { + return new IxZip2(nullCheck(source1, "source1 is null"), nullCheck(source2, "source2 is null"), nullCheck(zipper, "zipper is null")); } @@ -581,7 +576,7 @@ public static Ix zip( * If one of the source Iterables is sorter the sequence terminates eagerly. *

* The result's iterator() doesn't support remove(). - * + * * @param the first source's element type * @param the second source's element type * @param the third source's element type @@ -589,16 +584,16 @@ public static Ix zip( * @param source1 the first source Iterable * @param source2 the second source Iterable * @param source3 the third source Iterable - * @param zipper the function that takesone from each source, not null + * @param zipper the function that takes one from each source, not null * @return the new Ix instance * @throws NullPointerException if any of the sources or zipper is null * @since 1.0 */ public static Ix zip( - Iterable source1, Iterable source2, + Iterable source1, Iterable source2, Iterable source3, - Func3 zipper) { - return new IxZip3(nullCheck(source1, "source1 is null"), nullCheck(source2, "source2 is null"), + IxFunction3 zipper) { + return new IxZip3(nullCheck(source1, "source1 is null"), nullCheck(source2, "source2 is null"), nullCheck(source3, "source3 is null"), nullCheck(zipper, "zipper is null")); } @@ -608,7 +603,7 @@ public static Ix zip( * If one of the source Iterables is sorter the sequence terminates eagerly. *

* The result's iterator() doesn't support remove(). - * + * * @param the first source's element type * @param the second source's element type * @param the third source's element type @@ -618,24 +613,24 @@ public static Ix zip( * @param source2 the second source Iterable * @param source3 the third source Iterable * @param source4 the fourth source Iterable - * @param zipper the function that takesone from each source, not null + * @param zipper the function that takes one from each source, not null * @return the new Ix instance * @throws NullPointerException if any of the sources or zipper is null * @since 1.0 */ public static Ix zip( - Iterable source1, Iterable source2, + Iterable source1, Iterable source2, Iterable source3, Iterable source4, - Func4 zipper) { - return new IxZip4(nullCheck(source1, "source1 is null"), - nullCheck(source2, "source2 is null"), nullCheck(source3, "source3 is null"), + IxFunction4 zipper) { + return new IxZip4(nullCheck(source1, "source1 is null"), + nullCheck(source2, "source2 is null"), nullCheck(source3, "source3 is null"), nullCheck(source4, "source4 is null"), nullCheck(zipper, "zipper is null")); } //--------------------------------------------------------------------------------------- // Instance operators //--------------------------------------------------------------------------------------- - + /** * Emits true if all elements of this sequence match a given predicate (including empty). *

@@ -643,12 +638,12 @@ public static Ix zip( * @param predicate the predicate receiving each element * @return the new Ix instance * @throws NullPointerException if predicate is null - * @since 1.0 + * @since 1.0 */ - public final Ix all(Pred predicate) { + public final Ix all(IxPredicate predicate) { return new IxAll(this, nullCheck(predicate, "predicate is null")); } - + /** * Emits true if any element of this sequence matches the given predicate, * false otherwise (or for empty sequences). @@ -659,7 +654,7 @@ public final Ix all(Pred predicate) { * @throws NullPointerException if predicate is null * @since 1.0 */ - public final Ix any(Pred predicate) { + public final Ix any(IxPredicate predicate) { return new IxAny(this, nullCheck(predicate, "predicate is null")); } @@ -672,10 +667,10 @@ public final Ix any(Pred predicate) { * @throws NullPointerException if transformer is null * @since 1.0 */ - public final R as(Func1, R> transformer) { - return transformer.call(this); + public final R as(IxFunction, R> transformer) { + return transformer.apply(this); } - + /** * Calculates the float-based average of this sequence of numbers. *

The returned sequence is empty if this sequence is empty. @@ -707,7 +702,7 @@ public final Ix averageFloat() { public final Ix averageDouble() { return new IxAverageDouble((Iterable)this); } - + /** * Buffers the subsequent {@code size} elements into a sequence of * non-overlapping Lists. @@ -721,9 +716,9 @@ public final Ix averageDouble() { public final Ix> buffer(int size) { return new IxBuffer(this, positive(size, "size")); } - + /** - * Buffers the subsequent {@code size} elemeints into a sequence of + * Buffers the subsequent {@code size} elements into a sequence of * potentially overlapping Lists. *

* The result's iterator() doesn't support remove(). @@ -742,7 +737,7 @@ public final Ix> buffer(int size, int skip) { } return new IxBufferOverlap(this, positive(size, "size"), positive(skip, "skip")); } - + /** * Cast the elements to the specified class. *

@@ -757,7 +752,7 @@ public final Ix> buffer(int size, int skip) { public final Ix cast(Class clazz) { return (Ix)this; } - + /** * Collect the elements into a collection via collector action and emit that collection * as a single item. @@ -770,10 +765,10 @@ public final Ix cast(Class clazz) { * @throws NullPointerException if initialFactory or collector is null * @since 1.0 */ - public final Ix collect(Func0 initialFactory, Action2 collector) { - return new IxCollect(this, nullCheck(initialFactory, "initalFactory is null"), nullCheck(collector, "collector")); + public final Ix collect(IxSupplier initialFactory, IxConsumer2 collector) { + return new IxCollect(this, nullCheck(initialFactory, "initialFactory is null"), nullCheck(collector, "collector")); } - + /** * Collects the elements of this sequence into an Object array. *

@@ -785,7 +780,7 @@ public final Ix collectToArray() { return collect(ToListHelper.initialFactory(), ToListHelper.collector()) .map(ToListHelper.toArray()); } - + /** * Collects the elements of this sequence into a List. *

@@ -796,7 +791,7 @@ public final Ix collectToArray() { public final Ix> collectToList() { return collect(ToListHelper.initialFactory(), ToListHelper.collector()); } - + /** * Collects the elements of this sequence into a Map where the key is * determined from each element via the keySelector function; duplicates are @@ -810,8 +805,8 @@ public final Ix> collectToList() { * @throws NullPointerException if keySelector is null * @since 1.0 */ - public final Ix> collectToMap(Func1 keySelector) { - Func1 f = IdentityHelper.instance(); + public final Ix> collectToMap(IxFunction keySelector) { + IxFunction f = IdentityHelper.instance(); return this.collectToMap(keySelector, f); } @@ -832,7 +827,7 @@ public final Ix> collectToMap(Func1 keySel * @throws NullPointerException if keySelector or valueSelector is null * @since 1.0 */ - public final Ix> collectToMap(Func1 keySelector, Func1 valueSelector) { + public final Ix> collectToMap(IxFunction keySelector, IxFunction valueSelector) { return new IxToMap(this, nullCheck(keySelector, "keySelector is null"), nullCheck(valueSelector, "valueSelector is null")); } @@ -848,8 +843,8 @@ public final Ix> collectToMap(Func1 key * @throws NullPointerException if keySelector is null * @since 1.0 */ - public final Ix>> collectToMultimap(Func1 keySelector) { - Func1 f = IdentityHelper.instance(); + public final Ix>> collectToMultimap(IxFunction keySelector) { + IxFunction f = IdentityHelper.instance(); return this.collectToMultimap(keySelector, f); } @@ -869,10 +864,10 @@ public final Ix>> collectToMultimap(Func1 Ix>> collectToMultimap(Func1 keySelector, Func1 valueSelector) { + public final Ix>> collectToMultimap(IxFunction keySelector, IxFunction valueSelector) { return new IxToMultimap(this, keySelector, valueSelector); } - + /** * Collects the elements of this sequence into a Set. *

@@ -889,36 +884,36 @@ public final Ix> collectToSet() { * with this Ix instance and emits the elements of the returned Iterable. *

* The result's iterator() forwards the call remove() to the returned Iterable's Iterator. - * + * * @param the result value type * @param transformer the transformer called with this Ix when Ix.iterator() is invoked * @return the new Ix instance * @throws NullPointerException if transformer is null * @since 1.0 */ - public final Ix compose(Func1, ? extends Iterable> transformer) { + public final Ix compose(IxFunction, ? extends Iterable> transformer) { return new IxCompose(this, nullCheck(transformer, "transformer is null")); } - + /** - * Maps each element from this sequence into subsequent Iterable sequences whose elmenents are + * Maps each element from this sequence into subsequent Iterable sequences whose elements are * concatenated in order. *

* Note that flatMap and concatMap operations are the same in the Iterable world. *

* The result's iterator() forwards the call remove() to the current inner Iterator. - * + * * @param the result value type - * @param mapper the function + * @param mapper the function * @return the new Ix instance * @throws NullPointerException if mapper is null * @since 1.0 - * @see #flatMap(Func1) + * @see #flatMap(IxFunction) */ - public final Ix concatMap(Func1> mapper) { + public final Ix concatMap(IxFunction> mapper) { return new IxFlattenIterable(this, nullCheck(mapper, "mapper is null")); } - + /** * Emits elements of this sequence followed by the elements of the other sequence. *

@@ -934,7 +929,7 @@ public final Ix concatMap(Func1 concatWith(Iterable other) { return concat(this, other); } - + /** * Emits true if the sequence contains the given Object, compared via null-safe * equals. @@ -947,7 +942,7 @@ public final Ix concatWith(Iterable other) { public final Ix contains(Object o) { return new IxContains(this, o); } - + /** * Emits the number of elements in this sequence. *

@@ -981,7 +976,7 @@ public final Ix countLong() { public final Ix defaultIfEmpty(T value) { return switchIfEmpty(Ix.just(value)); } - + /** * Emits only distinct, never before seen elements (according to null-safe equals()) * of this sequence. @@ -998,7 +993,7 @@ public final Ix distinct() { } /** - * Emits only distinct, never before seen keys extracted from elements + * Emits only distinct, never before seen keys extracted from elements * (according to null-safe equals()) of this sequence. *

* Note that this operator uses a memory of seen elements which may grow unbounded @@ -1012,7 +1007,7 @@ public final Ix distinct() { * @throws NullPointerException if keySelector is null * @since 1.0 */ - public final Ix distinct(Func1 keySelector) { + public final Ix distinct(IxFunction keySelector) { return new IxDistinct(this, nullCheck(keySelector, "keySelector is null")); } @@ -1039,13 +1034,13 @@ public final Ix distinctUntilChanged() { * @throws NullPointerException if comparer is null * @since 1.0 */ - public final Ix distinctUntilChanged(Pred2 comparer) { + public final Ix distinctUntilChanged(IxPredicate2 comparer) { return new IxDistinctUntilChanged(this, IdentityHelper.instance(), nullCheck(comparer, "comparer is null")); } /** * Emits elements from this sequence if each element is different from the previous element - * (according to a null-safe equals() of the extracted key), dropping elements that evaluate + * (according to a null-safe equals() of the extracted key), dropping elements that evaluate * to the same as the previous. *

* The result's iterator() doesn't support remove(). @@ -1056,10 +1051,10 @@ public final Ix distinctUntilChanged(Pred2 comparer) { * @throws NullPointerException if comparer is null * @since 1.0 */ - public final Ix distinctUntilChanged(Func1 keySelector) { + public final Ix distinctUntilChanged(IxFunction keySelector) { return new IxDistinctUntilChanged(this, keySelector, EqualityHelper.INSTANCE); } - + /** * Calls the given action just before when the consumer calls next() of this Ix.iterator(). *

@@ -1069,7 +1064,7 @@ public final Ix distinctUntilChanged(Func1 keySelector) { * @throws NullPointerException if action is null * @since 1.0 */ - public final Ix doOnNext(Action1 action) { + public final Ix doOnNext(IxConsumer action) { return new IxDoOn(this, nullCheck(action, "action is null"), IxEmptyAction.instance0()); } @@ -1083,7 +1078,7 @@ public final Ix doOnNext(Action1 action) { * @throws NullPointerException if action is null * @since 1.0 */ - public final Ix doOnCompleted(Action0 action) { + public final Ix doOnCompleted(Runnable action) { return new IxDoOn(this, IxEmptyAction.instance1(), nullCheck(action, "action is null")); } @@ -1099,9 +1094,9 @@ public final Ix doOnCompleted(Action0 action) { public final Ix endWith(T... values) { return concat(this, fromArray(values)); } - + /** - * Emits distinct elements from this and the other Iterable which are not + * Emits distinct elements from this and the other Iterable which are not * in the other sequence (i.e., (A union B) minus (A intersection B)). *

* The result's iterator() doesn't support remove(). @@ -1115,40 +1110,40 @@ public final Ix endWith(T... values) { public final Ix except(Iterable other) { return new IxExcept(this, nullCheck(other, "other is null")); } - + /** * Emits elements of this sequence which match the given predicate only. *

* The result's iterator() forwards the call to remove() to this' Iterator. * @param predicate the predicate receiving the current element and if it - * returns true, the value is emitted, ingored otherwise. + * returns true, the value is emitted, ignored otherwise. * @return the new Ix instance * @throws NullPointerException if predicate is null * @since 1.0 */ - public final Ix filter(Pred predicate) { + public final Ix filter(IxPredicate predicate) { return new IxFilter(this, nullCheck(predicate, "predicate is null")); } - + /** - * Maps each element from this sequence into subsequent Iterable sequences whose elmenents are + * Maps each element from this sequence into subsequent Iterable sequences whose elements are * concatenated in order. *

* Note that flatMap and concatMap operations are the same in the Iterable world. *

* The result's iterator() forwards the call remove() to the current inner Iterator. - * + * * @param the result value type - * @param mapper the function + * @param mapper the function * @return the new Ix instance * @throws NullPointerException if mapper is null * @since 1.0 - * @see #concatMap(Func1) + * @see #concatMap(IxFunction) */ - public final Ix flatMap(Func1> mapper) { + public final Ix flatMap(IxFunction> mapper) { return new IxFlattenIterable(this, mapper); } - + /** * Groups elements of this sequence into distinct groups keyed by the keys returned by the keySelector. *

@@ -1162,14 +1157,14 @@ public final Ix flatMap(Func1> * @return the new Ix instance * @throws NullPointerException if keySelector is null * @since 1.0 - * @see #groupBy(Func1, Func1) + * @see #groupBy(IxFunction, IxFunction) */ - public final Ix> groupBy(Func1 keySelector) { + public final Ix> groupBy(IxFunction keySelector) { return groupBy(keySelector, IdentityHelper.instance()); } /** - * Groups mapped elements (by the valueSelector) of this sequence into distinct groups + * Groups mapped elements (by the valueSelector) of this sequence into distinct groups * keyed by the keys returned by the keySelector. *

* The operator doesn't lose data and calling hasNext/next on either the returned Ix or on the inner @@ -1181,14 +1176,14 @@ public final Ix> groupBy(Func1 keySe * @param keySelector the function receiving the current element and returns the key to be used for * grouping the values into the same inner GroupedIx. * @param valueSelector the function receiving the current element and returns the value to be emitted - * by the appropriate group + * by the appropriate group * @return the new Ix instance * @throws NullPointerException if keySelector or valueSelector is null * @since 1.0 - * @see #groupBy(Func1, Func1) + * @see #groupBy(IxFunction, IxFunction) */ - public final Ix> groupBy(Func1 keySelector, - Func1 valueSelector) { + public final Ix> groupBy(IxFunction keySelector, + IxFunction valueSelector) { return new IxGroupBy(this, nullCheck(keySelector, "keySelector is null"), nullCheck(valueSelector, "valueSelector is null")); } @@ -1202,9 +1197,9 @@ public final Ix> groupBy(Func1 ke public final Ix hasElements() { return new IxHasElements(this); } - + /** - * Hides the identity of this Ix instance and prevents certain identity-based optimiziations. + * Hides the identity of this Ix instance and prevents certain identity-based optimizations. *

* The result's iterator() forwards the remove() calls to this' Iterator. * @return the new Ix instance @@ -1213,7 +1208,7 @@ public final Ix hasElements() { public final Ix hide() { return new IxWrapper(this); } - + /** * Emits distinct values of this and the other Iterables that are present in * both sequences. @@ -1229,7 +1224,7 @@ public final Ix hide() { public final Ix intersect(Iterable other) { return new IxIntersect(this, nullCheck(other, "other is null")); } - + /** * Runs through this sequence, ignoring all values until this sequence completes. *

@@ -1240,7 +1235,7 @@ public final Ix intersect(Iterable other) { public final Ix ignoreElements() { return new IxIgnoreElements(this); } - + /** * Converts elements of this sequence to String and concatenates them into * a single, comma separated String. @@ -1252,7 +1247,7 @@ public final Ix ignoreElements() { public final Ix join() { return join(", "); } - + /** * Converts elements of this sequence to String and concatenates them into * a single String separated by the given character sequence. @@ -1265,7 +1260,7 @@ public final Ix join() { public final Ix join(CharSequence separator) { return new IxJoin(this, separator); } - + /** * Calls the given lifter function with the iterator of this sequence and emits * elements of the returned Iterator. @@ -1278,10 +1273,10 @@ public final Ix join(CharSequence separator) { * @throws NullPointerException if lifter is null * @since 1.0 */ - public final Ix lift(Func1, ? extends Iterator> lifter) { + public final Ix lift(IxFunction, ? extends Iterator> lifter) { return new IxLift(this, nullCheck(lifter, "lifter is null")); } - + /** * Maps each element of this sequence to some other value. *

@@ -1293,10 +1288,10 @@ public final Ix lift(Func1, ? extends Iterator> li * @throws NullPointerException if mapper is null * @since 1.0 */ - public final Ix map(Func1 mapper) { + public final Ix map(IxFunction mapper) { return new IxMap(this, mapper); } - + /** * Emits the first maximum element according to the given comparator. *

@@ -1316,7 +1311,7 @@ public final Ix max(Comparator comparator) { /** * Emits the first maximum element according to their natural order. *

- * The sequence may throw a ClassCastException if any of the elements is + * The sequence may throw a ClassCastException if any of the elements is * not self-comparable (i.e., doesn't implement the Comparable interface). *

* The result's iterator() doesn't support remove(). @@ -1328,7 +1323,7 @@ public final Ix max(Comparator comparator) { public final Ix max() { return max((Comparator)SelfComparator.INSTANCE); } - + /** * Returns the first maximum integer value. *

@@ -1394,7 +1389,7 @@ public final Ix min(Comparator comparator) { /** * Emits the first minimum element according to their natural order. *

- * The sequence may throw a ClassCastException if any of the element is + * The sequence may throw a ClassCastException if any of the element is * not self-comparable (i.e., doesn't implement the Comparable interface). *

* The result's iterator() doesn't support remove(). @@ -1436,7 +1431,7 @@ public final Ix minInt() { public final Ix minLong() { return new IxMinLong((Ix)this); } - + /** * Orders elements according to their natural order. *

@@ -1453,7 +1448,7 @@ public final Ix minLong() { public final Ix orderBy() { return orderBy((Comparator)SelfComparator.INSTANCE); } - + /** * Orders elements according to the comparator. *

@@ -1470,7 +1465,7 @@ public final Ix orderBy() { public final Ix orderBy(Comparator comparator) { return new IxOrderBy(this, IdentityHelper.instance(), nullCheck(comparator, "comparator is null"), 1); } - + /** * Orders elements according to the natural order of the extracted keys from these elements. *

@@ -1480,9 +1475,9 @@ public final Ix orderBy(Comparator comparator) { * @return the new Ix instance * @throws NullPointerException if keySelector is null * @since 1.0 - * @see #orderByReverse(Func1) + * @see #orderByReverse(IxFunction) */ - public final > Ix orderBy(Func1 keySelector) { + public final > Ix orderBy(IxFunction keySelector) { return new IxOrderBy(this, nullCheck(keySelector, "keySelector is null"), SelfComparator.INSTANCE, 1); } @@ -1502,7 +1497,7 @@ public final > Ix orderBy(Func1 public final Ix orderByReverse() { return orderByReverse((Comparator)SelfComparator.INSTANCE); } - + /** * Orders elements according to the reversed comparator. *

@@ -1519,7 +1514,7 @@ public final Ix orderByReverse() { public final Ix orderByReverse(Comparator comparator) { return new IxOrderBy(this, IdentityHelper.instance(), nullCheck(comparator, "comparator is null"), -1); } - + /** * Orders elements according to the reverse natural order of the extracted keys from these elements. *

@@ -1529,9 +1524,9 @@ public final Ix orderByReverse(Comparator comparator) { * @return the new Ix instance * @throws NullPointerException if keySelector is null * @since 1.0 - * @see #orderByReverse(Func1) + * @see #orderByReverse(IxFunction) */ - public final > Ix orderByReverse(Func1 keySelector) { + public final > Ix orderByReverse(IxFunction keySelector) { return new IxOrderBy(this, nullCheck(keySelector, "keySelector is null"), SelfComparator.INSTANCE, -1); } @@ -1560,10 +1555,10 @@ public final Ix publish() { * @throws NullPointerException if transform is null * @since 1.0 */ - public final Ix publish(Func1, ? extends Iterable> transform) { - return new IxPublishSelector(this, nullCheck(transform, "transfrom is null")); + public final Ix publish(IxFunction, ? extends Iterable> transform) { + return new IxPublishSelector(this, nullCheck(transform, "transform is null")); } - + /** * Reduces the elements of this sequence into a single value via a reducer function. *

@@ -1573,12 +1568,12 @@ public final Ix publish(Func1, ? extends Iterable reduce(Func2 reducer) { + public final Ix reduce(IxFunction2 reducer) { return new IxAggregate(this, nullCheck(reducer, "reducer is null")); } - + /** * Given a per-iterator() initial value, reduces the elements of this sequence into a single * value via a reducer function. @@ -1592,12 +1587,12 @@ public final Ix reduce(Func2 reducer) { * @return the new Ix instance * @throws NullPointerException if initialFactory or reducer is null * @since 1.0 - * @see #reduce(Func2) + * @see #reduce(IxFunction2) */ - public final Ix reduce(Func0 initialFactory, Func2 reducer) { + public final Ix reduce(IxSupplier initialFactory, IxFunction2 reducer) { return new IxReduce(this, initialFactory, reducer); } - + /** * Removes those elements via Iterator.remove() from this sequence that match the * given predicate. @@ -1608,12 +1603,12 @@ public final Ix reduce(Func0 initialFactory, Func2 reducer) { * @return the new Ix instance * @throws NullPointerException if predicate is null * @since 1.0 - * @see #retain(Pred) + * @see #retain(IxPredicate) */ - public final Ix remove(Pred predicate) { + public final Ix remove(IxPredicate predicate) { return new IxRemove(this, nullCheck(predicate, "predicate is null")); } - + /** * Repeats this sequence indefinitely. *

@@ -1624,7 +1619,7 @@ public final Ix remove(Pred predicate) { public final Ix repeat() { return concat(repeatValue(this)); } - + /** * Repeats this sequence at most the given number of times. *

A count of zero will yield an empty sequence, a count of one @@ -1639,7 +1634,7 @@ public final Ix repeat() { public final Ix repeat(long times) { return concat(repeatValue(this, times)); } - + /** * Repeats this sequence if the given predicate returns true after the sequence * completes in a round. @@ -1651,7 +1646,7 @@ public final Ix repeat(long times) { * @throws NullPointerException if stopPredicate is null * @since 1.0 */ - public final Ix repeat(Pred0 stopPredicate) { + public final Ix repeat(IxBooleanSupplier stopPredicate) { return concat(repeatValue(this, stopPredicate)); } @@ -1671,7 +1666,7 @@ public final Ix repeat(Pred0 stopPredicate) { * @throws NullPointerException if stopPredicate is null * @since 1.0 */ - public final Ix repeat(long times, Pred0 stopPredicate) { + public final Ix repeat(long times, IxBooleanSupplier stopPredicate) { return concat(repeatValue(this, times, stopPredicate)); } @@ -1714,7 +1709,7 @@ public final Ix replay(int size) { * @throws NullPointerException if transform is null * @since 1.0 */ - public final Ix replay(Func1, ? extends Iterable> transform) { + public final Ix replay(IxFunction, ? extends Iterable> transform) { return new IxReplaySelector(this, nullCheck(transform, "transform is null")); } @@ -1735,7 +1730,7 @@ public final Ix replay(Func1, ? extends Iterable Ix replay(int size, Func1, ? extends Iterable> transform) { + public final Ix replay(int size, IxFunction, ? extends Iterable> transform) { return new IxReplaySizeSelector(this, positive(size, "size"), nullCheck(transform, "transform is null")); } @@ -1749,12 +1744,12 @@ public final Ix replay(int size, Func1, ? extends Iterable< * @return the new Ix instance * @throws NullPointerException if predicate is null * @since 1.0 - * @see #remove(Pred) + * @see #remove(IxPredicate) */ - public final Ix retain(Pred predicate) { + public final Ix retain(IxPredicate predicate) { return new IxRetain(this, nullCheck(predicate, "predicate is null")); } - + /** * Plays this sequence in reverse. *

@@ -1780,7 +1775,7 @@ public final Ix reverse() { * @throws NullPointerException if scanner is null * @since 1.0 */ - public final Ix scan(Func2 scanner) { + public final Ix scan(IxFunction2 scanner) { return new IxScan(this, nullCheck(scanner, "scanner is null")); } @@ -1797,10 +1792,10 @@ public final Ix scan(Func2 scanner) { * @throws NullPointerException if initialFactory or scanner is null * @since 1.0 */ - public final Ix scan(Func0 initialFactory, Func2 scanner) { + public final Ix scan(IxSupplier initialFactory, IxFunction2 scanner) { return new IxScanSeed(this, nullCheck(initialFactory, "initialFactory is null"), nullCheck(scanner, "scanner is null")); } - + /** * Determines if two sequences have the same elements in the same order and are the same length based * on null-safe object equality. @@ -1827,7 +1822,7 @@ public final Ix sequenceEqual(Iterable other) { * @throws NullPointerException if other is null * @since 1.0 */ - public final Ix sequenceEqual(Iterable other, Pred2 comparer) { + public final Ix sequenceEqual(Iterable other, IxPredicate2 comparer) { return new IxSequenceEqual(this, nullCheck(other, "other is null"), nullCheck(comparer, "comparer is null")); } @@ -1873,12 +1868,12 @@ public final Ix skipLast(int n) { * @return the new Ix instance * @throws NullPointerException if predicate is null * @since 1.0 - * @see #takeWhile(Pred) + * @see #takeWhile(IxPredicate) */ - public final Ix skipWhile(Pred predicate) { + public final Ix skipWhile(IxPredicate predicate) { return new IxSkipWhile(this, nullCheck(predicate, "predicate is null")); } - + /** * Emits elements of the given array followed by the elements of this sequence. *

@@ -1925,11 +1920,11 @@ public final Ix sumInt() { public final Ix sumLong() { return new IxSumLong((Ix)this); } - + /** * Emits the elements of the other sequence if this sequence is empty. *

- * The result's Iterator forwards calls of remove() to this' or the other's Iterator. + * The result's Iterator forwards calls of remove() to this' or the other's Iterator. * @param other the other Iterable instance, not null * @return the new Ix instance * @throws NullPointerException if other is null @@ -1942,7 +1937,7 @@ public final Ix switchIfEmpty(Iterable other) { /** * Emits the first n elements (or less) of this sequence. *

- * The result's Iterator forwards calls of remove() to this' Iterator. + * The result's Iterator forwards calls of remove() to this' Iterator. * @param n the number of items to emit at most, non-negative * @return the new Ix instance * @throws IllegalArgumentException if n is negative @@ -1952,7 +1947,7 @@ public final Ix switchIfEmpty(Iterable other) { public final Ix take(int n) { return new IxTake(this, nonNegative(n, "n")); } - + /** * Emits the last n elements (or fewer) of this sequence. *

@@ -1966,45 +1961,45 @@ public final Ix take(int n) { public final Ix takeLast(int n) { return new IxTakeLast(this, nonNegative(n, "n")); } - + /** - * Take elements from this sequence while the given predicate returns true + * Take elements from this sequence while the given predicate returns true * for the current element (checked after emission of that element). *

- * The result's Iterator forwards calls of remove() to this' Iterator. + * The result's Iterator forwards calls of remove() to this' Iterator. * @param stopPredicate the function receiving the current element and returns * true if no further elements should be emitted after this element. * @return the new Ix instance * @throws NullPointerException if stopPredicate is null * @since 1.0 */ - public final Ix takeUntil(Pred stopPredicate) { + public final Ix takeUntil(IxPredicate stopPredicate) { return new IxTakeUntil(this, nullCheck(stopPredicate, "stopPredicate is null")); } - + /** - * Take elements from this sequence until the given predicate returns true + * Take elements from this sequence until the given predicate returns true * for the current element (checked before emission of that element). *

- * The result's Iterator forwards calls of remove() to this' Iterator. + * The result's Iterator forwards calls of remove() to this' Iterator. * @param predicate the function receiving the current element and returns * false if no further elements should be emitted (not even the current). * @return the new Ix instance * @throws NullPointerException if predicate is null * @since 1.0 */ - public final Ix takeWhile(Pred predicate) { + public final Ix takeWhile(IxPredicate predicate) { return new IxTakeWhile(this, nullCheck(predicate, "predicate is null")); } - - + + /** * Maps this sequence of numbers into a sequence of longs. *

* The sequence may throw a ClassCastException if any of the elements * is not a subclass of Number. *

- * The result's Iterator forwards calls of remove() to this' Iterator. + * The result's Iterator forwards calls of remove() to this' Iterator. * @return the new Ix instance * @since 1.0 */ @@ -2027,7 +2022,7 @@ public final Ix toLong() { public final Ix transform(IxTransform transformer) { return new IxTransformer(this, nullCheck(transformer, "transformer is null")); } - + /** * Emits a distinct set of values from both this and the other sequence. *

@@ -2044,9 +2039,9 @@ public final Ix union(Iterable other) { } /** - * Emits inner Ix Iterables of non-overapping sequences mapped from this sequence + * Emits inner Ix Iterables of non-overlapping sequences mapped from this sequence * with the given maximum size each. - * + * *

* The result's and the inner Ix' iterator() don't support remove(). * @param size the maximum size of the inner windows, positive @@ -2064,7 +2059,7 @@ public final Ix> window(int size) { * sequence with the given maximum size each and started each {@code skip} source elements. * @param size the maximum size of the inner windows, positive * @param skip after how many elements to start a new window (repeatedly), positive - * @return the new Ix Iinstance + * @return the new Ix instance * @throws IllegalArgumentException if size or skip is non-positive * @since 1.0 * @see #window(int) @@ -2078,23 +2073,23 @@ public final Ix> window(int size, int skip) { } return new IxWindowOverlap(this, positive(size, "size"), positive(skip, "skip")); } - + /** * Combines the next element from this and the other source Iterable via a zipper function. *

* If one of the source Iterables is sorter the sequence terminates eagerly. *

* The result's iterator() doesn't support remove(). - * + * * @param the other source's element type * @param the result value type * @param other the the other source Iterable - * @param zipper the function that takesone from each source, not null + * @param zipper the function that takes one from each source, not null * @return the new Ix instance * @throws NullPointerException if other or zipper is null * @since 1.0 */ - public final Ix zipWith(Iterable other, Func2 zipper) { + public final Ix zipWith(Iterable other, IxFunction2 zipper) { return zip(this, other, zipper); } @@ -2138,17 +2133,17 @@ public final T first(T defaultValue) { } return defaultValue; } - + /** * Consumes the entire sequence and calls the given action with each value. * @param action the action to call * @throws NullPointerException if action is null * @since 1.0 - * @see #foreachWhile(Pred) + * @see #foreachWhile(IxPredicate) */ - public final void foreach(Action1 action) { + public final void foreach(IxConsumer action) { for (T t : this) { - action.call(t); + action.accept(t); } } @@ -2159,9 +2154,9 @@ public final void foreach(Action1 action) { * return true to continue the loop or false to quit the loop. * @throws NullPointerException if action is null * @since 1.0 - * @see #foreach(Action1) + * @see #foreach(IxConsumer) */ - public final void foreachWhile(Pred predicate) { + public final void foreachWhile(IxPredicate predicate) { for (T t : this) { if (!predicate.test(t)) { break; @@ -2201,7 +2196,7 @@ public final T last() { if (!it.hasNext()) { throw new NoSuchElementException(); } - + for (;;) { T t = it.next(); if (!it.hasNext()) { @@ -2209,7 +2204,7 @@ public final T last() { } } } - + /** * Returns the last element of this sequence or the defaultValue if * this sequence is empty. @@ -2228,7 +2223,7 @@ public final T last(T defaultValue) { if (!it.hasNext()) { return defaultValue; } - + for (;;) { T t = it.next(); if (!it.hasNext()) { @@ -2256,9 +2251,9 @@ public final void print() { public final void print(CharSequence separator, int charsPerLine) { boolean first = true; int len = 0; - + for (T v : this) { - + String s = String.valueOf(v); if (first) { @@ -2277,7 +2272,7 @@ public final void print(CharSequence separator, int charsPerLine) { len += s.length(); } } - + } } @@ -2301,7 +2296,7 @@ public final void println(CharSequence prefix) { System.out.print(prefix); System.out.println(v); } - } + } /** * Removes all elements by repeatedly calling this sequence's Iterator.remove(). */ @@ -2323,11 +2318,11 @@ public final void removeAll() { * for elements to keep. * @throws UnsupportedOperationException if the this Iterable * doesn't allow removing elements. - * @see #retainAll(Pred) + * @see #retainAll(IxPredicate) * @see #removeAll() * @since 1.0 */ - public final void removeAll(Pred predicate) { + public final void removeAll(IxPredicate predicate) { Iterator it = iterator(); while (it.hasNext()) { T v = it.next(); @@ -2346,10 +2341,10 @@ public final void removeAll(Pred predicate) { * for elements to remove. * @throws UnsupportedOperationException if the this Iterable * doesn't allow removing elements. - * @see #removeAll(Pred) + * @see #removeAll(IxPredicate) * @since 1.0 */ - public final void retainAll(Pred predicate) { + public final void retainAll(IxPredicate predicate) { Iterator it = iterator(); while (it.hasNext()) { T v = it.next(); @@ -2391,10 +2386,10 @@ public final T single() { } throw new NoSuchElementException("The source is empty."); } - + /** - * Returns the single element of this sequence, defalutValue + * Returns the single element of this sequence, defaultValue * if this sequence is empty or IndexOutOfBoundsException if this sequence has more * than one element * @param defaultValue the value to return if this sequence is empty @@ -2430,9 +2425,9 @@ public final void subscribe() { * @throws NullPointerException if consumer is null * @since 1.0 */ - public final void subscribe(Action1 onNext) { + public final void subscribe(IxConsumer onNext) { for (T v : this) { - onNext.call(v); + onNext.accept(v); } } @@ -2441,18 +2436,17 @@ public final void subscribe(Action1 onNext) { * each element and calls the onError with any exception thrown by the iteration * or the onNext action. * @param onNext the consumer to call with each element - * @param onError the consumer to call with the exception thrown + * @param onError the consumer to call with the exception thrown * @throws NullPointerException if onError is null * @since 1.0 */ - public final void subscribe(Action1 onNext, Action1 onError) { + public final void subscribe(IxConsumer onNext, IxConsumer onError) { try { for (T v : this) { - onNext.call(v); + onNext.accept(v); } } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - onError.call(ex); + onError.accept(ex); } } @@ -2463,71 +2457,22 @@ public final void subscribe(Action1 onNext, Action1 onErro * without exception. * @param onNext the consumer to call with each element * @param onError the consumer to call with the exception thrown - * @param onCompleted the action called after the sequence has been consumed + * @param onCompleted the action called after the sequence has been consumed * @throws NullPointerException if onError or onCompleted is null * @since 1.0 */ - public final void subscribe(Action1 onNext, Action1 onError, Action0 onCompleted) { + public final void subscribe(IxConsumer onNext, IxConsumer onError, Runnable onCompleted) { try { for (T v : this) { - onNext.call(v); + onNext.accept(v); } } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - onError.call(ex); + onError.accept(ex); return; } - onCompleted.call(); + onCompleted.run(); } - /** - * Consumes this sequence and calls the appropriate onXXX method on the given Observer instance. - * @param observer the observer to forward values, error or completion to. - * @throws NullPointerException if observer is null - * @since 1.0 - */ - public final void subscribe(Observer observer) { - try { - for (T v : this) { - observer.onNext(v); - } - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - observer.onError(ex); - return; - } - observer.onCompleted(); - } - - /** - * Consumes this sequence and calls the appropriate onXXX method on the given Subscriber instance - * as long as it has not unsubscribed. - * @param subscriber the subscriber to forward values, error or completion to. - * @throws NullPointerException if subscriber is null - * @since 1.0 - */ - public final void subscribe(Subscriber subscriber) { - try { - for (T v : this) { - if (subscriber.isUnsubscribed()) { - return; - } - subscriber.onNext(v); - } - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - if (subscriber.isUnsubscribed()) { - return; - } - subscriber.onError(ex); - return; - } - if (subscriber.isUnsubscribed()) { - return; - } - subscriber.onCompleted(); - } - /** * Collects the elements of this sequence into an Object array. *

@@ -2574,7 +2519,7 @@ public final List toList() { * @throws NullPointerException if keySelector is null * @since 1.0 */ - public final Map toMap(Func1 keySelector) { + public final Map toMap(IxFunction keySelector) { return collectToMap(keySelector).first(); } @@ -2594,7 +2539,7 @@ public final Map toMap(Func1 keySelector) { * @throws NullPointerException if keySelector or valueSelector is null * @since 1.0 */ - public final Map toMap(Func1 keySelector, Func1 valueSelector) { + public final Map toMap(IxFunction keySelector, IxFunction valueSelector) { return collectToMap(keySelector, valueSelector).first(); } @@ -2609,7 +2554,7 @@ public final Map toMap(Func1 keySelector, F * @throws NullPointerException if keySelector is null * @since 1.0 */ - public final Map> toMultimap(Func1 keySelector) { + public final Map> toMultimap(IxFunction keySelector) { return collectToMultimap(keySelector).first(); } @@ -2628,10 +2573,10 @@ public final Map> toMultimap(Func1 * @throws NullPointerException if keySelector or valueSelector is null * @since 1.0 */ - public final Map> toMultimap(Func1 keySelector, Func1 valueSelector) { + public final Map> toMultimap(IxFunction keySelector, IxFunction valueSelector) { return collectToMultimap(keySelector, valueSelector).first(); } - + /** * Collects the elements of this sequence into a Set. *

@@ -2646,7 +2591,7 @@ public final Set toSet() { // -------------------------------------------------------------------------------------------- // Helper methods // -------------------------------------------------------------------------------------------- - + /** * Checks if the value is null and if so, throws * a NullPointerException with the given message. @@ -2661,7 +2606,7 @@ protected static U nullCheck(U value, String message) { } return value; } - + /** * Calls the given callable and rethrows its exception * (as RuntimeException if necessary). @@ -2682,10 +2627,10 @@ protected static U checkedCall(Callable callable) { throw new RuntimeException(ex); } } - + /** * Checks if the given value is non-negative and returns it; throws - * an IllegalArgumentException otherwise + * an IllegalArgumentException otherwise. * @param n the number to check * @param name the name of the parameter * @return n @@ -2696,10 +2641,10 @@ protected static long nonNegative(long n, String name) { } return n; } - + /** * Checks if the given value is non-negative and returns it; throws - * an IllegalArgumentException otherwise + * an IllegalArgumentException otherwise. * @param n the number to check * @param name the name of the parameter * @return n @@ -2713,7 +2658,7 @@ protected static int nonNegative(int n, String name) { /** * Checks if the given value is positive and returns it; throws - * an IllegalArgumentException otherwise + * an IllegalArgumentException otherwise. * @param n the number to check * @param name the name of the parameter * @return n diff --git a/src/main/java/ix/IxAggregate.java b/src/main/java/ix/IxAggregate.java index 3749c4b..2a4b255 100644 --- a/src/main/java/ix/IxAggregate.java +++ b/src/main/java/ix/IxAggregate.java @@ -18,13 +18,11 @@ import java.util.Iterator; -import rx.functions.Func2; - final class IxAggregate extends IxSource { - final Func2 aggregator; - - public IxAggregate(Iterable source, Func2 aggregator) { + final IxFunction2 aggregator; + + IxAggregate(Iterable source, IxFunction2 aggregator) { super(source); this.aggregator = aggregator; } @@ -33,12 +31,12 @@ public IxAggregate(Iterable source, Func2 aggregator) { public Iterator iterator() { return new AggregateIterator(source.iterator(), aggregator); } - + static final class AggregateIterator extends IxSourceIterator { - - final Func2 aggregator; - - public AggregateIterator(Iterator it, Func2 aggregator) { + + final IxFunction2 aggregator; + + AggregateIterator(Iterator it, IxFunction2 aggregator) { super(it); this.aggregator = aggregator; } @@ -46,12 +44,12 @@ public AggregateIterator(Iterator it, Func2 aggregator) { @Override protected boolean moveNext() { Iterator it = this.it; - Func2 f = aggregator; - + IxFunction2 f = aggregator; + if (it.hasNext()) { T acc = it.next(); while (it.hasNext()) { - acc = f.call(acc, it.next()); + acc = f.apply(acc, it.next()); } value = acc; hasValue = true; diff --git a/src/main/java/ix/IxAll.java b/src/main/java/ix/IxAll.java index be72ccb..ceb6fd4 100644 --- a/src/main/java/ix/IxAll.java +++ b/src/main/java/ix/IxAll.java @@ -20,46 +20,46 @@ final class IxAll extends IxSource { - final Pred predicate; - - public IxAll(Iterable source, Pred predicate) { + final IxPredicate predicate; + + IxAll(Iterable source, IxPredicate predicate) { super(source); this.predicate = predicate; } - + @Override public Iterator iterator() { return new AllIterator(source.iterator(), predicate); } - + static final class AllIterator extends IxSourceIterator { - final Pred predicate; + final IxPredicate predicate; - public AllIterator(Iterator it, Pred predicate) { + AllIterator(Iterator it, IxPredicate predicate) { super(it); this.predicate = predicate; } - + @Override protected boolean moveNext() { Iterator it = this.it; - Pred pred = predicate; - + IxPredicate p = predicate; + while (it.hasNext()) { - if (!pred.test(it.next())) { + if (!p.test(it.next())) { hasValue = true; value = false; done = true; return true; } } - + hasValue = true; value = true; done = true; return true; } - + } } diff --git a/src/main/java/ix/IxAny.java b/src/main/java/ix/IxAny.java index 201ddf3..9589936 100644 --- a/src/main/java/ix/IxAny.java +++ b/src/main/java/ix/IxAny.java @@ -20,46 +20,46 @@ final class IxAny extends IxSource { - final Pred predicate; - - public IxAny(Iterable source, Pred predicate) { + final IxPredicate predicate; + + IxAny(Iterable source, IxPredicate predicate) { super(source); this.predicate = predicate; } - + @Override public Iterator iterator() { return new AnyIterator(source.iterator(), predicate); } - + static final class AnyIterator extends IxSourceIterator { - final Pred predicate; + final IxPredicate predicate; - public AnyIterator(Iterator it, Pred predicate) { + AnyIterator(Iterator it, IxPredicate predicate) { super(it); this.predicate = predicate; } - + @Override protected boolean moveNext() { Iterator it = this.it; - Pred pred = predicate; - + IxPredicate p = predicate; + while (it.hasNext()) { - if (pred.test(it.next())) { + if (p.test(it.next())) { hasValue = true; value = true; done = true; return true; } } - + hasValue = true; value = false; done = true; return true; } - + } } diff --git a/src/main/java/ix/IxAverageDouble.java b/src/main/java/ix/IxAverageDouble.java index 6de30b6..b51b692 100644 --- a/src/main/java/ix/IxAverageDouble.java +++ b/src/main/java/ix/IxAverageDouble.java @@ -20,7 +20,7 @@ final class IxAverageDouble extends IxSource { - public IxAverageDouble(Iterable source) { + IxAverageDouble(Iterable source) { super(source); } @@ -31,7 +31,7 @@ public Iterator iterator() { static final class AverageFloatIterator extends IxSourceIterator { - public AverageFloatIterator(Iterator it) { + AverageFloatIterator(Iterator it) { super(it); } @@ -41,17 +41,17 @@ protected boolean moveNext() { double accumulator = 0f; long count = 0; - + if (!it.hasNext()) { done = true; return false; } - + do { accumulator += it.next().doubleValue(); count++; } while (it.hasNext()); - + value = accumulator / count; hasValue = true; done = true; diff --git a/src/main/java/ix/IxAverageFloat.java b/src/main/java/ix/IxAverageFloat.java index cd3f05e..8cf3664 100644 --- a/src/main/java/ix/IxAverageFloat.java +++ b/src/main/java/ix/IxAverageFloat.java @@ -20,7 +20,7 @@ final class IxAverageFloat extends IxSource { - public IxAverageFloat(Iterable source) { + IxAverageFloat(Iterable source) { super(source); } @@ -31,7 +31,7 @@ public Iterator iterator() { static final class AverageFloatIterator extends IxSourceIterator { - public AverageFloatIterator(Iterator it) { + AverageFloatIterator(Iterator it) { super(it); } @@ -41,17 +41,17 @@ protected boolean moveNext() { float accumulator = 0f; int count = 0; - + if (!it.hasNext()) { done = true; return false; } - + do { accumulator += it.next().floatValue(); count++; } while (it.hasNext()); - + value = accumulator / count; hasValue = true; done = true; diff --git a/src/main/java/ix/IxBaseIterator.java b/src/main/java/ix/IxBaseIterator.java index b17930c..d46d00a 100644 --- a/src/main/java/ix/IxBaseIterator.java +++ b/src/main/java/ix/IxBaseIterator.java @@ -25,13 +25,13 @@ * @param the result value type */ public abstract class IxBaseIterator implements Iterator { - - /** Inidicates a value is available for consumption. */ + + /** Indicates a value is available for consumption. */ protected boolean hasValue; - + /** Indicates there are no more data available. */ protected boolean done; - + /** The current value if hasValue is true. */ protected R value; @@ -40,7 +40,7 @@ public abstract class IxBaseIterator implements Iterator { * @return what the hasNext should return */ protected abstract boolean moveNext(); - + @Override public final boolean hasNext() { boolean b = hasValue; @@ -51,7 +51,7 @@ public final boolean hasNext() { } return b; } - + @Override public final R next() { if (!hasValue && !hasNext()) { @@ -62,7 +62,7 @@ public final R next() { value = null; return v; } - + @Override public void remove() { throw new UnsupportedOperationException(); diff --git a/src/main/java/ix/Pred0.java b/src/main/java/ix/IxBooleanSupplier.java similarity index 78% rename from src/main/java/ix/Pred0.java rename to src/main/java/ix/IxBooleanSupplier.java index b23a207..c1ecdc2 100644 --- a/src/main/java/ix/Pred0.java +++ b/src/main/java/ix/IxBooleanSupplier.java @@ -17,12 +17,12 @@ package ix; /** - * A supplier of a single boolean value. + * A function callback with no inputs and a boolean output. */ -public interface Pred0 { +public interface IxBooleanSupplier { /** - * Returns a boolean value. - * @return a boolean value + * Calls the function which returns a boolean. + * @return the output boolean */ boolean getAsBoolean(); } diff --git a/src/main/java/ix/IxBuffer.java b/src/main/java/ix/IxBuffer.java index cb0ee10..1a03c38 100644 --- a/src/main/java/ix/IxBuffer.java +++ b/src/main/java/ix/IxBuffer.java @@ -21,12 +21,12 @@ final class IxBuffer extends IxSource> { final int size; - - public IxBuffer(Iterable source, int size) { + + IxBuffer(Iterable source, int size) { super(source); this.size = size; } - + @Override public Iterator> iterator() { return new BufferIterator(source.iterator(), size); @@ -35,7 +35,7 @@ public Iterator> iterator() { static final class BufferIterator extends IxSourceIterator> { final int size; - public BufferIterator(Iterator it, int size) { + BufferIterator(Iterator it, int size) { super(it); this.size = size; } @@ -43,16 +43,16 @@ public BufferIterator(Iterator it, int size) { @Override protected boolean moveNext() { int s = size; - + Iterator it = this.it; - + List list = new ArrayList(); - + while (s != 0 && it.hasNext()) { list.add(it.next()); s--; } - + if (list.isEmpty()) { done = true; return false; @@ -64,7 +64,7 @@ protected boolean moveNext() { } return true; } - - + + } } diff --git a/src/main/java/ix/IxBufferOverlap.java b/src/main/java/ix/IxBufferOverlap.java index ebbc07e..c801ddf 100644 --- a/src/main/java/ix/IxBufferOverlap.java +++ b/src/main/java/ix/IxBufferOverlap.java @@ -18,34 +18,32 @@ import java.util.*; -import rx.functions.Action2; - final class IxBufferOverlap extends IxSource> { final int size; - + final int skip; - - public IxBufferOverlap(Iterable source, int size, int skip) { + + IxBufferOverlap(Iterable source, int size, int skip) { super(source); this.size = size; this.skip = skip; } - + @Override public Iterator> iterator() { return new BufferIterator(source.iterator(), size, skip); } static final class BufferIterator extends IxSourceQueuedIterator, List> - implements Action2, T> { + implements IxConsumer2, T> { final int size; - + final int skip; - + int index; - - public BufferIterator(Iterator it, int size, int skip) { + + BufferIterator(Iterator it, int size, int skip) { super(it); this.size = size; this.skip = skip; @@ -55,12 +53,12 @@ public BufferIterator(Iterator it, int size, int skip) { @Override protected boolean moveNext() { Iterator it = this.it; - + int s = size; int k = skip; - + int i = index; - + while (it.hasNext()) { if (i == 0) { offer(new ArrayList()); @@ -70,26 +68,26 @@ protected boolean moveNext() { if (++i == k) { i = 0; } - + if (((List)peek()).size() == s) { break; } } index = i; - + List list = fromObject(poll()); if (list == null) { done = true; return false; } - + value = list; hasValue = true; return true; } - + @Override - public void call(List t1, T t2) { + public void accept(List t1, T t2) { t1.add(t2); } } diff --git a/src/main/java/ix/IxBufferSkip.java b/src/main/java/ix/IxBufferSkip.java index e275be1..70ca253 100644 --- a/src/main/java/ix/IxBufferSkip.java +++ b/src/main/java/ix/IxBufferSkip.java @@ -21,15 +21,15 @@ final class IxBufferSkip extends IxSource> { final int size; - + final int skip; - - public IxBufferSkip(Iterable source, int size, int skip) { + + IxBufferSkip(Iterable source, int size, int skip) { super(source); this.size = size; this.skip = skip; } - + @Override public Iterator> iterator() { return new BufferSkipIterator(source.iterator(), size, skip); @@ -37,12 +37,12 @@ public Iterator> iterator() { static final class BufferSkipIterator extends IxSourceIterator> { final int size; - + final int skip; - + boolean once; - public BufferSkipIterator(Iterator it, int size, int skip) { + BufferSkipIterator(Iterator it, int size, int skip) { super(it); this.size = size; this.skip = skip; @@ -51,28 +51,28 @@ public BufferSkipIterator(Iterator it, int size, int skip) { @Override protected boolean moveNext() { Iterator it = this.it; - + int s = size; - + if (once) { int k = skip - s; while (k != 0 && it.hasNext()) { it.next(); k--; } - + } else { once = true; } List list = new ArrayList(); - + while (s != 0 && it.hasNext()) { list.add(it.next()); s--; } - - + + if (list.isEmpty()) { done = true; return false; @@ -84,7 +84,7 @@ protected boolean moveNext() { } return true; } - - + + } } diff --git a/src/main/java/ix/IxCharacters.java b/src/main/java/ix/IxCharacters.java index 0f75588..c54a404 100644 --- a/src/main/java/ix/IxCharacters.java +++ b/src/main/java/ix/IxCharacters.java @@ -21,31 +21,31 @@ final class IxCharacters extends Ix { final CharSequence source; - + final int start; - + final int end; - - public IxCharacters(CharSequence source, int start, int end) { + + IxCharacters(CharSequence source, int start, int end) { this.source = source; this.start = start; this.end = end; } - + @Override public Iterator iterator() { return new CharactersIterator(source, start, end); } - + static final class CharactersIterator implements Iterator { final CharSequence source; final int end; - + int index; - - public CharactersIterator(CharSequence source, int start, int end) { + + CharactersIterator(CharSequence source, int start, int end) { this.source = source; this.index = start; this.end = end; @@ -65,7 +65,7 @@ public Integer next() { } throw new NoSuchElementException(); } - + @Override public void remove() { throw new UnsupportedOperationException(); diff --git a/src/main/java/ix/IxCollect.java b/src/main/java/ix/IxCollect.java index 5712589..4932bc2 100644 --- a/src/main/java/ix/IxCollect.java +++ b/src/main/java/ix/IxCollect.java @@ -18,15 +18,13 @@ import java.util.Iterator; -import rx.functions.*; - final class IxCollect extends IxSource { - final Func0 initialFactory; - - final Action2 collector; - - public IxCollect(Iterable source, Func0 initialFactory, Action2 collector) { + final IxSupplier initialFactory; + + final IxConsumer2 collector; + + IxCollect(Iterable source, IxSupplier initialFactory, IxConsumer2 collector) { super(source); this.initialFactory = initialFactory; this.collector = collector; @@ -34,14 +32,14 @@ public IxCollect(Iterable source, Func0 initialFactory, Action2 coll @Override public Iterator iterator() { - return new CollectorIterator(source.iterator(), collector, initialFactory.call()); + return new CollectorIterator(source.iterator(), collector, initialFactory.get()); } static final class CollectorIterator extends IxSourceIterator { - final Action2 collector; - - public CollectorIterator(Iterator it, Action2 collector, C value) { + final IxConsumer2 collector; + + CollectorIterator(Iterator it, IxConsumer2 collector, C value) { super(it); this.collector = collector; this.value = value; @@ -50,15 +48,15 @@ public CollectorIterator(Iterator it, Action2 collector, C value) { @Override protected boolean moveNext() { Iterator it = this.it; - - Action2 coll = collector; - + + IxConsumer2 coll = collector; + C c = value; - + while (it.hasNext()) { - coll.call(c, it.next()); + coll.accept(c, it.next()); } - + hasValue = true; done = true; return true; diff --git a/src/main/java/ix/IxCompose.java b/src/main/java/ix/IxCompose.java index 03775a9..c578bf8 100644 --- a/src/main/java/ix/IxCompose.java +++ b/src/main/java/ix/IxCompose.java @@ -18,13 +18,11 @@ import java.util.Iterator; -import rx.functions.Func1; - final class IxCompose extends IxSource { - final Func1, ? extends Iterable> transformer; - - public IxCompose(Iterable source, Func1, ? extends Iterable> transformer) { + final IxFunction, ? extends Iterable> transformer; + + IxCompose(Iterable source, IxFunction, ? extends Iterable> transformer) { super(source); this.transformer = transformer; } @@ -32,7 +30,7 @@ public IxCompose(Iterable source, Func1, ? extends Iterable iterator() { - return (Iterator)transformer.call(from(source)).iterator(); + return (Iterator)transformer.apply(from(source)).iterator(); } } diff --git a/src/main/java/ix/IxConsumer.java b/src/main/java/ix/IxConsumer.java new file mode 100644 index 0000000..b56463b --- /dev/null +++ b/src/main/java/ix/IxConsumer.java @@ -0,0 +1,29 @@ +/* + * Copyright 2011-2016 David Karnok + * + * 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 ix; + +/** + * A function callback with one input value. + * @param the input value type + */ +public interface IxConsumer { + /** + * Applies a function to the input value. + * @param t the input value + */ + void accept(T t); +} diff --git a/src/main/java/ix/IxConsumer2.java b/src/main/java/ix/IxConsumer2.java new file mode 100644 index 0000000..5ec592c --- /dev/null +++ b/src/main/java/ix/IxConsumer2.java @@ -0,0 +1,31 @@ +/* + * Copyright 2011-2016 David Karnok + * + * 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 ix; + +/** + * A function callback with two input values. + * @param the input value type + * @param the input value type + */ +public interface IxConsumer2 { + /** + * Applies a function to the input value. + * @param t the first input value + * @param u the second input value + */ + void accept(T t, U u); +} diff --git a/src/main/java/ix/IxContains.java b/src/main/java/ix/IxContains.java index b9f58aa..5e44c24 100644 --- a/src/main/java/ix/IxContains.java +++ b/src/main/java/ix/IxContains.java @@ -21,8 +21,8 @@ final class IxContains extends IxSource { final Object o; - - public IxContains(Iterable source, Object o) { + + IxContains(Iterable source, Object o) { super(source); this.o = o; } @@ -31,21 +31,21 @@ public IxContains(Iterable source, Object o) { public Iterator iterator() { return new ContainsIterator(source.iterator(), o); } - + static final class ContainsIterator extends IxSourceIterator { final Object o; - public ContainsIterator(Iterator it, Object o) { + ContainsIterator(Iterator it, Object o) { super(it); this.o = o; } - + @Override protected boolean moveNext() { Iterator it = this.it; Object o = this.o; - + while (it.hasNext()) { T v = it.next(); if (o == v || (o != null && o.equals(v))) { @@ -55,7 +55,7 @@ protected boolean moveNext() { return true; } } - + value = false; hasValue = true; done = true; diff --git a/src/main/java/ix/IxCount.java b/src/main/java/ix/IxCount.java index 2866a5d..882f662 100644 --- a/src/main/java/ix/IxCount.java +++ b/src/main/java/ix/IxCount.java @@ -20,7 +20,7 @@ final class IxCount extends IxSource { - public IxCount(Iterable source) { + IxCount(Iterable source) { super(source); } @@ -31,21 +31,21 @@ public Iterator iterator() { static final class CountIterator extends IxSourceIterator { - public CountIterator(Iterator it) { + CountIterator(Iterator it) { super(it); } @Override protected boolean moveNext() { int c = 0; - + Iterator it = this.it; - + while (it.hasNext()) { it.next(); c++; } - + value = c; hasValue = true; done = true; diff --git a/src/main/java/ix/IxCountLong.java b/src/main/java/ix/IxCountLong.java index 240fde1..f06a40f 100644 --- a/src/main/java/ix/IxCountLong.java +++ b/src/main/java/ix/IxCountLong.java @@ -20,7 +20,7 @@ final class IxCountLong extends IxSource { - public IxCountLong(Iterable source) { + IxCountLong(Iterable source) { super(source); } @@ -31,21 +31,21 @@ public Iterator iterator() { static final class CountLongIterator extends IxSourceIterator { - public CountLongIterator(Iterator it) { + CountLongIterator(Iterator it) { super(it); } @Override protected boolean moveNext() { long c = 0; - + Iterator it = this.it; - + while (it.hasNext()) { it.next(); c++; } - + value = c; hasValue = true; done = true; diff --git a/src/main/java/ix/IxDefer.java b/src/main/java/ix/IxDefer.java index af03c3c..6d5b409 100644 --- a/src/main/java/ix/IxDefer.java +++ b/src/main/java/ix/IxDefer.java @@ -18,19 +18,17 @@ import java.util.Iterator; -import rx.functions.Func0; - final class IxDefer extends Ix { - final Func0> factory; - - public IxDefer(Func0> factory) { + final IxSupplier> factory; + + IxDefer(IxSupplier> factory) { this.factory = factory; } - + @SuppressWarnings("unchecked") @Override public Iterator iterator() { - return (Iterator)factory.call().iterator(); + return (Iterator)factory.get().iterator(); } } diff --git a/src/main/java/ix/IxDistinct.java b/src/main/java/ix/IxDistinct.java index 97a13d0..94ac42d 100644 --- a/src/main/java/ix/IxDistinct.java +++ b/src/main/java/ix/IxDistinct.java @@ -18,28 +18,26 @@ import java.util.*; -import rx.functions.Func1; - final class IxDistinct extends IxSource { - final Func1 keySelector; - - public IxDistinct(Iterable source, Func1 keySelector) { + final IxFunction keySelector; + + IxDistinct(Iterable source, IxFunction keySelector) { super(source); this.keySelector = keySelector; } - + @Override public Iterator iterator() { return new DistinctIterator(source.iterator(), keySelector); } static final class DistinctIterator extends IxSourceIterator { - final Func1 keySelector; + final IxFunction keySelector; final Set set; - - public DistinctIterator(Iterator it, Func1 keySelector) { + + DistinctIterator(Iterator it, IxFunction keySelector) { super(it); this.keySelector = keySelector; this.set = new HashSet(); @@ -48,19 +46,19 @@ public DistinctIterator(Iterator it, Func1 keySelector) { @Override protected boolean moveNext() { Iterator it = this.it; - + while (it.hasNext()) { T v = it.next(); - - K k = keySelector.call(v); - + + K k = keySelector.apply(v); + if (set.add(k)) { value = v; hasValue = true; return true; } } - + done = true; return false; } diff --git a/src/main/java/ix/IxDistinctUntilChanged.java b/src/main/java/ix/IxDistinctUntilChanged.java index 9915650..9f7b44a 100644 --- a/src/main/java/ix/IxDistinctUntilChanged.java +++ b/src/main/java/ix/IxDistinctUntilChanged.java @@ -18,16 +18,14 @@ import java.util.Iterator; -import rx.functions.Func1; - final class IxDistinctUntilChanged extends IxSource { - final Func1 keySelector; - - final Pred2 comparer; - - public IxDistinctUntilChanged(Iterable source, Func1 keySelector, - Pred2 comparer) { + final IxFunction keySelector; + + final IxPredicate2 comparer; + + IxDistinctUntilChanged(Iterable source, IxFunction keySelector, + IxPredicate2 comparer) { super(source); this.keySelector = keySelector; this.comparer = comparer; @@ -39,17 +37,17 @@ public Iterator iterator() { } static final class DistinctUntilChangedIterator extends IxSourceIterator { - - final Func1 keySelector; - - final Pred2 comparer; + + final IxFunction keySelector; + + final IxPredicate2 comparer; K last; - + boolean once; - - public DistinctUntilChangedIterator(Iterator it, Func1 keySelector, - Pred2 comparer) { + + DistinctUntilChangedIterator(Iterator it, IxFunction keySelector, + IxPredicate2 comparer) { super(it); this.keySelector = keySelector; this.comparer = comparer; @@ -58,40 +56,40 @@ public DistinctUntilChangedIterator(Iterator it, Func1 keySelec @Override protected boolean moveNext() { Iterator it = this.it; - + K prev = last; - K curr = null; - + K curr; + while (it.hasNext()) { T v = it.next(); - curr = keySelector.call(v); + curr = keySelector.apply(v); if (!once) { once = true; - + last = curr; - + value = v; hasValue = true; return true; } - + if (!comparer.test(prev, curr)) { last = curr; - + value = v; hasValue = true; return true; } - + prev = curr; } - - + + done = true; return false; } - + } } diff --git a/src/main/java/ix/IxDoOn.java b/src/main/java/ix/IxDoOn.java index d4c74b9..57feef6 100644 --- a/src/main/java/ix/IxDoOn.java +++ b/src/main/java/ix/IxDoOn.java @@ -18,15 +18,13 @@ import java.util.Iterator; -import rx.functions.*; - final class IxDoOn extends IxSource { - final Action1 onNext; - - final Action0 onCompleted; - - public IxDoOn(Iterable source, Action1 onNext, Action0 onCompleted) { + final IxConsumer onNext; + + final Runnable onCompleted; + + IxDoOn(Iterable source, IxConsumer onNext, Runnable onCompleted) { super(source); this.onNext = onNext; this.onCompleted = onCompleted; @@ -38,11 +36,11 @@ public Iterator iterator() { } static final class DoOnIterator extends IxSourceIterator { - final Action1 onNext; - - final Action0 onCompleted; + final IxConsumer onNext; + + final Runnable onCompleted; - public DoOnIterator(Iterator it, Action1 onNext, Action0 onCompleted) { + DoOnIterator(Iterator it, IxConsumer onNext, Runnable onCompleted) { super(it); this.onNext = onNext; this.onCompleted = onCompleted; @@ -54,10 +52,10 @@ protected boolean moveNext() { T v = it.next(); value = v; hasValue = true; - onNext.call(v); + onNext.accept(v); return true; } - onCompleted.call(); + onCompleted.run(); done = true; return false; } diff --git a/src/main/java/ix/IxEmitter.java b/src/main/java/ix/IxEmitter.java new file mode 100644 index 0000000..f1a0e61 --- /dev/null +++ b/src/main/java/ix/IxEmitter.java @@ -0,0 +1,36 @@ +/* + * Copyright 2011-2016 David Karnok + * + * 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 ix; + +/** + * Allows signalling values or completion in an imperative manner. + * + * @param the value type emitted + */ +public interface IxEmitter { + + /** + * The next value to signal. + * @param value the value to signal + */ + void onNext(T value); + + /** + * Indicate no more values will be generated. + */ + void onComplete(); +} diff --git a/src/main/java/ix/IxEmpty.java b/src/main/java/ix/IxEmpty.java index a19d66e..7e76d4d 100644 --- a/src/main/java/ix/IxEmpty.java +++ b/src/main/java/ix/IxEmpty.java @@ -21,12 +21,12 @@ final class IxEmpty extends Ix implements Iterator { static final IxEmpty INSTANCE = new IxEmpty(); - + @SuppressWarnings("unchecked") static Ix instance() { return (Ix)INSTANCE; } - + @Override public Iterator iterator() { return this; @@ -41,7 +41,7 @@ public boolean hasNext() { public Object next() { throw new NoSuchElementException(); } - + @Override public void remove() { throw new UnsupportedOperationException(); diff --git a/src/main/java/ix/IxEmptyAction.java b/src/main/java/ix/IxEmptyAction.java index dcd81f3..44bf72c 100644 --- a/src/main/java/ix/IxEmptyAction.java +++ b/src/main/java/ix/IxEmptyAction.java @@ -16,28 +16,26 @@ package ix; -import rx.functions.*; - -enum IxEmptyAction implements Action1, Action0 { +enum IxEmptyAction implements IxConsumer, Runnable { INSTANCE; @SuppressWarnings("unchecked") - public static Action1 instance1() { - return (Action1)INSTANCE; + public static IxConsumer instance1() { + return (IxConsumer)INSTANCE; } - public static Action0 instance0() { + public static Runnable instance0() { return INSTANCE; } @Override - public void call(Object t) { + public void accept(Object t) { // deliberately no op } - + @Override - public void call() { + public void run() { // deliberately no op } - + } diff --git a/src/main/java/ix/IxExcept.java b/src/main/java/ix/IxExcept.java index a8380ee..af4bdb5 100644 --- a/src/main/java/ix/IxExcept.java +++ b/src/main/java/ix/IxExcept.java @@ -23,33 +23,33 @@ final class IxExcept extends IxSource { final Iterable other; - public IxExcept(Iterable source, Iterable other) { + IxExcept(Iterable source, Iterable other) { super(source); this.other = other; } - + @Override public Iterator iterator() { return new ExceptIterator(source.iterator(), other.iterator()); } - + static final class ExceptIterator extends IxSourceIterator { final Iterator other; - + final LinkedHashMap set; - + Iterator> setIterator; - + boolean once; - + boolean second; - public ExceptIterator(Iterator it, Iterator other) { + ExceptIterator(Iterator it, Iterator other) { super(it); this.other = other; this.set = new LinkedHashMap(); } - + @Override protected boolean moveNext() { LinkedHashMap secondSet = set; @@ -59,13 +59,13 @@ protected boolean moveNext() { secondSet.put(other.next(), true); } } - + for (;;) { if (second) { Iterator> sIt = setIterator; while (sIt.hasNext()) { Entry e = sIt.next(); - + if (e.getValue()) { value = e.getKey(); hasValue = true; @@ -78,7 +78,7 @@ protected boolean moveNext() { Iterator fIt = it; while (fIt.hasNext()) { T v = fIt.next(); - + Boolean b = secondSet.get(v); if (b == null) { value = v; @@ -92,7 +92,7 @@ protected boolean moveNext() { second = true; setIterator = secondSet.entrySet().iterator(); } - } + } } } } diff --git a/src/main/java/ix/IxFilter.java b/src/main/java/ix/IxFilter.java index e530c6e..c26a036 100644 --- a/src/main/java/ix/IxFilter.java +++ b/src/main/java/ix/IxFilter.java @@ -20,9 +20,9 @@ final class IxFilter extends IxSource { - final Pred predicate; - - public IxFilter(Iterable source, Pred predicate) { + final IxPredicate predicate; + + IxFilter(Iterable source, IxPredicate predicate) { super(source); this.predicate = predicate; } @@ -34,9 +34,9 @@ public Iterator iterator() { static final class FilterIterator extends IxSourceIterator { - final Pred predicate; - - public FilterIterator(Iterator it, Pred predicate) { + final IxPredicate predicate; + + FilterIterator(Iterator it, IxPredicate predicate) { super(it); this.predicate = predicate; } @@ -57,7 +57,7 @@ protected boolean moveNext() { } } } - + @Override public void remove() { it.remove(); diff --git a/src/main/java/ix/IxFlattenArrayIterable.java b/src/main/java/ix/IxFlattenArrayIterable.java index aa89bfa..e8656ce 100644 --- a/src/main/java/ix/IxFlattenArrayIterable.java +++ b/src/main/java/ix/IxFlattenArrayIterable.java @@ -22,8 +22,8 @@ final class IxFlattenArrayIterable extends Ix { final Iterable[] sources; - - public IxFlattenArrayIterable(Iterable[] sources) { + + IxFlattenArrayIterable(Iterable[] sources) { this.sources = sources; } @@ -31,7 +31,7 @@ public IxFlattenArrayIterable(Iterable[] sources) { public Iterator iterator() { return new FlattenIterator(sources); } - + static final class FlattenIterator extends IxBaseIterator { final Iterable[] sources; @@ -39,8 +39,8 @@ static final class FlattenIterator extends IxBaseIterator { Iterator current; int index; - - public FlattenIterator(Iterable[] sources) { + + FlattenIterator(Iterable[] sources) { this.sources = sources; } @@ -48,7 +48,7 @@ public FlattenIterator(Iterable[] sources) { @Override protected boolean moveNext() { Iterator c = current; - + while (c == null) { int i = index; if (i != sources.length) { @@ -59,9 +59,9 @@ protected boolean moveNext() { hasValue = true; return true; } - + c = inner.iterator(); - + if (c.hasNext()) { current = c; break; @@ -73,16 +73,16 @@ protected boolean moveNext() { return false; } } - + value = c.next(); hasValue = true; - + if (!c.hasNext()) { current = null; } return true; } - + } } diff --git a/src/main/java/ix/IxFlattenIterable.java b/src/main/java/ix/IxFlattenIterable.java index 6b4aa63..d1969c1 100644 --- a/src/main/java/ix/IxFlattenIterable.java +++ b/src/main/java/ix/IxFlattenIterable.java @@ -19,13 +19,11 @@ import java.util.Iterator; import java.util.concurrent.Callable; -import rx.functions.Func1; - final class IxFlattenIterable extends IxSource { - final Func1> mapper; - - public IxFlattenIterable(Iterable source, Func1> mapper) { + final IxFunction> mapper; + + IxFlattenIterable(Iterable source, IxFunction> mapper) { super(source); this.mapper = mapper; } @@ -34,18 +32,18 @@ public IxFlattenIterable(Iterable source, Func1 iterator() { if (source instanceof Callable) { - return (Iterator)(mapper.call(checkedCall((Callable)source)).iterator()); + return (Iterator)(mapper.apply(checkedCall((Callable)source)).iterator()); } return new FlattenIterator(source.iterator(), mapper); } - + static final class FlattenIterator extends IxSourceIterator { - final Func1> mapper; + final IxFunction> mapper; Iterator current; - - public FlattenIterator(Iterator it, Func1> mapper) { + + FlattenIterator(Iterator it, IxFunction> mapper) { super(it); this.mapper = mapper; } @@ -54,18 +52,18 @@ public FlattenIterator(Iterator it, Func1 c = current; - + while (c == null) { if (it.hasNext()) { - Iterable inner = mapper.call(it.next()); + Iterable inner = mapper.apply(it.next()); if (inner instanceof Callable) { value = checkedCall((Callable)inner); hasValue = true; return true; } - + c = inner.iterator(); - + if (c.hasNext()) { current = c; break; @@ -77,16 +75,16 @@ protected boolean moveNext() { return false; } } - + value = c.next(); hasValue = true; - + if (!c.hasNext()) { current = null; } return true; } - + } } diff --git a/src/main/java/ix/IxForloop.java b/src/main/java/ix/IxForloop.java index acf1cf1..7035e9a 100644 --- a/src/main/java/ix/IxForloop.java +++ b/src/main/java/ix/IxForloop.java @@ -18,45 +18,43 @@ import java.util.Iterator; -import rx.functions.Func1; - final class IxForloop extends Ix { final T seed; - - final Pred condition; - - final Func1 selector; - - final Func1 next; - - public IxForloop(T seed, Pred condition, Func1 selector, - Func1 next) { + + final IxPredicate condition; + + final IxFunction selector; + + final IxFunction next; + + IxForloop(T seed, IxPredicate condition, IxFunction selector, + IxFunction next) { this.seed = seed; this.condition = condition; this.selector = selector; this.next = next; } - + @Override public Iterator iterator() { return new ForloopIterator(seed, condition, selector, next); } - + static final class ForloopIterator extends IxBaseIterator { - + T index; - final Pred condition; - - final Func1 selector; - - final Func1 next; + final IxPredicate condition; + + final IxFunction selector; + + final IxFunction next; boolean exceptFirst; - - public ForloopIterator(T index, Pred condition, Func1 selector, - Func1 next) { + + ForloopIterator(T index, IxPredicate condition, IxFunction selector, + IxFunction next) { this.index = index; this.condition = condition; this.selector = selector; @@ -66,22 +64,22 @@ public ForloopIterator(T index, Pred condition, Func1 extends Ix { final int start; final int end; final T[] array; - - public IxFromArray(int start, int end, T[] array) { + + IxFromArray(int start, int end, T[] array) { this.start = start; this.end = end; this.array = array; @@ -39,10 +39,10 @@ static final class FromArray implements Iterator { final T[] array; final int end; - + int index; - public FromArray(int start, int end, T[] array) { + FromArray(int start, int end, T[] array) { this.index = start; this.end = end; this.array = array; diff --git a/src/main/java/ix/IxFunction.java b/src/main/java/ix/IxFunction.java new file mode 100644 index 0000000..3086135 --- /dev/null +++ b/src/main/java/ix/IxFunction.java @@ -0,0 +1,31 @@ +/* + * Copyright 2011-2016 David Karnok + * + * 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 ix; + +/** + * A function callback with one input value and one output value. + * @param the input value type + * @param the output value type + */ +public interface IxFunction { + /** + * Applies a function to the input value and returns an output value. + * @param t the input value + * @return the output value + */ + R apply(T t); +} diff --git a/src/main/java/ix/IxFunction2.java b/src/main/java/ix/IxFunction2.java new file mode 100644 index 0000000..64cceac --- /dev/null +++ b/src/main/java/ix/IxFunction2.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2016 David Karnok + * + * 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 ix; + +/** + * A function callback with two input values and one output value. + * @param the first input value type + * @param the second input value type + * @param the output value type + */ +public interface IxFunction2 { + /** + * Applies a function to the input values and returns an output value. + * @param t the first input value + * @param u the second input value + * @return the output value + */ + R apply(T t, U u); +} diff --git a/src/main/java/ix/IxFunction3.java b/src/main/java/ix/IxFunction3.java new file mode 100644 index 0000000..827f97c --- /dev/null +++ b/src/main/java/ix/IxFunction3.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011-2016 David Karnok + * + * 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 ix; + +/** + * A function callback with three input values and one output value. + * @param the first input value type + * @param the second input value type + * @param the third input value type + * @param the output value type + */ +public interface IxFunction3 { + /** + * Applies a function to the input values and returns an output value. + * @param t the first input value + * @param u the second input value + * @param v the third input value + * @return the output value + */ + R apply(T t, U u, V v); +} diff --git a/src/main/java/ix/IxFunction4.java b/src/main/java/ix/IxFunction4.java new file mode 100644 index 0000000..562601c --- /dev/null +++ b/src/main/java/ix/IxFunction4.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011-2016 David Karnok + * + * 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 ix; + +/** + * A function callback with four input values and one output value. + * @param the first input value type + * @param the second input value type + * @param the third input value type + * @param the fourth input value type + * @param the output value type + */ +public interface IxFunction4 { + /** + * Applies a function to the input values and returns an output value. + * @param t the first input value + * @param u the second input value + * @param v the third input value + * @param w the fourth input value + * @return the output value + */ + R apply(T t, U u, V v, W w); +} diff --git a/src/main/java/ix/IxGenerate.java b/src/main/java/ix/IxGenerate.java index e324c1e..b7740d8 100644 --- a/src/main/java/ix/IxGenerate.java +++ b/src/main/java/ix/IxGenerate.java @@ -18,38 +18,35 @@ import java.util.Iterator; -import rx.Observer; -import rx.functions.*; - final class IxGenerate extends Ix { - final Func0 stateFactory; - - final Func2, S> generator; - - final Action1 stateDisposer; - - public IxGenerate(Func0 stateFactory, Func2, S> generator, Action1 stateDisposer) { + final IxSupplier stateFactory; + + final IxFunction2, S> generator; + + final IxConsumer stateDisposer; + + IxGenerate(IxSupplier stateFactory, IxFunction2, S> generator, IxConsumer stateDisposer) { this.stateFactory = stateFactory; this.generator = generator; this.stateDisposer = stateDisposer; } - + @Override public Iterator iterator() { - return new GenerateIterator(stateFactory.call(), generator, stateDisposer); + return new GenerateIterator(stateFactory.get(), generator, stateDisposer); } - + static final class GenerateIterator extends IxBaseIterator - implements Observer { + implements IxEmitter { - final Func2, S> generator; - - final Action1 stateDisposer; + final IxFunction2, S> generator; + + final IxConsumer stateDisposer; S state; - - public GenerateIterator(S state, Func2, S> generator, Action1 stateDisposer) { + + GenerateIterator(S state, IxFunction2, S> generator, IxConsumer stateDisposer) { this.state = state; this.generator = generator; this.stateDisposer = stateDisposer; @@ -57,42 +54,29 @@ public GenerateIterator(S state, Func2, S> generator, Action1 extends Ix { - final Action1> generator; - - public IxGenerateStateless(Action1> generator) { + final IxConsumer> generator; + + IxGenerateStateless(IxConsumer> generator) { this.generator = generator; } - + @Override public Iterator iterator() { return new GenerateIterator(generator); } - + static final class GenerateIterator extends IxBaseIterator - implements Observer { + implements IxEmitter { - final Action1> generator; - - public GenerateIterator(Action1> generator) { + final IxConsumer> generator; + + GenerateIterator(IxConsumer> generator) { this.generator = generator; } @Override protected boolean moveNext() { - - generator.call(this); - + + generator.accept(this); + boolean hv = hasValue; if (!hv && !done) { throw new IllegalStateException("The generator didn't call any of the onXXX methods!"); } return hv; } - + @Override public void onNext(T t) { value = t; hasValue = true; } - - @Override - public void onError(Throwable e) { - if (e instanceof RuntimeException) { - throw (RuntimeException)e; - } - if (e instanceof Error) { - throw (Error)e; - } - throw new RuntimeException(e); - } - + @Override - public void onCompleted() { + public void onComplete() { done = true; } } diff --git a/src/main/java/ix/IxGroupBy.java b/src/main/java/ix/IxGroupBy.java index 93e3da7..e23d9f3 100644 --- a/src/main/java/ix/IxGroupBy.java +++ b/src/main/java/ix/IxGroupBy.java @@ -18,18 +18,16 @@ import java.util.*; -import rx.functions.Func1; - final class IxGroupBy extends IxSource> { static final Object NULL = new Object(); - - final Func1 keySelector; - - final Func1 valueSelector; - - public IxGroupBy(Iterable source, Func1 keySelector, - Func1 valueSelector) { + + final IxFunction keySelector; + + final IxFunction valueSelector; + + IxGroupBy(Iterable source, IxFunction keySelector, + IxFunction valueSelector) { super(source); this.keySelector = keySelector; this.valueSelector = valueSelector; @@ -41,16 +39,16 @@ public Iterator> iterator() { } static final class GroupByIterator extends IxSourceIterator> { - final Func1 keySelector; - - final Func1 valueSelector; + final IxFunction keySelector; + + final IxFunction valueSelector; final Map> groups; final Queue> queue; - - public GroupByIterator(Iterator it, Func1 keySelector, - Func1 valueSelector) { + + GroupByIterator(Iterator it, IxFunction keySelector, + IxFunction valueSelector) { super(it); this.keySelector = keySelector; this.valueSelector = valueSelector; @@ -82,18 +80,18 @@ boolean mainMoveNext() { groups.clear(); return false; } - + T v = it.next(); - - K key = keySelector.call(v); - V val = valueSelector.call(v); - + + K key = keySelector.apply(v); + V val = valueSelector.apply(v); + GroupedIterable g = groups.get(key); if (g == null) { g = new GroupedIterable(key, this); groups.put(key, g); g.iterator.queue.offer(val != null ? val : NULL); - + queue.offer(g); return true; } else { @@ -101,7 +99,7 @@ boolean mainMoveNext() { } } } - + boolean groupMoveNext(GroupByGroupIterator groupIterator) { if (done) { return false; @@ -111,12 +109,12 @@ boolean groupMoveNext(GroupByGroupIterator groupIterator) { groups.clear(); return false; } - + T v = it.next(); - - K key = keySelector.call(v); - V val = valueSelector.call(v); - + + K key = keySelector.apply(v); + V val = valueSelector.apply(v); + GroupedIterable g = groups.get(key); if (g == null) { g = new GroupedIterable(key, this); @@ -132,14 +130,14 @@ boolean groupMoveNext(GroupByGroupIterator groupIterator) { } } } - + static final class GroupedIterable extends GroupedIx { final GroupByGroupIterator iterator; - + boolean once; - - public GroupedIterable(K key, GroupByIterator parent) { + + GroupedIterable(K key, GroupByIterator parent) { super(key); this.iterator = new GroupByGroupIterator(parent, key); } @@ -152,26 +150,26 @@ public Iterator iterator() { } throw new IllegalStateException("This GroupedIx iterable can be consumed only once."); } - + @Override public String toString() { return "GroupedIterable[key=" + iterator.key + ", queue=" + iterator.queue.size() + "]"; } } - + static final class GroupByGroupIterator extends IxBaseIterator { final GroupByIterator parent; - + final K key; final ArrayDeque queue; - - public GroupByGroupIterator(GroupByIterator parent, K key) { + + GroupByGroupIterator(GroupByIterator parent, K key) { this.parent = parent; this.key = key; this.queue = new ArrayDeque(); } - + @SuppressWarnings("unchecked") @Override protected boolean moveNext() { diff --git a/src/main/java/ix/IxHasElements.java b/src/main/java/ix/IxHasElements.java index 3b6405c..1d2d9b9 100644 --- a/src/main/java/ix/IxHasElements.java +++ b/src/main/java/ix/IxHasElements.java @@ -20,7 +20,7 @@ final class IxHasElements extends IxSource { - public IxHasElements(Iterable source) { + IxHasElements(Iterable source) { super(source); } @@ -31,10 +31,10 @@ public Iterator iterator() { static final class HasElementsIterator extends IxSourceIterator { - public HasElementsIterator(Iterator it) { + HasElementsIterator(Iterator it) { super(it); } - + @Override protected boolean moveNext() { value = it.hasNext(); diff --git a/src/main/java/ix/IxIgnoreElements.java b/src/main/java/ix/IxIgnoreElements.java index f431128..f7240f5 100644 --- a/src/main/java/ix/IxIgnoreElements.java +++ b/src/main/java/ix/IxIgnoreElements.java @@ -20,7 +20,7 @@ final class IxIgnoreElements extends IxSource { - public IxIgnoreElements(Iterable source) { + IxIgnoreElements(Iterable source) { super(source); } @@ -31,21 +31,21 @@ public Iterator iterator() { static final class IgnoreElementsIterator extends IxSourceIterator { - public IgnoreElementsIterator(Iterator it) { + IgnoreElementsIterator(Iterator it) { super(it); } @Override protected boolean moveNext() { Iterator it = this.it; - + while (it.hasNext()) { it.next(); } - + done = true; return false; } - + } } diff --git a/src/main/java/ix/IxIntersect.java b/src/main/java/ix/IxIntersect.java index 33e1548..40a1332 100644 --- a/src/main/java/ix/IxIntersect.java +++ b/src/main/java/ix/IxIntersect.java @@ -22,29 +22,29 @@ final class IxIntersect extends IxSource { final Iterable other; - public IxIntersect(Iterable source, Iterable other) { + IxIntersect(Iterable source, Iterable other) { super(source); this.other = other; } - + @Override public Iterator iterator() { return new IntersectIterator(source.iterator(), other.iterator()); } - + static final class IntersectIterator extends IxSourceIterator { final Iterator other; - + final Set set; - + boolean once; - public IntersectIterator(Iterator it, Iterator other) { + IntersectIterator(Iterator it, Iterator other) { super(it); this.other = other; this.set = new HashSet(); } - + @Override protected boolean moveNext() { Set secondSet = set; @@ -59,7 +59,7 @@ protected boolean moveNext() { Iterator fIt = it; while (fIt.hasNext()) { T v = fIt.next(); - + if (secondSet.contains(v)) { value = v; hasValue = true; diff --git a/src/main/java/ix/IxJoin.java b/src/main/java/ix/IxJoin.java index 4142c06..85566bd 100644 --- a/src/main/java/ix/IxJoin.java +++ b/src/main/java/ix/IxJoin.java @@ -21,8 +21,8 @@ final class IxJoin extends IxSource { final CharSequence separator; - - public IxJoin(Iterable source, CharSequence separator) { + + IxJoin(Iterable source, CharSequence separator) { super(source); this.separator = separator; } @@ -31,32 +31,32 @@ public IxJoin(Iterable source, CharSequence separator) { public Iterator iterator() { return new JoinIterator(source.iterator(), separator); } - + static final class JoinIterator extends IxSourceIterator { final CharSequence separator; - public JoinIterator(Iterator it, CharSequence separator) { + JoinIterator(Iterator it, CharSequence separator) { super(it); this.separator = separator; } - + @Override protected boolean moveNext() { CharSequence sep = separator; - + Iterator it = this.it; - + StringBuilder b = new StringBuilder(); - + if (it.hasNext()) { b.append(it.next()); - + while (it.hasNext()) { b.append(sep); b.append(it.next()); } } - + value = b.toString(); hasValue = true; done = true; diff --git a/src/main/java/ix/IxJust.java b/src/main/java/ix/IxJust.java index ba34558..b28fa2f 100644 --- a/src/main/java/ix/IxJust.java +++ b/src/main/java/ix/IxJust.java @@ -21,31 +21,31 @@ final class IxJust extends Ix implements IxScalarCallable { final T value; - - public IxJust(T value) { + + IxJust(T value) { this.value = value; } - + @Override public T call() { return value; } - + @Override public Iterator iterator() { return new JustIterator(value); } - + static final class JustIterator implements Iterator { final T value; - + boolean empty; - - public JustIterator(T value) { + + JustIterator(T value) { this.value = value; } - + @Override public boolean hasNext() { return !empty; @@ -59,7 +59,7 @@ public T next() { } throw new NoSuchElementException(); } - + @Override public void remove() { throw new UnsupportedOperationException(); diff --git a/src/main/java/ix/IxLift.java b/src/main/java/ix/IxLift.java index e3e14bc..0c4ec67 100644 --- a/src/main/java/ix/IxLift.java +++ b/src/main/java/ix/IxLift.java @@ -18,20 +18,18 @@ import java.util.Iterator; -import rx.functions.Func1; - final class IxLift extends IxSource { - final Func1, ? extends Iterator> lifter; - - public IxLift(Iterable source, Func1, ? extends Iterator> lifter) { + final IxFunction, ? extends Iterator> lifter; + + IxLift(Iterable source, IxFunction, ? extends Iterator> lifter) { super(source); this.lifter = lifter; } @Override public Iterator iterator() { - return lifter.call(source.iterator()); + return lifter.apply(source.iterator()); } } diff --git a/src/main/java/ix/IxMap.java b/src/main/java/ix/IxMap.java index b542f4f..684de67 100644 --- a/src/main/java/ix/IxMap.java +++ b/src/main/java/ix/IxMap.java @@ -18,13 +18,11 @@ import java.util.Iterator; -import rx.functions.Func1; - final class IxMap extends IxSource { - final Func1 mapper; - - public IxMap(Iterable source, Func1 mapper) { + final IxFunction mapper; + + IxMap(Iterable source, IxFunction mapper) { super(source); this.mapper = mapper; } @@ -35,12 +33,12 @@ public Iterator iterator() { } static final class MapIterator implements Iterator { - + final Iterator it; - - final Func1 mapper; - public MapIterator(Iterator it, Func1 mapper) { + final IxFunction mapper; + + MapIterator(Iterator it, IxFunction mapper) { this.it = it; this.mapper = mapper; } @@ -52,9 +50,9 @@ public boolean hasNext() { @Override public R next() { - return mapper.call(it.next()); + return mapper.apply(it.next()); } - + @Override public void remove() { it.remove(); diff --git a/src/main/java/ix/IxMaxInt.java b/src/main/java/ix/IxMaxInt.java index af7b419..394a340 100644 --- a/src/main/java/ix/IxMaxInt.java +++ b/src/main/java/ix/IxMaxInt.java @@ -20,7 +20,7 @@ final class IxMaxInt extends IxSource { - public IxMaxInt(Iterable source) { + IxMaxInt(Iterable source) { super(source); } @@ -31,7 +31,7 @@ public Iterator iterator() { static final class MaxIntIterator extends IxSourceIterator { - public MaxIntIterator(Iterator it) { + MaxIntIterator(Iterator it) { super(it); } @@ -47,12 +47,12 @@ protected boolean moveNext() { while (it.hasNext()) { sum = Math.max(sum, it.next()); } - + value = sum; hasValue = true; done = true; return true; } - + } } diff --git a/src/main/java/ix/IxMaxLong.java b/src/main/java/ix/IxMaxLong.java index e9877d3..652255d 100644 --- a/src/main/java/ix/IxMaxLong.java +++ b/src/main/java/ix/IxMaxLong.java @@ -20,7 +20,7 @@ final class IxMaxLong extends IxSource { - public IxMaxLong(Iterable source) { + IxMaxLong(Iterable source) { super(source); } @@ -31,7 +31,7 @@ public Iterator iterator() { static final class MaxLongIterator extends IxSourceIterator { - public MaxLongIterator(Iterator it) { + MaxLongIterator(Iterator it) { super(it); } @@ -47,12 +47,12 @@ protected boolean moveNext() { while (it.hasNext()) { sum = Math.max(sum, it.next()); } - + value = sum; hasValue = true; done = true; return true; } - + } } diff --git a/src/main/java/ix/IxMinInt.java b/src/main/java/ix/IxMinInt.java index f310560..0f5f627 100644 --- a/src/main/java/ix/IxMinInt.java +++ b/src/main/java/ix/IxMinInt.java @@ -20,7 +20,7 @@ final class IxMinInt extends IxSource { - public IxMinInt(Iterable source) { + IxMinInt(Iterable source) { super(source); } @@ -31,7 +31,7 @@ public Iterator iterator() { static final class MinIntIterator extends IxSourceIterator { - public MinIntIterator(Iterator it) { + MinIntIterator(Iterator it) { super(it); } @@ -47,12 +47,12 @@ protected boolean moveNext() { while (it.hasNext()) { sum = Math.min(sum, it.next()); } - + value = sum; hasValue = true; done = true; return true; } - + } } diff --git a/src/main/java/ix/IxMinLong.java b/src/main/java/ix/IxMinLong.java index 0f8670e..7a04e9f 100644 --- a/src/main/java/ix/IxMinLong.java +++ b/src/main/java/ix/IxMinLong.java @@ -20,7 +20,7 @@ final class IxMinLong extends IxSource { - public IxMinLong(Iterable source) { + IxMinLong(Iterable source) { super(source); } @@ -31,7 +31,7 @@ public Iterator iterator() { static final class MinLongIterator extends IxSourceIterator { - public MinLongIterator(Iterator it) { + MinLongIterator(Iterator it) { super(it); } @@ -47,12 +47,12 @@ protected boolean moveNext() { while (it.hasNext()) { sum = Math.min(sum, it.next()); } - + value = sum; hasValue = true; done = true; return true; } - + } } diff --git a/src/main/java/ix/IxMinMax.java b/src/main/java/ix/IxMinMax.java index 1adf261..d2e2e24 100644 --- a/src/main/java/ix/IxMinMax.java +++ b/src/main/java/ix/IxMinMax.java @@ -21,10 +21,10 @@ final class IxMinMax extends IxSource { final Comparator comparator; - + final int flag; - - public IxMinMax(Iterable source, Comparator comparator, int flag) { + + IxMinMax(Iterable source, Comparator comparator, int flag) { super(source); this.comparator = comparator; this.flag = flag; @@ -34,14 +34,14 @@ public IxMinMax(Iterable source, Comparator comparator, int flag) public Iterator iterator() { return new MinMaxIterator(source.iterator(), comparator, flag); } - + static final class MinMaxIterator extends IxSourceIterator { final Comparator comparator; - + final int flag; - - public MinMaxIterator(Iterator it, Comparator comparator, int flag) { + + MinMaxIterator(Iterator it, Comparator comparator, int flag) { super(it); this.comparator = comparator; this.flag = flag; @@ -50,16 +50,16 @@ public MinMaxIterator(Iterator it, Comparator comparator, int flag @Override protected boolean moveNext() { T v; - + Iterator it = this.it; - + if (!it.hasNext()) { done = true; return false; } - + v = it.next(); - + Comparator f = comparator; int g = flag; @@ -69,13 +69,13 @@ protected boolean moveNext() { v = w; } } - + value = v; hasValue = true; done = true; return true; } - + } } diff --git a/src/main/java/ix/IxOrderBy.java b/src/main/java/ix/IxOrderBy.java index a57c6df..b77e66a 100644 --- a/src/main/java/ix/IxOrderBy.java +++ b/src/main/java/ix/IxOrderBy.java @@ -18,17 +18,15 @@ import java.util.*; -import rx.functions.Func1; - final class IxOrderBy extends IxSource { - final Func1 keySelector; - + final IxFunction keySelector; + final Comparator comparator; - + final int flag; - - public IxOrderBy(Iterable source, Func1 keySelector, Comparator comparator, int flag) { + + IxOrderBy(Iterable source, IxFunction keySelector, Comparator comparator, int flag) { super(source); this.keySelector = keySelector; this.comparator = comparator; @@ -39,20 +37,20 @@ public IxOrderBy(Iterable source, Func1 keySelector, Comparator public Iterator iterator() { return new OrderByIterator(source.iterator(), keySelector, comparator, flag); } - + static final class OrderByIterator extends IxSourceIterator implements Comparator { - final Func1 keySelector; - + final IxFunction keySelector; + final Comparator comparator; final int flag; - + List values; - + int index; - - public OrderByIterator(Iterator it, Func1 keySelector, Comparator comparator, int flag) { + + OrderByIterator(Iterator it, IxFunction keySelector, Comparator comparator, int flag) { super(it); this.keySelector = keySelector; this.comparator = comparator; @@ -61,28 +59,28 @@ public OrderByIterator(Iterator it, Func1 keySelector, Comparat @Override protected boolean moveNext() { - + List list = values; - + if (list == null) { list = new ArrayList(); - + Iterator it = this.it; - + while (it.hasNext()) { list.add(it.next()); } - + if (list.isEmpty()) { done = true; return false; } - + Collections.sort(list, this); - + values = list; } - + int i = index; if (i != list.size()) { index = i + 1; @@ -94,11 +92,11 @@ protected boolean moveNext() { done = true; return false; } - + @Override public int compare(T o1, T o2) { - K k1 = keySelector.call(o1); - K k2 = keySelector.call(o2); + K k1 = keySelector.apply(o1); + K k2 = keySelector.apply(o2); return comparator.compare(k1, k2) * flag; } } diff --git a/src/main/java/ix/Pred.java b/src/main/java/ix/IxPredicate.java similarity index 70% rename from src/main/java/ix/Pred.java rename to src/main/java/ix/IxPredicate.java index 390f87f..3b81236 100644 --- a/src/main/java/ix/Pred.java +++ b/src/main/java/ix/IxPredicate.java @@ -17,15 +17,14 @@ package ix; /** - * A predicate functional interface to test a value and return a primitive - * boolean. - * @param the value to test + * A function callback with one input value and a boolean return value. + * @param the input value type */ -public interface Pred { +public interface IxPredicate { /** - * Test the given value. - * @param t the value to test - * @return true if the value passes the test + * Applies a function to the input value and returns a boolean value. + * @param t the input value + * @return the output boolean */ boolean test(T t); } diff --git a/src/main/java/ix/Pred2.java b/src/main/java/ix/IxPredicate2.java similarity index 64% rename from src/main/java/ix/Pred2.java rename to src/main/java/ix/IxPredicate2.java index e80f56f..1f39934 100644 --- a/src/main/java/ix/Pred2.java +++ b/src/main/java/ix/IxPredicate2.java @@ -17,17 +17,16 @@ package ix; /** - * A predicate functional interface to test a value and return a primitive - * boolean. - * @param the first value to test - * @param the second value to test + * A function callback with two input values and a boolean return value. + * @param the first input value type + * @param the second input value */ -public interface Pred2 { +public interface IxPredicate2 { /** - * Test the given value. - * @param t the first value to test - * @param u the second value to test - * @return true if the value passes the test + * Applies a function to the input value and returns a boolean value. + * @param t the first input value + * @param u the second input value + * @return the output boolean */ boolean test(T t, U u); } diff --git a/src/main/java/ix/IxPublish.java b/src/main/java/ix/IxPublish.java index 74651e6..4570ce0 100644 --- a/src/main/java/ix/IxPublish.java +++ b/src/main/java/ix/IxPublish.java @@ -21,8 +21,8 @@ final class IxPublish extends IxSource { Iterator current; - - public IxPublish(Iterable source) { + + IxPublish(Iterable source) { super(source); } diff --git a/src/main/java/ix/IxPublishSelector.java b/src/main/java/ix/IxPublishSelector.java index 7ae68d8..f03130e 100644 --- a/src/main/java/ix/IxPublishSelector.java +++ b/src/main/java/ix/IxPublishSelector.java @@ -18,13 +18,11 @@ import java.util.Iterator; -import rx.functions.Func1; - final class IxPublishSelector extends IxSource { - final Func1, ? extends Iterable> selector; - - public IxPublishSelector(Iterable source, Func1, ? extends Iterable> selector) { + final IxFunction, ? extends Iterable> selector; + + IxPublishSelector(Iterable source, IxFunction, ? extends Iterable> selector) { super(source); this.selector = selector; } @@ -32,18 +30,18 @@ public IxPublishSelector(Iterable source, Func1, ? extends Iter @SuppressWarnings("unchecked") @Override public Iterator iterator() { - - return (Iterator)selector.call(new PublishSelectorIterable(source.iterator())).iterator(); + + return (Iterator)selector.apply(new PublishSelectorIterable(source.iterator())).iterator(); } static final class PublishSelectorIterable extends Ix { - + final Iterator source; - public PublishSelectorIterable(Iterator source) { + PublishSelectorIterable(Iterator source) { this.source = source; } - + @Override public Iterator iterator() { return source; diff --git a/src/main/java/ix/IxRange.java b/src/main/java/ix/IxRange.java index 2aa8bcd..06ff9a9 100644 --- a/src/main/java/ix/IxRange.java +++ b/src/main/java/ix/IxRange.java @@ -21,26 +21,26 @@ final class IxRange extends Ix { final int start; - + final int end; - - public IxRange(int start, int count) { + + IxRange(int start, int count) { this.start = start; this.end = start + count; } - + @Override public Iterator iterator() { return new RangeIterator(start, end); } - + static final class RangeIterator implements Iterator { - + final int end; - + int index; - - public RangeIterator(int start, int end) { + + RangeIterator(int start, int end) { this.index = start; this.end = end; } @@ -59,7 +59,7 @@ public Integer next() { } throw new NoSuchElementException(); } - + @Override public void remove() { throw new UnsupportedOperationException(); diff --git a/src/main/java/ix/IxReduce.java b/src/main/java/ix/IxReduce.java index 8d28540..aa58af7 100644 --- a/src/main/java/ix/IxReduce.java +++ b/src/main/java/ix/IxReduce.java @@ -18,15 +18,13 @@ import java.util.Iterator; -import rx.functions.*; - final class IxReduce extends IxSource { - final Func0 initialFactory; - - final Func2 reducer; - - public IxReduce(Iterable source, Func0 initialFactory, Func2 reducer) { + final IxSupplier initialFactory; + + final IxFunction2 reducer; + + IxReduce(Iterable source, IxSupplier initialFactory, IxFunction2 reducer) { super(source); this.initialFactory = initialFactory; this.reducer = reducer; @@ -34,14 +32,14 @@ public IxReduce(Iterable source, Func0 initialFactory, Func2 redu @Override public Iterator iterator() { - return new CollectorIterator(source.iterator(), reducer, initialFactory.call()); + return new CollectorIterator(source.iterator(), reducer, initialFactory.get()); } static final class CollectorIterator extends IxSourceIterator { - final Func2 reducer; - - public CollectorIterator(Iterator it, Func2 reducer, C value) { + final IxFunction2 reducer; + + CollectorIterator(Iterator it, IxFunction2 reducer, C value) { super(it); this.reducer = reducer; this.value = value; @@ -50,15 +48,15 @@ public CollectorIterator(Iterator it, Func2 reducer, C value) { @Override protected boolean moveNext() { Iterator it = this.it; - - Func2 f = reducer; - + + IxFunction2 f = reducer; + C c = value; - + while (it.hasNext()) { - c = f.call(c, it.next()); + c = f.apply(c, it.next()); } - + value = c; hasValue = true; done = true; diff --git a/src/main/java/ix/IxRemove.java b/src/main/java/ix/IxRemove.java index ef2ba4c..fe99cd8 100644 --- a/src/main/java/ix/IxRemove.java +++ b/src/main/java/ix/IxRemove.java @@ -20,9 +20,9 @@ final class IxRemove extends IxSource { - final Pred predicate; - - public IxRemove(Iterable source, Pred predicate) { + final IxPredicate predicate; + + IxRemove(Iterable source, IxPredicate predicate) { super(source); this.predicate = predicate; } @@ -33,24 +33,24 @@ public Iterator iterator() { } static final class RemoveIterator extends IxSourceIterator { - final Pred predicate; + final IxPredicate predicate; - public RemoveIterator(Iterator it, Pred predicate) { + RemoveIterator(Iterator it, IxPredicate predicate) { super(it); this.predicate = predicate; } @Override protected boolean moveNext() { - + for (;;) { if (!it.hasNext()) { done = true; return false; } - + T v = it.next(); - + if (predicate.test(v)) { it.remove(); } else { @@ -60,7 +60,7 @@ protected boolean moveNext() { } } } - + @Override public void remove() { it.remove(); diff --git a/src/main/java/ix/IxRepeat.java b/src/main/java/ix/IxRepeat.java index 481af71..c06f8f0 100644 --- a/src/main/java/ix/IxRepeat.java +++ b/src/main/java/ix/IxRepeat.java @@ -21,8 +21,8 @@ final class IxRepeat extends Ix { final T value; - - public IxRepeat(T value) { + + IxRepeat(T value) { this.value = value; } @@ -32,23 +32,23 @@ public Iterator iterator() { } static final class RepeatIterator implements Iterator { - + final T value; - - public RepeatIterator(T value) { + + RepeatIterator(T value) { this.value = value; } - + @Override public boolean hasNext() { return true; } - + @Override public T next() { return value; } - + @Override public void remove() { throw new UnsupportedOperationException(); diff --git a/src/main/java/ix/IxRepeatCount.java b/src/main/java/ix/IxRepeatCount.java index 4e07497..c974425 100644 --- a/src/main/java/ix/IxRepeatCount.java +++ b/src/main/java/ix/IxRepeatCount.java @@ -21,10 +21,10 @@ final class IxRepeatCount extends Ix { final T value; - + final long count; - - public IxRepeatCount(T value, long count) { + + IxRepeatCount(T value, long count) { this.value = value; this.count = count; } @@ -35,21 +35,21 @@ public Iterator iterator() { } static final class RepeatCountIterator implements Iterator { - + final T value; - + long count; - - public RepeatCountIterator(T value, long count) { + + RepeatCountIterator(T value, long count) { this.value = value; this.count = count; } - + @Override public boolean hasNext() { return count != 0L; } - + @Override public T next() { long c = count; @@ -59,7 +59,7 @@ public T next() { } throw new NoSuchElementException(); } - + @Override public void remove() { throw new UnsupportedOperationException(); diff --git a/src/main/java/ix/IxRepeatPredicate.java b/src/main/java/ix/IxRepeatPredicate.java index c6780e0..8c21013 100644 --- a/src/main/java/ix/IxRepeatPredicate.java +++ b/src/main/java/ix/IxRepeatPredicate.java @@ -16,17 +16,17 @@ package ix; -import java.util.*; +import java.util.Iterator; final class IxRepeatPredicate extends Ix { final T value; - + final long count; - - final Pred0 stopPredicate; - - public IxRepeatPredicate(T value, long count, Pred0 stopPredicate) { + + final IxBooleanSupplier stopPredicate; + + IxRepeatPredicate(T value, long count, IxBooleanSupplier stopPredicate) { this.value = value; this.stopPredicate = stopPredicate; this.count = count; @@ -40,17 +40,17 @@ public Iterator iterator() { static final class RepeatPredicateIterator extends IxBaseIterator { final T valueToRepeat; - + long count; - - final Pred0 stopPredicate; - - public RepeatPredicateIterator(T value, long count, Pred0 stopPredicate) { + + final IxBooleanSupplier stopPredicate; + + RepeatPredicateIterator(T value, long count, IxBooleanSupplier stopPredicate) { this.valueToRepeat = value; this.stopPredicate = stopPredicate; this.count = count; } - + @Override protected boolean moveNext() { long c = count--; @@ -62,6 +62,6 @@ protected boolean moveNext() { done = true; return false; } - + } } diff --git a/src/main/java/ix/IxReplay.java b/src/main/java/ix/IxReplay.java index 7226409..9f588ba 100644 --- a/src/main/java/ix/IxReplay.java +++ b/src/main/java/ix/IxReplay.java @@ -23,8 +23,8 @@ final class IxReplay extends IxSource { List list; Iterator it; - - public IxReplay(Iterable source) { + + IxReplay(Iterable source) { super(source); } @@ -35,37 +35,37 @@ public Iterator iterator() { } return new ReplayIterator(this); } - + boolean moveNext() { if (!it.hasNext()) { return false; } - + List list = this.list; if (list == null) { list = new ArrayList(); this.list = list; } - + list.add(it.next()); return true; } static final class ReplayIterator extends IxBaseIterator { - + final IxReplay parent; - + int index; - public ReplayIterator(IxReplay parent) { + ReplayIterator(IxReplay parent) { this.parent = parent; } - + @Override protected boolean moveNext() { int i = index; List list = parent.list; - + if (list == null || i == list.size()) { if (!parent.moveNext()) { done = true; diff --git a/src/main/java/ix/IxReplaySelector.java b/src/main/java/ix/IxReplaySelector.java index d8041cb..943a835 100644 --- a/src/main/java/ix/IxReplaySelector.java +++ b/src/main/java/ix/IxReplaySelector.java @@ -18,13 +18,11 @@ import java.util.Iterator; -import rx.functions.Func1; - final class IxReplaySelector extends IxSource { - final Func1, ? extends Iterable> selector; - - public IxReplaySelector(Iterable source, Func1, ? extends Iterable> selector) { + final IxFunction, ? extends Iterable> selector; + + IxReplaySelector(Iterable source, IxFunction, ? extends Iterable> selector) { super(source); this.selector = selector; } @@ -32,7 +30,7 @@ public IxReplaySelector(Iterable source, Func1, ? extends Itera @SuppressWarnings("unchecked") @Override public Iterator iterator() { - - return (Iterator)selector.call(new IxReplay(source)).iterator(); + + return (Iterator)selector.apply(new IxReplay(source)).iterator(); } } diff --git a/src/main/java/ix/IxReplaySize.java b/src/main/java/ix/IxReplaySize.java index 778e248..edfc5e5 100644 --- a/src/main/java/ix/IxReplaySize.java +++ b/src/main/java/ix/IxReplaySize.java @@ -21,21 +21,21 @@ final class IxReplaySize extends IxSource { final int maxSize; - + Iterator it; - + Node head; - + Node tail; int size; - - public IxReplaySize(Iterable source, int maxSize) { + + IxReplaySize(Iterable source, int maxSize) { super(source); this.maxSize = maxSize; this.head = this.tail = new Node(null); } - + @Override public Iterator iterator() { if (it == null) { @@ -43,16 +43,16 @@ public Iterator iterator() { } return new ReplaySizeIterator(this, head); } - + boolean moveNext() { if (!it.hasNext()) { return false; } - + Node n = new Node(it.next()); tail.next = n; tail = n; - + int s = size; if (s != maxSize) { size = s + 1; @@ -61,23 +61,23 @@ boolean moveNext() { } return true; } - + static final class Node { final T value; - + Node next; - - public Node(T value) { + + Node(T value) { this.value = value; } } - + static final class ReplaySizeIterator extends IxBaseIterator { final IxReplaySize parent; Node node; - - public ReplaySizeIterator(IxReplaySize parent, Node node) { + + ReplaySizeIterator(IxReplaySize parent, Node node) { this.parent = parent; this.node = node; } @@ -85,7 +85,7 @@ public ReplaySizeIterator(IxReplaySize parent, Node node) { @Override protected boolean moveNext() { Node n = node; - + if (n.next == null) { if (!parent.moveNext()) { done = true; @@ -93,11 +93,11 @@ protected boolean moveNext() { } } n = n.next; - + value = n.value; hasValue = true; node = n; - + return true; } } diff --git a/src/main/java/ix/IxReplaySizeSelector.java b/src/main/java/ix/IxReplaySizeSelector.java index 11dca1d..fa52393 100644 --- a/src/main/java/ix/IxReplaySizeSelector.java +++ b/src/main/java/ix/IxReplaySizeSelector.java @@ -18,16 +18,14 @@ import java.util.Iterator; -import rx.functions.Func1; - final class IxReplaySizeSelector extends IxSource { final int maxSize; - - final Func1, ? extends Iterable> selector; - - public IxReplaySizeSelector(Iterable source, int maxSize, - Func1, ? extends Iterable> selector) { + + final IxFunction, ? extends Iterable> selector; + + IxReplaySizeSelector(Iterable source, int maxSize, + IxFunction, ? extends Iterable> selector) { super(source); this.maxSize = maxSize; this.selector = selector; @@ -36,7 +34,7 @@ public IxReplaySizeSelector(Iterable source, int maxSize, @SuppressWarnings("unchecked") @Override public Iterator iterator() { - - return (Iterator)selector.call(new IxReplaySize(source, maxSize)).iterator(); + + return (Iterator)selector.apply(new IxReplaySize(source, maxSize)).iterator(); } } diff --git a/src/main/java/ix/IxRetain.java b/src/main/java/ix/IxRetain.java index 6be2f4a..d467853 100644 --- a/src/main/java/ix/IxRetain.java +++ b/src/main/java/ix/IxRetain.java @@ -20,9 +20,9 @@ final class IxRetain extends IxSource { - final Pred predicate; - - public IxRetain(Iterable source, Pred predicate) { + final IxPredicate predicate; + + IxRetain(Iterable source, IxPredicate predicate) { super(source); this.predicate = predicate; } @@ -33,24 +33,24 @@ public Iterator iterator() { } static final class RetainIterator extends IxSourceIterator { - final Pred predicate; + final IxPredicate predicate; - public RetainIterator(Iterator it, Pred predicate) { + RetainIterator(Iterator it, IxPredicate predicate) { super(it); this.predicate = predicate; } @Override protected boolean moveNext() { - + for (;;) { if (!it.hasNext()) { done = true; return false; } - + T v = it.next(); - + if (predicate.test(v)) { value = v; hasValue = true; @@ -60,7 +60,7 @@ protected boolean moveNext() { } } } - + @Override public void remove() { it.remove(); diff --git a/src/main/java/ix/IxReverse.java b/src/main/java/ix/IxReverse.java index 013ffb9..6faf720 100644 --- a/src/main/java/ix/IxReverse.java +++ b/src/main/java/ix/IxReverse.java @@ -20,7 +20,7 @@ final class IxReverse extends IxSource { - public IxReverse(Iterable source) { + IxReverse(Iterable source) { super(source); } @@ -32,17 +32,17 @@ public Iterator iterator() { static final class ReverseIterator extends IxSourceIterator { List list; - + int index; - - public ReverseIterator(Iterator it) { + + ReverseIterator(Iterator it) { super(it); } - + @Override protected boolean moveNext() { List list = this.list; - + if (list == null) { list = new ArrayList(); this.list = list; @@ -51,7 +51,7 @@ protected boolean moveNext() { } index = list.size(); } - + int i = index; if (i == 0) { done = true; diff --git a/src/main/java/ix/IxScan.java b/src/main/java/ix/IxScan.java index d227995..e618c34 100644 --- a/src/main/java/ix/IxScan.java +++ b/src/main/java/ix/IxScan.java @@ -18,13 +18,11 @@ import java.util.Iterator; -import rx.functions.Func2; - final class IxScan extends IxSource { - final Func2 scanner; - - public IxScan(Iterable source, Func2 scanner) { + final IxFunction2 scanner; + + IxScan(Iterable source, IxFunction2 scanner) { super(source); this.scanner = scanner; } @@ -35,25 +33,25 @@ public Iterator iterator() { } static final class ScanIterator extends IxSourceIterator { - - final Func2 scanner; + + final IxFunction2 scanner; T last; - + boolean once; - - public ScanIterator(Iterator it, Func2 scanner) { + + ScanIterator(Iterator it, IxFunction2 scanner) { super(it); this.scanner = scanner; } - + @Override protected boolean moveNext() { if (!once) { if (it.hasNext()) { once = true; T v = it.next(); - + last = v; value = v; hasValue = true; @@ -62,17 +60,17 @@ protected boolean moveNext() { done = true; return false; } - + if (it.hasNext()) { T v = it.next(); - - v = scanner.call(last, v); + + v = scanner.apply(last, v); last = v; value = v; hasValue = true; return true; } - + last = null; done = true; return false; diff --git a/src/main/java/ix/IxScanSeed.java b/src/main/java/ix/IxScanSeed.java index c44778a..d02bbf3 100644 --- a/src/main/java/ix/IxScanSeed.java +++ b/src/main/java/ix/IxScanSeed.java @@ -18,15 +18,13 @@ import java.util.Iterator; -import rx.functions.*; - final class IxScanSeed extends IxSource { - final Func0 seed; - - final Func2 scanner; - - public IxScanSeed(Iterable source, Func0 seed, Func2 scanner) { + final IxSupplier seed; + + final IxFunction2 scanner; + + IxScanSeed(Iterable source, IxSupplier seed, IxFunction2 scanner) { super(source); this.seed = seed; this.scanner = scanner; @@ -34,22 +32,22 @@ public IxScanSeed(Iterable source, Func0 seed, Func2 scanner) { @Override public Iterator iterator() { - return new ScanSeedIterator(source.iterator(), seed.call(), scanner); + return new ScanSeedIterator(source.iterator(), seed.get(), scanner); } - + static final class ScanSeedIterator extends IxSourceIterator { - final Func2 scanner; + final IxFunction2 scanner; R accumulator; - + boolean once; - public ScanSeedIterator(Iterator it, R accumulator, Func2 scanner) { + ScanSeedIterator(Iterator it, R accumulator, IxFunction2 scanner) { super(it); this.accumulator = accumulator; this.scanner = scanner; } - + @Override protected boolean moveNext() { if (!once) { @@ -58,17 +56,17 @@ protected boolean moveNext() { hasValue = true; return true; } - + if (it.hasNext()) { - - R v = scanner.call(accumulator, it.next()); - + + R v = scanner.apply(accumulator, it.next()); + accumulator = v; value = v; hasValue = true; return true; } - + accumulator = null; done = true; return false; diff --git a/src/main/java/ix/IxSequenceEqual.java b/src/main/java/ix/IxSequenceEqual.java index caf74cd..b26f1e5 100644 --- a/src/main/java/ix/IxSequenceEqual.java +++ b/src/main/java/ix/IxSequenceEqual.java @@ -21,11 +21,11 @@ final class IxSequenceEqual extends IxSource { final Iterable other; - - final Pred2 comparer; - - public IxSequenceEqual(Iterable source, Iterable other, - Pred2 comparer) { + + final IxPredicate2 comparer; + + IxSequenceEqual(Iterable source, Iterable other, + IxPredicate2 comparer) { super(source); this.other = other; this.comparer = comparer; @@ -35,15 +35,15 @@ public IxSequenceEqual(Iterable source, Iterable other, public Iterator iterator() { return new SequenceEqualIterator(source.iterator(), other.iterator(), comparer); } - + static final class SequenceEqualIterator extends IxSourceIterator { - + final Iterator other; - final Pred2 comparer; - - public SequenceEqualIterator(Iterator it, Iterator other, - Pred2 comparer) { + final IxPredicate2 comparer; + + SequenceEqualIterator(Iterator it, Iterator other, + IxPredicate2 comparer) { super(it); this.other = other; this.comparer = comparer; @@ -51,19 +51,19 @@ public SequenceEqualIterator(Iterator it, Iterator other, @Override protected boolean moveNext() { - + Iterator it2 = it; - + while (it2.hasNext()) { - + T v = it2.next(); - + if (other.hasNext()) { T u = other.next(); - + if (!comparer.test(v, u)) { - + value = false; hasValue = true; done = true; @@ -82,14 +82,14 @@ protected boolean moveNext() { done = true; return true; } - + value = true; hasValue = true; done = true; return true; } - - + + } } diff --git a/src/main/java/ix/IxSkip.java b/src/main/java/ix/IxSkip.java index 2c319d2..ef56e1f 100644 --- a/src/main/java/ix/IxSkip.java +++ b/src/main/java/ix/IxSkip.java @@ -21,8 +21,8 @@ final class IxSkip extends IxSource { final int n; - - public IxSkip(Iterable source, int n) { + + IxSkip(Iterable source, int n) { super(source); this.n = n; } @@ -35,7 +35,8 @@ public Iterator iterator() { static final class SkipIterator extends IxSourceIterator { int n; - public SkipIterator(Iterator it, int n) { + + SkipIterator(Iterator it, int n) { super(it); this.n = n; } @@ -43,7 +44,7 @@ public SkipIterator(Iterator it, int n) { protected boolean moveNext() { Iterator it = this.it; int n = this.n; - + if (n != 0) { while (n != 0) { if (it.hasNext()) { @@ -64,7 +65,7 @@ protected boolean moveNext() { done = true; return false; } - - + + } } diff --git a/src/main/java/ix/IxSkipLast.java b/src/main/java/ix/IxSkipLast.java index b8cbc31..09e4aa2 100644 --- a/src/main/java/ix/IxSkipLast.java +++ b/src/main/java/ix/IxSkipLast.java @@ -21,8 +21,8 @@ final class IxSkipLast extends IxSource { final int n; - - public IxSkipLast(Iterable source, int n) { + + IxSkipLast(Iterable source, int n) { super(source); this.n = n; } @@ -31,14 +31,14 @@ public IxSkipLast(Iterable source, int n) { public Iterator iterator() { return new SkipLastIterator(source.iterator(), n); } - + static final class SkipLastIterator extends IxSourceQueuedIterator { final int n; - + int size; - - public SkipLastIterator(Iterator it, int n) { + + SkipLastIterator(Iterator it, int n) { super(it); this.n = n; } @@ -47,13 +47,13 @@ public SkipLastIterator(Iterator it, int n) { protected boolean moveNext() { int s = size; int n = this.n; - + Iterator it = this.it; if (!it.hasNext()) { done = true; return false; } - + if (s != n) { while (s != n) { offer(toObject(it.next())); @@ -70,9 +70,9 @@ protected boolean moveNext() { offer(toObject(it.next())); hasValue = true; - + return true; } - + } } diff --git a/src/main/java/ix/IxSkipWhile.java b/src/main/java/ix/IxSkipWhile.java index d17f91c..158ea62 100644 --- a/src/main/java/ix/IxSkipWhile.java +++ b/src/main/java/ix/IxSkipWhile.java @@ -20,9 +20,9 @@ final class IxSkipWhile extends IxSource { - final Pred predicate; - - public IxSkipWhile(Iterable source, Pred predicate) { + final IxPredicate predicate; + + IxSkipWhile(Iterable source, IxPredicate predicate) { super(source); this.predicate = predicate; } @@ -31,21 +31,21 @@ public IxSkipWhile(Iterable source, Pred predicate) { public Iterator iterator() { return new SkipWhileIterator(source.iterator(), predicate); } - + static final class SkipWhileIterator extends IxSourceIterator { - final Pred predicate; + final IxPredicate predicate; + + boolean passThrough; - boolean passthrough; - - public SkipWhileIterator(Iterator it, Pred predicate) { + SkipWhileIterator(Iterator it, IxPredicate predicate) { super(it); this.predicate = predicate; } @Override protected boolean moveNext() { - if (passthrough) { + if (passThrough) { if (it.hasNext()) { hasValue = true; value = it.next(); @@ -54,21 +54,21 @@ protected boolean moveNext() { done = true; return false; } - + while (it.hasNext()) { T v = it.next(); if (!predicate.test(v)) { - passthrough = true; + passThrough = true; hasValue = true; value = v; return true; } } - + done = true; return false; } - + @Override public void remove() { it.remove(); diff --git a/src/main/java/ix/IxSource.java b/src/main/java/ix/IxSource.java index 4ef6f3c..f3a0364 100644 --- a/src/main/java/ix/IxSource.java +++ b/src/main/java/ix/IxSource.java @@ -17,16 +17,16 @@ package ix; /** - * Abstract base class for Ix operators that take a source Iterable. + * Abstract base class for Ix operators that take a source Iterable. * @param the source value type * @param the result value type */ abstract class IxSource extends Ix { protected final Iterable source; - - public IxSource(Iterable source) { + + IxSource(Iterable source) { this.source = source; } - + } diff --git a/src/main/java/ix/IxSourceIterator.java b/src/main/java/ix/IxSourceIterator.java index e7b87c6..da541fb 100644 --- a/src/main/java/ix/IxSourceIterator.java +++ b/src/main/java/ix/IxSourceIterator.java @@ -29,7 +29,7 @@ public abstract class IxSourceIterator extends IxBaseIterator { /** The upstream's iterator. */ protected final Iterator it; - + public IxSourceIterator(Iterator it) { this.it = it; } diff --git a/src/main/java/ix/IxSourceQueuedIterator.java b/src/main/java/ix/IxSourceQueuedIterator.java index 05e10e7..c1584a5 100644 --- a/src/main/java/ix/IxSourceQueuedIterator.java +++ b/src/main/java/ix/IxSourceQueuedIterator.java @@ -18,8 +18,6 @@ import java.util.Iterator; -import rx.functions.*; - /** * A base iterator that extends a custom ArrayDeque, references an upstream iterator * and manages the state between hasNext() and the next() calls; plus defines @@ -28,21 +26,21 @@ * @param the queued element types * @param the result value type */ -public abstract class IxSourceQueuedIterator +public abstract class IxSourceQueuedIterator extends IxSourceIterator { - protected static final Object NULL = new Object(); - + protected static final Object NULL = new Object(); + private Object[] array; - + private int producerIndex; - + private int consumerIndex; - + public IxSourceQueuedIterator(Iterator it) { super(it); } - + /** * Cast the value into an object and turn * a null value into a sentinel value. @@ -53,7 +51,7 @@ public IxSourceQueuedIterator(Iterator it) { protected final Object toObject(U value) { return value != null ? value : NULL; } - + /** * Cast the object back to a typed value. * @param value the value to cast back @@ -63,7 +61,7 @@ protected final Object toObject(U value) { protected final U fromObject(Object value) { return value == NULL ? null : (U)value; } - + protected final boolean offer(Object value) { if (value == null) { throw new NullPointerException("The queue doesn't support null values."); @@ -75,7 +73,7 @@ protected final boolean offer(Object value) { } int mask = a.length - 1; int pi = producerIndex; - + int offset = pi & mask; if (a[offset] != null) { int newLen = mask * 2 + 2; @@ -93,14 +91,14 @@ protected final boolean offer(Object value) { } return true; } - + protected final Object poll() { Object[] a = array; if (a != null) { int m = a.length - 1; int ci = consumerIndex; int offset = ci & m; - + Object v = a[offset]; if (v != null) { a[offset] = null; @@ -110,30 +108,30 @@ protected final Object poll() { } return null; } - + protected final Object peek() { Object[] a = array; if (a != null) { int m = a.length - 1; int ci = consumerIndex; int offset = ci & m; - + return a[offset]; } return null; } - + protected final boolean isEmpty() { return consumerIndex == producerIndex; } - + protected final void clear() { array = null; consumerIndex = 0; producerIndex = 0; } - - protected final void foreach(Action2 action, S state) { + + protected final void foreach(IxConsumer2 action, S state) { Object[] a = array; if (a != null) { int m = a.length - 1; @@ -141,7 +139,7 @@ protected final void foreach(Action2 action, S state) { for (int ci = consumerIndex; ci != pi; ci++) { int offset = ci & m; Object o = a[offset]; - action.call(fromObject(o), state); + action.accept(fromObject(o), state); } } } diff --git a/src/main/java/ix/IxSplit.java b/src/main/java/ix/IxSplit.java index bee3e0a..117e8d6 100644 --- a/src/main/java/ix/IxSplit.java +++ b/src/main/java/ix/IxSplit.java @@ -21,10 +21,10 @@ final class IxSplit extends Ix { final String string; - + final String by; - - public IxSplit(String string, String by) { + + IxSplit(String string, String by) { this.string = string; this.by = by; } @@ -36,21 +36,21 @@ public Iterator iterator() { static final class SplitIterator extends IxBaseIterator { final String string; - + final String by; int index; - public SplitIterator(String string, String by) { + SplitIterator(String string, String by) { this.string = string; this.by = by; } - + @Override protected boolean moveNext() { int i = index; int j = string.indexOf(by, i); - + if (j < 0) { value = string.substring(i); hasValue = true; diff --git a/src/main/java/ix/IxSumInt.java b/src/main/java/ix/IxSumInt.java index 897885e..bb312d6 100644 --- a/src/main/java/ix/IxSumInt.java +++ b/src/main/java/ix/IxSumInt.java @@ -20,7 +20,7 @@ final class IxSumInt extends IxSource { - public IxSumInt(Iterable source) { + IxSumInt(Iterable source) { super(source); } @@ -31,7 +31,7 @@ public Iterator iterator() { static final class SumIntIterator extends IxSourceIterator { - public SumIntIterator(Iterator it) { + SumIntIterator(Iterator it) { super(it); } @@ -47,12 +47,12 @@ protected boolean moveNext() { while (it.hasNext()) { sum += it.next(); } - + value = sum; hasValue = true; done = true; return true; } - + } } diff --git a/src/main/java/ix/IxSumLong.java b/src/main/java/ix/IxSumLong.java index 8a6e2c6..6e9f7ab 100644 --- a/src/main/java/ix/IxSumLong.java +++ b/src/main/java/ix/IxSumLong.java @@ -20,7 +20,7 @@ final class IxSumLong extends IxSource { - public IxSumLong(Iterable source) { + IxSumLong(Iterable source) { super(source); } @@ -31,7 +31,7 @@ public Iterator iterator() { static final class SumLongIterator extends IxSourceIterator { - public SumLongIterator(Iterator it) { + SumLongIterator(Iterator it) { super(it); } @@ -47,12 +47,12 @@ protected boolean moveNext() { while (it.hasNext()) { sum += it.next(); } - + value = sum; hasValue = true; done = true; return true; } - + } } diff --git a/src/main/java/ix/IxSupplier.java b/src/main/java/ix/IxSupplier.java new file mode 100644 index 0000000..23df3fb --- /dev/null +++ b/src/main/java/ix/IxSupplier.java @@ -0,0 +1,29 @@ +/* + * Copyright 2011-2016 David Karnok + * + * 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 ix; + +/** + * A function callback with no inputs and one output value. + * @param the output value type + */ +public interface IxSupplier { + /** + * Calls the function which returns a value. + * @return the output value + */ + R get(); +} diff --git a/src/main/java/ix/IxSwitchIfEmpty.java b/src/main/java/ix/IxSwitchIfEmpty.java index bd43a9c..aa4d6dd 100644 --- a/src/main/java/ix/IxSwitchIfEmpty.java +++ b/src/main/java/ix/IxSwitchIfEmpty.java @@ -22,7 +22,7 @@ final class IxSwitchIfEmpty extends IxSource { final Iterable other; - public IxSwitchIfEmpty(Iterable source, Iterable other) { + IxSwitchIfEmpty(Iterable source, Iterable other) { super(source); this.other = other; } @@ -40,7 +40,7 @@ static final class SwitchIfEmptyIterator extends IxSourceIterator { boolean nonEmpty; - public SwitchIfEmptyIterator(Iterator it, Iterable other) { + SwitchIfEmptyIterator(Iterator it, Iterable other) { super(it); this.other = other; } @@ -57,7 +57,7 @@ protected boolean moveNext() { done = true; return false; } - + if (nonEmpty) { if (it.hasNext()) { value = it.next(); @@ -67,14 +67,14 @@ protected boolean moveNext() { done = true; return false; } - + if (it.hasNext()) { nonEmpty = true; value = it.next(); hasValue = true; return true; } - + ot = other.iterator(); otherIterator = ot; if (ot.hasNext()) { diff --git a/src/main/java/ix/IxTake.java b/src/main/java/ix/IxTake.java index 93e0ca6..698171c 100644 --- a/src/main/java/ix/IxTake.java +++ b/src/main/java/ix/IxTake.java @@ -21,8 +21,8 @@ final class IxTake extends IxSource { final int n; - - public IxTake(Iterable source, int n) { + + IxTake(Iterable source, int n) { super(source); this.n = n; } @@ -31,15 +31,16 @@ public IxTake(Iterable source, int n) { public Iterator iterator() { return new TakeIterator(source.iterator(), n); } - + static final class TakeIterator extends IxSourceIterator { int n; - public TakeIterator(Iterator it, int n) { + + TakeIterator(Iterator it, int n) { super(it); this.n = n; } - + @Override protected boolean moveNext() { int n = this.n; @@ -47,14 +48,14 @@ protected boolean moveNext() { done = true; return false; } - + value = it.next(); hasValue = true; this.n = n - 1; - + return true; } - + @Override public void remove() { it.remove(); diff --git a/src/main/java/ix/IxTakeLast.java b/src/main/java/ix/IxTakeLast.java index 35bff0a..278a354 100644 --- a/src/main/java/ix/IxTakeLast.java +++ b/src/main/java/ix/IxTakeLast.java @@ -21,8 +21,8 @@ final class IxTakeLast extends IxSource { final int n; - - public IxTakeLast(Iterable source, int n) { + + IxTakeLast(Iterable source, int n) { super(source); this.n = n; } @@ -31,16 +31,16 @@ public IxTakeLast(Iterable source, int n) { public Iterator iterator() { return new TakeLastIterator(source.iterator(), n); } - + static final class TakeLastIterator extends IxSourceQueuedIterator { int n; - - public TakeLastIterator(Iterator it, int n) { + + TakeLastIterator(Iterator it, int n) { super(it); this.n = n; } - + @Override protected boolean moveNext() { @@ -57,7 +57,7 @@ protected boolean moveNext() { } this.n = n; } - + Object o = poll(); if (o != null) { value = fromObject(o); diff --git a/src/main/java/ix/IxTakeUntil.java b/src/main/java/ix/IxTakeUntil.java index 38f61fa..ff89ad4 100644 --- a/src/main/java/ix/IxTakeUntil.java +++ b/src/main/java/ix/IxTakeUntil.java @@ -20,9 +20,9 @@ final class IxTakeUntil extends IxSource { - final Pred predicate; - - public IxTakeUntil(Iterable source, Pred predicate) { + final IxPredicate predicate; + + IxTakeUntil(Iterable source, IxPredicate predicate) { super(source); this.predicate = predicate; } @@ -31,12 +31,12 @@ public IxTakeUntil(Iterable source, Pred predicate) { public Iterator iterator() { return new TakeUntilIterator(source.iterator(), predicate); } - + static final class TakeUntilIterator extends IxSourceIterator { - final Pred predicate; + final IxPredicate predicate; - public TakeUntilIterator(Iterator it, Pred predicate) { + TakeUntilIterator(Iterator it, IxPredicate predicate) { super(it); this.predicate = predicate; } @@ -55,7 +55,7 @@ protected boolean moveNext() { done = true; return false; } - + @Override public void remove() { it.remove(); diff --git a/src/main/java/ix/IxTakeWhile.java b/src/main/java/ix/IxTakeWhile.java index 438f966..5da9258 100644 --- a/src/main/java/ix/IxTakeWhile.java +++ b/src/main/java/ix/IxTakeWhile.java @@ -20,9 +20,9 @@ final class IxTakeWhile extends IxSource { - final Pred predicate; - - public IxTakeWhile(Iterable source, Pred predicate) { + final IxPredicate predicate; + + IxTakeWhile(Iterable source, IxPredicate predicate) { super(source); this.predicate = predicate; } @@ -31,12 +31,12 @@ public IxTakeWhile(Iterable source, Pred predicate) { public Iterator iterator() { return new TakeWhileIterator(source.iterator(), predicate); } - + static final class TakeWhileIterator extends IxSourceIterator { - final Pred predicate; + final IxPredicate predicate; - public TakeWhileIterator(Iterator it, Pred predicate) { + TakeWhileIterator(Iterator it, IxPredicate predicate) { super(it); this.predicate = predicate; } @@ -56,7 +56,7 @@ protected boolean moveNext() { done = true; return false; } - + @Override public void remove() { it.remove(); diff --git a/src/main/java/ix/IxToMap.java b/src/main/java/ix/IxToMap.java index deb8144..f9c3527 100644 --- a/src/main/java/ix/IxToMap.java +++ b/src/main/java/ix/IxToMap.java @@ -18,15 +18,13 @@ import java.util.*; -import rx.functions.Func1; - final class IxToMap extends IxSource> { - final Func1 keySelector; - - final Func1 valueSelector; + final IxFunction keySelector; + + final IxFunction valueSelector; - public IxToMap(Iterable source, Func1 keySelector, Func1 valueSelector) { + IxToMap(Iterable source, IxFunction keySelector, IxFunction valueSelector) { super(source); this.keySelector = keySelector; this.valueSelector = valueSelector; @@ -36,14 +34,14 @@ public IxToMap(Iterable source, Func1 keySelector, Fu public Iterator> iterator() { return new ToMapIterator(source.iterator(), keySelector, valueSelector); } - + static final class ToMapIterator extends IxSourceIterator> { - final Func1 keySelector; - - final Func1 valueSelector; + final IxFunction keySelector; - public ToMapIterator(Iterator it, Func1 keySelector, Func1 valueSelector) { + final IxFunction valueSelector; + + ToMapIterator(Iterator it, IxFunction keySelector, IxFunction valueSelector) { super(it); this.keySelector = keySelector; this.valueSelector = valueSelector; @@ -52,23 +50,23 @@ public ToMapIterator(Iterator it, Func1 keySelector, @Override protected boolean moveNext() { Iterator it = this.it; - - Func1 keySelector = this.keySelector; - - Func1 valueSelector = this.valueSelector; - + + IxFunction keySelector = this.keySelector; + + IxFunction valueSelector = this.valueSelector; + Map result = new HashMap(); - + while (it.hasNext()) { T t = it.next(); - - K k = keySelector.call(t); - - V v = valueSelector.call(t); - + + K k = keySelector.apply(t); + + V v = valueSelector.apply(t); + result.put(k, v); } - + value = result; hasValue = true; done = true; diff --git a/src/main/java/ix/IxToMultimap.java b/src/main/java/ix/IxToMultimap.java index b4baecd..a01c5db 100644 --- a/src/main/java/ix/IxToMultimap.java +++ b/src/main/java/ix/IxToMultimap.java @@ -18,15 +18,13 @@ import java.util.*; -import rx.functions.Func1; - final class IxToMultimap extends IxSource>> { - final Func1 keySelector; - - final Func1 valueSelector; + final IxFunction keySelector; + + final IxFunction valueSelector; - public IxToMultimap(Iterable source, Func1 keySelector, Func1 valueSelector) { + IxToMultimap(Iterable source, IxFunction keySelector, IxFunction valueSelector) { super(source); this.keySelector = keySelector; this.valueSelector = valueSelector; @@ -36,14 +34,14 @@ public IxToMultimap(Iterable source, Func1 keySelecto public Iterator>> iterator() { return new ToMapIterator(source.iterator(), keySelector, valueSelector); } - + static final class ToMapIterator extends IxSourceIterator>> { - final Func1 keySelector; - - final Func1 valueSelector; + final IxFunction keySelector; + + final IxFunction valueSelector; - public ToMapIterator(Iterator it, Func1 keySelector, Func1 valueSelector) { + ToMapIterator(Iterator it, IxFunction keySelector, IxFunction valueSelector) { super(it); this.keySelector = keySelector; this.valueSelector = valueSelector; @@ -52,29 +50,29 @@ public ToMapIterator(Iterator it, Func1 keySelector, @Override protected boolean moveNext() { Iterator it = this.it; - - Func1 keySelector = this.keySelector; - - Func1 valueSelector = this.valueSelector; - + + IxFunction keySelector = this.keySelector; + + IxFunction valueSelector = this.valueSelector; + Map> result = new HashMap>(); - + while (it.hasNext()) { T t = it.next(); - - K k = keySelector.call(t); - + + K k = keySelector.apply(t); + Collection coll = result.get(k); if (coll == null) { coll = new ArrayList(); result.put(k, coll); } - - V v = valueSelector.call(t); - + + V v = valueSelector.apply(t); + coll.add(v); } - + value = result; hasValue = true; done = true; diff --git a/src/main/java/ix/IxToSet.java b/src/main/java/ix/IxToSet.java index 7924ee3..b3e6983 100644 --- a/src/main/java/ix/IxToSet.java +++ b/src/main/java/ix/IxToSet.java @@ -20,7 +20,7 @@ final class IxToSet extends IxSource> { - public IxToSet(Iterable source) { + IxToSet(Iterable source) { super(source); } @@ -28,24 +28,24 @@ public IxToSet(Iterable source) { public Iterator> iterator() { return new ToSetIterator(source.iterator()); } - + static final class ToSetIterator extends IxSourceIterator> { - public ToSetIterator(Iterator it) { + ToSetIterator(Iterator it) { super(it); } @Override protected boolean moveNext() { - + Set set = new HashSet(); Iterator it = this.it; - + while (it.hasNext()) { set.add(it.next()); } - + value = set; hasValue = true; done = true; diff --git a/src/main/java/ix/IxTransform.java b/src/main/java/ix/IxTransform.java index 797f4d9..a6b8e1b 100644 --- a/src/main/java/ix/IxTransform.java +++ b/src/main/java/ix/IxTransform.java @@ -18,8 +18,6 @@ import java.util.Iterator; -import rx.functions.Action1; - /** * Functional interface that allows transforming an * upstream Iterator for each downstream next() call. @@ -45,10 +43,10 @@ public interface IxTransform { int STOP = 0; - + int NEXT = 1; - + int LAST = 2; - - int moveNext(Iterator it, Action1 consumer); + + int moveNext(Iterator it, IxConsumer consumer); } diff --git a/src/main/java/ix/IxTransformer.java b/src/main/java/ix/IxTransformer.java index ebce7ad..aeebe1f 100644 --- a/src/main/java/ix/IxTransformer.java +++ b/src/main/java/ix/IxTransformer.java @@ -18,13 +18,11 @@ import java.util.Iterator; -import rx.functions.Action1; - final class IxTransformer extends IxSource { final IxTransform transform; - - public IxTransformer(Iterable source, IxTransform transform) { + + IxTransformer(Iterable source, IxTransform transform) { super(source); this.transform = transform; } @@ -35,15 +33,15 @@ public Iterator iterator() { } static final class TransformerIterator extends IxSourceIterator - implements Action1 { - + implements IxConsumer { + final IxTransform transform; - public TransformerIterator(Iterator it, IxTransform transform) { + TransformerIterator(Iterator it, IxTransform transform) { super(it); this.transform = transform; } - + @Override protected boolean moveNext() { int m = transform.moveNext(it, this); @@ -61,9 +59,9 @@ protected boolean moveNext() { } return true; } - + @Override - public void call(R t) { + public void accept(R t) { if (hasValue) { throw new IllegalStateException("Value already set in this turn!"); } diff --git a/src/main/java/ix/IxUnion.java b/src/main/java/ix/IxUnion.java index 03e865b..2961f9d 100644 --- a/src/main/java/ix/IxUnion.java +++ b/src/main/java/ix/IxUnion.java @@ -22,30 +22,30 @@ final class IxUnion extends IxSource { final Iterable other; - public IxUnion(Iterable source, Iterable other) { + IxUnion(Iterable source, Iterable other) { super(source); this.other = other; } - + @Override public Iterator iterator() { return new UnionIterator(source.iterator(), other.iterator()); } static final class UnionIterator extends IxSourceIterator { - + final Iterator other; final Set set; - + boolean second; - - public UnionIterator(Iterator it, Iterator other) { + + UnionIterator(Iterator it, Iterator other) { super(it); this.other = other; this.set = new HashSet(); } - + @Override protected boolean moveNext() { Set set = this.set; @@ -60,11 +60,11 @@ protected boolean moveNext() { return true; } } - + done = true; return false; } - + Iterator it = this.it; while (it.hasNext()) { T v = it.next(); @@ -74,7 +74,7 @@ protected boolean moveNext() { return true; } } - + second = true; } } diff --git a/src/main/java/ix/IxWindow.java b/src/main/java/ix/IxWindow.java index 5a50837..c0632dc 100644 --- a/src/main/java/ix/IxWindow.java +++ b/src/main/java/ix/IxWindow.java @@ -24,7 +24,7 @@ final class IxWindow extends IxSource> { static final Object NULL = new Object(); - public IxWindow(Iterable source, int size) { + IxWindow(Iterable source, int size) { super(source); this.size = size; } @@ -33,20 +33,20 @@ public IxWindow(Iterable source, int size) { public Iterator> iterator() { return new WindowIterator(source.iterator(), size); } - + static final class WindowIterator extends IxSourceIterator> { final int size; - + int index; WindowIterable current; - - public WindowIterator(Iterator it, int size) { + + WindowIterator(Iterator it, int size) { super(it); this.size = size; } - + @Override protected boolean moveNext() { int i = index; @@ -55,9 +55,9 @@ protected boolean moveNext() { done = true; return false; } - + T v = it.next(); - + WindowIterable c; if (i++ == 0) { if (i == size) { @@ -72,24 +72,24 @@ protected boolean moveNext() { hasValue = true; return true; } - + current.iterator.queue.offer(v != null ? v : NULL); - + if (i == size) { i = 0; } } } - + boolean moveInner() { if (!it.hasNext()) { return false; } - + T v = it.next(); - + current.iterator.queue.offer(v != null ? v : NULL); - + int i = index + 1; if (i == size) { current = null; @@ -104,10 +104,10 @@ boolean moveInner() { static final class WindowIterable extends Ix { final WindowInnerIterator iterator; - + boolean once; - - public WindowIterable(WindowIterator parent, int size) { + + WindowIterable(WindowIterator parent, int size) { this.iterator = new WindowInnerIterator(parent, size); } @@ -120,21 +120,21 @@ public Iterator iterator() { throw new IllegalStateException("This Window Ix iterable can be consumed only once."); } } - + static final class WindowInnerIterator extends IxBaseIterator { - + final WindowIterator parent; - + final ArrayDeque queue; int remaining; - - public WindowInnerIterator(WindowIterator parent, int remaining) { + + WindowInnerIterator(WindowIterator parent, int remaining) { this.parent = parent; this.queue = new ArrayDeque(); this.remaining = remaining; } - + @SuppressWarnings("unchecked") @Override protected boolean moveNext() { @@ -144,7 +144,7 @@ protected boolean moveNext() { return false; } Object o = queue.poll(); - + if (o == null) { if (!parent.moveInner()) { done = true; @@ -152,12 +152,12 @@ protected boolean moveNext() { } o = queue.poll(); } - + value = o == NULL ? null : (T)o; hasValue = true; remaining = r - 1; return true; } } - + } diff --git a/src/main/java/ix/IxWindowOverlap.java b/src/main/java/ix/IxWindowOverlap.java index 83f2b5f..21ae806 100644 --- a/src/main/java/ix/IxWindowOverlap.java +++ b/src/main/java/ix/IxWindowOverlap.java @@ -21,12 +21,12 @@ final class IxWindowOverlap extends IxSource> { final int size; - + final int skip; - + static final Object NULL = new Object(); - - public IxWindowOverlap(Iterable source, int size, int skip) { + + IxWindowOverlap(Iterable source, int size, int skip) { super(source); this.size = size; this.skip = skip; @@ -36,29 +36,29 @@ public IxWindowOverlap(Iterable source, int size, int skip) { public Iterator> iterator() { return new WindowIterator(source.iterator(), size, skip); } - + static final class WindowIterator extends IxSourceIterator> { final int size; - + final int skip; - + final Queue> queue; - + final Queue> windows; - + int index; - + int headSize; - - public WindowIterator(Iterator it, int size, int skip) { + + WindowIterator(Iterator it, int size, int skip) { super(it); this.size = size; this.skip = skip; this.queue = new ArrayDeque>(); this.windows = new ArrayDeque>(); } - + @Override protected boolean moveNext() { WindowIterable w = queue.poll(); @@ -69,19 +69,19 @@ protected boolean moveNext() { } w = queue.poll(); } - + value = w; hasValue = true; return true; } - + boolean moveMain() { int i = index; for (;;) { if (!it.hasNext()) { return false; } - + T v = it.next(); for (WindowIterable c : windows) { @@ -106,28 +106,28 @@ boolean moveMain() { c.iterator.offer(v); queue.offer(c); windows.offer(c); - + return true; } - + if (i == skip) { i = 0; } } } - + boolean moveInner() { int i = index; if (!it.hasNext()) { return false; } - + T v = it.next(); for (WindowIterable c : windows) { c.iterator.offer(v); } - + int j = headSize + 1; if (j == size) { windows.poll(); @@ -142,7 +142,7 @@ boolean moveInner() { queue.offer(c); windows.offer(c); } - + if (i == skip) { index = 0; } @@ -153,10 +153,10 @@ boolean moveInner() { static final class WindowIterable extends Ix { final WindowInnerIterator iterator; - + boolean once; - - public WindowIterable(WindowIterator parent, int size) { + + WindowIterable(WindowIterator parent, int size) { this.iterator = new WindowInnerIterator(parent); } @@ -169,18 +169,18 @@ public Iterator iterator() { throw new IllegalStateException("This Window Ix iterable can be consumed only once."); } } - + static final class WindowInnerIterator extends IxBaseIterator { - + final WindowIterator parent; - + final ArrayDeque queue; - - public WindowInnerIterator(WindowIterator parent) { + + WindowInnerIterator(WindowIterator parent) { this.parent = parent; this.queue = new ArrayDeque(); } - + @SuppressWarnings("unchecked") @Override protected boolean moveNext() { @@ -197,15 +197,15 @@ protected boolean moveNext() { return false; } } - + value = o == NULL ? null : (T)o; hasValue = true; return true; } - + void offer(T v) { queue.offer(v != null ? v : NULL); } } - + } diff --git a/src/main/java/ix/IxWindowSkip.java b/src/main/java/ix/IxWindowSkip.java index f3fcf6a..6e7f8d7 100644 --- a/src/main/java/ix/IxWindowSkip.java +++ b/src/main/java/ix/IxWindowSkip.java @@ -21,12 +21,12 @@ final class IxWindowSkip extends IxSource> { final int size; - + final int skip; - + static final Object NULL = new Object(); - public IxWindowSkip(Iterable source, int size, int skip) { + IxWindowSkip(Iterable source, int size, int skip) { super(source); this.size = size; this.skip = skip; @@ -36,23 +36,23 @@ public IxWindowSkip(Iterable source, int size, int skip) { public Iterator> iterator() { return new WindowIterator(source.iterator(), size, skip); } - + static final class WindowIterator extends IxSourceIterator> { final int size; - + int index; - + final int skip; WindowIterable current; - - public WindowIterator(Iterator it, int size, int skip) { + + WindowIterator(Iterator it, int size, int skip) { super(it); this.size = size; this.skip = skip; } - + @Override protected boolean moveNext() { int i = index; @@ -61,9 +61,9 @@ protected boolean moveNext() { done = true; return false; } - + T v = it.next(); - + if (i++ == 0) { index = i; WindowIterable c = new WindowIterable(this, size); @@ -73,26 +73,26 @@ protected boolean moveNext() { hasValue = true; return true; } - + WindowInnerIterator ci = current.iterator; - + if (ci.offered < size) { ci.offer(v); } - + if (i == skip) { i = 0; } } } - + boolean moveInner() { if (!it.hasNext()) { return false; } - + T v = it.next(); - + current.iterator.offer(v); index++; @@ -103,10 +103,10 @@ boolean moveInner() { static final class WindowIterable extends Ix { final WindowInnerIterator iterator; - + boolean once; - - public WindowIterable(WindowIterator parent, int size) { + + WindowIterable(WindowIterator parent, int size) { this.iterator = new WindowInnerIterator(parent, size); } @@ -119,23 +119,23 @@ public Iterator iterator() { throw new IllegalStateException("This Window Ix iterable can be consumed only once."); } } - + static final class WindowInnerIterator extends IxBaseIterator { - + final WindowIterator parent; - + final ArrayDeque queue; int remaining; - + int offered; - - public WindowInnerIterator(WindowIterator parent, int size) { + + WindowInnerIterator(WindowIterator parent, int size) { this.parent = parent; this.queue = new ArrayDeque(); this.remaining = size; } - + @SuppressWarnings("unchecked") @Override protected boolean moveNext() { @@ -145,7 +145,7 @@ protected boolean moveNext() { return false; } Object o = queue.poll(); - + if (o == null) { if (!parent.moveInner()) { done = true; @@ -153,17 +153,17 @@ protected boolean moveNext() { } o = queue.poll(); } - + value = o == NULL ? null : (T)o; hasValue = true; remaining = r - 1; return true; } - + void offer(T t) { offered++; queue.offer(t != null ? t : NULL); } } - + } diff --git a/src/main/java/ix/IxWrapper.java b/src/main/java/ix/IxWrapper.java index e8c0fac..53ab5b2 100644 --- a/src/main/java/ix/IxWrapper.java +++ b/src/main/java/ix/IxWrapper.java @@ -20,10 +20,10 @@ final class IxWrapper extends IxSource { - public IxWrapper(Iterable source) { + IxWrapper(Iterable source) { super(source); } - + @Override public Iterator iterator() { return source.iterator(); diff --git a/src/main/java/ix/IxZip2.java b/src/main/java/ix/IxZip2.java index 3027463..a7e1e6b 100644 --- a/src/main/java/ix/IxZip2.java +++ b/src/main/java/ix/IxZip2.java @@ -18,17 +18,15 @@ import java.util.Iterator; -import rx.functions.Func2; - final class IxZip2 extends Ix { final Iterable source1; final Iterable source2; - final Func2 zipper; - - public IxZip2(Iterable source1, Iterable source2, Func2 zipper) { + final IxFunction2 zipper; + + IxZip2(Iterable source1, Iterable source2, IxFunction2 zipper) { this.source1 = source1; this.source2 = source2; this.zipper = zipper; @@ -38,21 +36,21 @@ public IxZip2(Iterable source1, Iterable source2, Func2 iterator() { return new Zip2Iterator(source1.iterator(), source2.iterator(), zipper); } - + static final class Zip2Iterator extends IxBaseIterator { final Iterator source1; final Iterator source2; - final Func2 zipper; - - public Zip2Iterator(Iterator source1, Iterator source2, Func2 zipper) { + final IxFunction2 zipper; + + Zip2Iterator(Iterator source1, Iterator source2, IxFunction2 zipper) { this.source1 = source1; this.source2 = source2; this.zipper = zipper; } - + @Override protected boolean moveNext() { if (!source1.hasNext()) { @@ -61,18 +59,18 @@ protected boolean moveNext() { } T1 t1 = source1.next(); - + if (!source2.hasNext()) { done = true; return false; } - + T2 t2 = source2.next(); - value = zipper.call(t1, t2); + value = zipper.apply(t1, t2); hasValue = true; return true; } - + } } diff --git a/src/main/java/ix/IxZip3.java b/src/main/java/ix/IxZip3.java index 99b23e4..b45c4ce 100644 --- a/src/main/java/ix/IxZip3.java +++ b/src/main/java/ix/IxZip3.java @@ -18,8 +18,6 @@ import java.util.Iterator; -import rx.functions.Func3; - final class IxZip3 extends Ix { final Iterable source1; @@ -27,10 +25,10 @@ final class IxZip3 extends Ix { final Iterable source3; - final Func3 zipper; - - public IxZip3(Iterable source1, Iterable source2, Iterable source3, - Func3 zipper) { + final IxFunction3 zipper; + + IxZip3(Iterable source1, Iterable source2, Iterable source3, + IxFunction3 zipper) { this.source1 = source1; this.source2 = source2; this.source3 = source3; @@ -39,7 +37,7 @@ public IxZip3(Iterable source1, Iterable source2, Iterable source3, @Override public Iterator iterator() { - return new Zip3Iterator(source1.iterator(), source2.iterator(), + return new Zip3Iterator(source1.iterator(), source2.iterator(), source3.iterator(), zipper); } @@ -51,16 +49,16 @@ static final class Zip3Iterator extends IxBaseIterator { final Iterator source3; - final Func3 zipper; - - public Zip3Iterator(Iterator source1, Iterator source2, Iterator source3, - Func3 zipper) { + final IxFunction3 zipper; + + Zip3Iterator(Iterator source1, Iterator source2, Iterator source3, + IxFunction3 zipper) { this.source1 = source1; this.source2 = source2; this.source3 = source3; this.zipper = zipper; } - + @Override protected boolean moveNext() { if (!source1.hasNext()) { @@ -83,11 +81,11 @@ protected boolean moveNext() { } T3 t3 = source3.next(); - - value = zipper.call(t1, t2, t3); + + value = zipper.apply(t1, t2, t3); hasValue = true; return true; } - + } } diff --git a/src/main/java/ix/IxZip4.java b/src/main/java/ix/IxZip4.java index b49d385..66929b9 100644 --- a/src/main/java/ix/IxZip4.java +++ b/src/main/java/ix/IxZip4.java @@ -18,8 +18,6 @@ import java.util.Iterator; -import rx.functions.Func4; - final class IxZip4 extends Ix { final Iterable source1; @@ -29,11 +27,11 @@ final class IxZip4 extends Ix { final Iterable source4; - final Func4 zipper; - - public IxZip4(Iterable source1, Iterable source2, + final IxFunction4 zipper; + + IxZip4(Iterable source1, Iterable source2, Iterable source3, Iterable source4, - Func4 zipper) { + IxFunction4 zipper) { this.source1 = source1; this.source2 = source2; this.source3 = source3; @@ -43,7 +41,7 @@ public IxZip4(Iterable source1, Iterable source2, @Override public Iterator iterator() { - return new Zip4Iterator(source1.iterator(), source2.iterator(), + return new Zip4Iterator(source1.iterator(), source2.iterator(), source3.iterator(), source4.iterator(), zipper); } @@ -57,18 +55,18 @@ static final class Zip4Iterator extends IxBaseIterator { final Iterator source4; - final Func4 zipper; - - public Zip4Iterator(Iterator source1, Iterator source2, Iterator source3, + final IxFunction4 zipper; + + Zip4Iterator(Iterator source1, Iterator source2, Iterator source3, Iterator source4, - Func4 zipper) { + IxFunction4 zipper) { this.source1 = source1; this.source2 = source2; this.source3 = source3; this.source4 = source4; this.zipper = zipper; } - + @Override protected boolean moveNext() { if (!source1.hasNext()) { @@ -98,11 +96,11 @@ protected boolean moveNext() { } T4 t4 = source4.next(); - - value = zipper.call(t1, t2, t3, t4); + + value = zipper.apply(t1, t2, t3, t4); hasValue = true; return true; } - + } } diff --git a/src/main/java/ix/IxZipArray.java b/src/main/java/ix/IxZipArray.java index d40bcef..22f396a 100644 --- a/src/main/java/ix/IxZipArray.java +++ b/src/main/java/ix/IxZipArray.java @@ -18,15 +18,13 @@ import java.util.Iterator; -import rx.functions.FuncN; - final class IxZipArray extends Ix { final Iterable[] sources; - - final FuncN zipper; - - public IxZipArray(Iterable[] sources, FuncN zipper) { + + final IxFunction zipper; + + IxZipArray(Iterable[] sources, IxFunction zipper) { this.sources = sources; this.zipper = zipper; } @@ -34,37 +32,37 @@ public IxZipArray(Iterable[] sources, FuncN zipper) { @SuppressWarnings("unchecked") @Override public Iterator iterator() { - + Iterable[] src = sources; - - Iterator[] itors = new Iterator[src.length]; - for (int i = 0; i < itors.length; i++) { - itors[i] = (Iterator)src[i].iterator(); + + Iterator[] iterators = new Iterator[src.length]; + for (int i = 0; i < iterators.length; i++) { + iterators[i] = (Iterator)src[i].iterator(); } - - return new ZipArrayIterator(itors, zipper); + + return new ZipArrayIterator(iterators, zipper); } - + static final class ZipArrayIterator extends IxBaseIterator { final Iterator[] sources; - final FuncN zipper; + final IxFunction zipper; - public ZipArrayIterator(Iterator[] sources, FuncN zipper) { + ZipArrayIterator(Iterator[] sources, IxFunction zipper) { this.sources = sources; this.zipper = zipper; } - + @SuppressWarnings("unchecked") @Override protected boolean moveNext() { - Iterator[] itors = sources; - int n = itors.length; + Iterator[] iterators = sources; + int n = iterators.length; T[] a = (T[])new Object[n]; - + for (int i = 0; i < n; i++) { - Iterator it = itors[i]; + Iterator it = iterators[i]; if (it.hasNext()) { a[i] = it.next(); } else { @@ -72,13 +70,13 @@ protected boolean moveNext() { return false; } } - - value = zipper.call(a); + + value = zipper.apply(a); hasValue = true; - + return true; } - + } } diff --git a/src/main/java/ix/IxZipIterable.java b/src/main/java/ix/IxZipIterable.java index f242df0..74b2681 100644 --- a/src/main/java/ix/IxZipIterable.java +++ b/src/main/java/ix/IxZipIterable.java @@ -19,15 +19,14 @@ import java.util.*; import ix.IxZipArray.ZipArrayIterator; -import rx.functions.FuncN; final class IxZipIterable extends Ix { final Iterable> sources; - - final FuncN zipper; - - public IxZipIterable(Iterable> sources, FuncN zipper) { + + final IxFunction zipper; + + IxZipIterable(Iterable> sources, IxFunction zipper) { this.sources = sources; this.zipper = zipper; } @@ -35,22 +34,22 @@ public IxZipIterable(Iterable> sources, FuncN @SuppressWarnings("unchecked") @Override public Iterator iterator() { - + Iterable[] src = new Iterable[8]; int n = 0; - + for (Iterable it : sources) { if (n == src.length) { src = Arrays.copyOf(src, n + (n >> 1)); } src[n++] = it; } - - Iterator[] itors = new Iterator[n]; + + Iterator[] iterators = new Iterator[n]; for (int i = 0; i < n; i++) { - itors[i] = (Iterator)src[i].iterator(); + iterators[i] = (Iterator)src[i].iterator(); } - - return new ZipArrayIterator(itors, zipper); + + return new ZipArrayIterator(iterators, zipper); } } diff --git a/src/main/java/ix/NumberToLongHelper.java b/src/main/java/ix/NumberToLongHelper.java index 41ee68b..92c268a 100644 --- a/src/main/java/ix/NumberToLongHelper.java +++ b/src/main/java/ix/NumberToLongHelper.java @@ -16,13 +16,11 @@ package ix; -import rx.functions.Func1; - -enum NumberToLongHelper implements Func1 { +enum NumberToLongHelper implements IxFunction { INSTANCE; - + @Override - public Long call(Number t1) { + public Long apply(Number t1) { return t1.longValue(); } } \ No newline at end of file diff --git a/src/main/java/ix/SelfComparator.java b/src/main/java/ix/SelfComparator.java index 75f3368..6e4aef0 100644 --- a/src/main/java/ix/SelfComparator.java +++ b/src/main/java/ix/SelfComparator.java @@ -22,7 +22,7 @@ enum SelfComparator implements Comparator { INSTANCE ; - + @SuppressWarnings("unchecked") @Override public int compare(Comparable o1, Comparable o2) { diff --git a/src/main/java/ix/ToListHelper.java b/src/main/java/ix/ToListHelper.java index 7c2781c..f894f51 100644 --- a/src/main/java/ix/ToListHelper.java +++ b/src/main/java/ix/ToListHelper.java @@ -18,38 +18,36 @@ import java.util.*; -import rx.functions.*; - -enum ToListHelper implements Func0>, Action2, Object>, Func1, Object[]> { +enum ToListHelper implements IxSupplier>, IxConsumer2, Object>, IxFunction, Object[]> { INSTANCE; @SuppressWarnings({ "rawtypes", "unchecked" }) - public static Func0> initialFactory() { - return (Func0)INSTANCE; + public static IxSupplier> initialFactory() { + return (IxSupplier)INSTANCE; } @SuppressWarnings({ "rawtypes", "unchecked" }) - public static Action2, T> collector() { - return (Action2)INSTANCE; + public static IxConsumer2, T> collector() { + return (IxConsumer2)INSTANCE; } @SuppressWarnings({ "rawtypes", "unchecked" }) - public static Func1, Object[]> toArray() { - return (Func1)INSTANCE; + public static IxFunction, Object[]> toArray() { + return (IxFunction)INSTANCE; } @Override - public void call(List t1, Object t2) { + public void accept(List t1, Object t2) { t1.add(t2); } @Override - public List call() { + public List get() { return new ArrayList(); } @Override - public Object[] call(List t) { + public Object[] apply(List t) { return t.toArray(); } - + } diff --git a/src/test/java/ix/AggregateTest.java b/src/test/java/ix/AggregateTest.java index 8b6d83b..6702184 100644 --- a/src/test/java/ix/AggregateTest.java +++ b/src/test/java/ix/AggregateTest.java @@ -22,25 +22,25 @@ public class AggregateTest { @Test public void normal() { - + Ix source = Ix.range(1, 10).sumInt(); - + IxTestHelper.assertValues(source, 55); } - + @Test public void just() { - + Ix source = Ix.just(1).sumInt(); - + IxTestHelper.assertValues(source, 1); } @Test public void empty() { - + Ix source = Ix.empty().sumInt(); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/AnyAllTest.java b/src/test/java/ix/AnyAllTest.java index 295e26b..82fe86d 100644 --- a/src/test/java/ix/AnyAllTest.java +++ b/src/test/java/ix/AnyAllTest.java @@ -22,85 +22,85 @@ public class AnyAllTest { @Test public void anyFound() { - Ix source = Ix.range(1, 5).any(new Pred() { + Ix source = Ix.range(1, 5).any(new IxPredicate() { @Override public boolean test(Integer v) { return v == 3; } }); - + IxTestHelper.assertValues(source, true); - + IxTestHelper.assertNoRemove(source); } @Test public void anyNotFound() { - Ix source = Ix.range(1, 5).any(new Pred() { + Ix source = Ix.range(1, 5).any(new IxPredicate() { @Override public boolean test(Integer v) { return v == 0; } }); - + IxTestHelper.assertValues(source, false); - + IxTestHelper.assertNoRemove(source); } - + @Test public void anyEmpty() { - Ix source = Ix.empty().any(new Pred() { + Ix source = Ix.empty().any(new IxPredicate() { @Override public boolean test(Integer v) { return v == 3; } }); - + IxTestHelper.assertValues(source, false); - + IxTestHelper.assertNoRemove(source); } @Test public void allTrue() { - Ix source = Ix.range(1, 5).all(new Pred() { + Ix source = Ix.range(1, 5).all(new IxPredicate() { @Override public boolean test(Integer v) { return v < 6; } }); - + IxTestHelper.assertValues(source, true); - + IxTestHelper.assertNoRemove(source); } @Test public void allFalse() { - Ix source = Ix.range(1, 5).all(new Pred() { + Ix source = Ix.range(1, 5).all(new IxPredicate() { @Override public boolean test(Integer v) { return false; } }); - + IxTestHelper.assertValues(source, false); - + IxTestHelper.assertNoRemove(source); } - + @Test public void allEmpty() { - Ix source = Ix.empty().all(new Pred() { + Ix source = Ix.empty().all(new IxPredicate() { @Override public boolean test(Integer v) { return false; } }); - + IxTestHelper.assertValues(source, true); - + IxTestHelper.assertNoRemove(source); } diff --git a/src/test/java/ix/AsComposeTest.java b/src/test/java/ix/AsComposeTest.java index 4e32ebb..d903725 100644 --- a/src/test/java/ix/AsComposeTest.java +++ b/src/test/java/ix/AsComposeTest.java @@ -18,39 +18,37 @@ import org.junit.*; -import rx.functions.Func1; - public class AsComposeTest { @Test public void normal() { - Integer value = Ix.range(1, 5).as(new Func1, Integer>() { + Integer value = Ix.range(1, 5).as(new IxFunction, Integer>() { @Override - public Integer call(Ix ix) { + public Integer apply(Ix ix) { return ix.first(); } }); - + Assert.assertEquals(1, value.intValue()); } - + @Test public void compose() { - Ix source = Ix.range(1, 5).compose(new Func1, Iterable>() { + Ix source = Ix.range(1, 5).compose(new IxFunction, Iterable>() { @Override - public Iterable call(Ix ix) { + public Iterable apply(Ix ix) { final int[] index = { 1 }; - return ix.map(new Func1() { + return ix.map(new IxFunction() { @Override - public String call(Integer v) { + public String apply(Integer v) { return v + "-" + (index[0]++); } }); } }); - + IxTestHelper.assertValues(source, "1-1", "2-2", "3-3", "4-4", "5-5"); - + IxTestHelper.assertValues(source, "1-1", "2-2", "3-3", "4-4", "5-5"); } } diff --git a/src/test/java/ix/AverageTest.java b/src/test/java/ix/AverageTest.java index f8303f5..16e2c91 100644 --- a/src/test/java/ix/AverageTest.java +++ b/src/test/java/ix/AverageTest.java @@ -23,54 +23,54 @@ public class AverageTest { @Test public void normalFloat() { Ix source = Ix.range(1, 5).averageFloat(); - + IxTestHelper.assertValues(source, 3f); - + IxTestHelper.assertNoRemove(source); } @Test public void justFloat() { Ix source = Ix.just(1).averageFloat(); - + IxTestHelper.assertValues(source, 1f); - + IxTestHelper.assertNoRemove(source); } @Test public void emptyFloat() { Ix source = Ix.empty().averageFloat(); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } - + @Test public void normalDouble() { Ix source = Ix.range(1, 5).averageDouble(); - + IxTestHelper.assertValues(source, 3d); - + IxTestHelper.assertNoRemove(source); } @Test public void justDouble() { Ix source = Ix.just(1).averageDouble(); - + IxTestHelper.assertValues(source, 1d); - + IxTestHelper.assertNoRemove(source); } @Test public void emptyDouble() { Ix source = Ix.empty().averageDouble(); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } diff --git a/src/test/java/ix/BufferTest.java b/src/test/java/ix/BufferTest.java index 9a2d28d..e88723f 100644 --- a/src/test/java/ix/BufferTest.java +++ b/src/test/java/ix/BufferTest.java @@ -26,39 +26,39 @@ public class BufferTest { @Test public void normal() { Ix> source = Ix.range(1, 5).buffer(2); - + IxTestHelper.assertValues(source, Arrays.asList(1, 2), Arrays.asList(3, 4), Arrays.asList(5)); - + IxTestHelper.assertNoRemove(source); } - + @SuppressWarnings("unchecked") @Test public void normalExactLength() { Ix> source = Ix.range(1, 6).buffer(2); - + IxTestHelper.assertValues(source, Arrays.asList(1, 2), Arrays.asList(3, 4), Arrays.asList(5, 6)); - + IxTestHelper.assertNoRemove(source); } - + @SuppressWarnings("unchecked") @Test public void normalSameSkip() { Ix> source = Ix.range(1, 5).buffer(2, 2); - + IxTestHelper.assertValues(source, Arrays.asList(1, 2), Arrays.asList(3, 4), Arrays.asList(5)); - + IxTestHelper.assertNoRemove(source); } - + @SuppressWarnings("unchecked") @Test public void normalSameSkipExactLength() { Ix> source = Ix.range(1, 6).buffer(2, 2); - + IxTestHelper.assertValues(source, Arrays.asList(1, 2), Arrays.asList(3, 4), Arrays.asList(5, 6)); - + IxTestHelper.assertNoRemove(source); } @@ -66,9 +66,9 @@ public void normalSameSkipExactLength() { @Test public void normalSkip() { Ix> source = Ix.range(1, 5).buffer(2, 3); - + IxTestHelper.assertValues(source, Arrays.asList(1, 2), Arrays.asList(4, 5)); - + IxTestHelper.assertNoRemove(source); } @@ -76,9 +76,9 @@ public void normalSkip() { @Test public void normalSkipShorter() { Ix> source = Ix.range(1, 4).buffer(2, 3); - + IxTestHelper.assertValues(source, Arrays.asList(1, 2), Arrays.asList(4)); - + IxTestHelper.assertNoRemove(source); } @@ -86,9 +86,9 @@ public void normalSkipShorter() { @Test public void normalSkipShortest() { Ix> source = Ix.range(1, 3).buffer(2, 3); - + IxTestHelper.assertValues(source, Arrays.asList(1, 2)); - + IxTestHelper.assertNoRemove(source); } @@ -96,67 +96,67 @@ public void normalSkipShortest() { @Test public void normalOverlap() { Ix> source = Ix.range(1, 5).buffer(2, 1); - - IxTestHelper.assertValues(source, - Arrays.asList(1, 2), - Arrays.asList(2, 3), - Arrays.asList(3, 4), - Arrays.asList(4, 5), + + IxTestHelper.assertValues(source, + Arrays.asList(1, 2), + Arrays.asList(2, 3), + Arrays.asList(3, 4), + Arrays.asList(4, 5), Arrays.asList(5)); - + IxTestHelper.assertNoRemove(source); } - + @SuppressWarnings("unchecked") @Test public void normalOverlapLonger() { Ix> source = Ix.range(1, 10).buffer(3, 1); - - IxTestHelper.assertValues(source, - Arrays.asList(1, 2, 3), - Arrays.asList(2, 3, 4), - Arrays.asList(3, 4, 5), - Arrays.asList(4, 5, 6), - Arrays.asList(5, 6, 7), - Arrays.asList(6, 7, 8), - Arrays.asList(7, 8, 9), - Arrays.asList(8, 9, 10), - Arrays.asList(9, 10), + + IxTestHelper.assertValues(source, + Arrays.asList(1, 2, 3), + Arrays.asList(2, 3, 4), + Arrays.asList(3, 4, 5), + Arrays.asList(4, 5, 6), + Arrays.asList(5, 6, 7), + Arrays.asList(6, 7, 8), + Arrays.asList(7, 8, 9), + Arrays.asList(8, 9, 10), + Arrays.asList(9, 10), Arrays.asList(10) ); - + IxTestHelper.assertNoRemove(source); } - + @SuppressWarnings("unchecked") @Test public void normalOverlapSorter() { Ix> source = Ix.range(1, 2).buffer(3, 2); - - IxTestHelper.assertValues(source, + + IxTestHelper.assertValues(source, Arrays.asList(1, 2) ); - + IxTestHelper.assertNoRemove(source); } - + @SuppressWarnings("unchecked") @Test public void normalOverlapEmpty() { Ix> source = Ix.empty().buffer(3, 2); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } - + @SuppressWarnings("unchecked") @Test public void normalOverlapJust() { Ix> source = Ix.just(1).buffer(3, 2); - + IxTestHelper.assertValues(source, Arrays.asList(1)); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/CharactersTest.java b/src/test/java/ix/CharactersTest.java index c269c50..01bbf45 100644 --- a/src/test/java/ix/CharactersTest.java +++ b/src/test/java/ix/CharactersTest.java @@ -23,63 +23,63 @@ public class CharactersTest { @Test public void normal() { Ix source = Ix.characters("Hello world!"); - + IxTestHelper.assertValues(source, - (int)'H', (int)'e', (int)'l', (int)'l', - (int)'o', (int)' ', (int)'w', (int)'o', (int)'r', (int)'l', + (int)'H', (int)'e', (int)'l', (int)'l', + (int)'o', (int)' ', (int)'w', (int)'o', (int)'r', (int)'l', (int)'d', (int)'!'); - + IxTestHelper.assertNoRemove(source); } @Test public void normalRange() { Ix source = Ix.characters("Hello world!", 2, 8); - + IxTestHelper.assertValues(source, - (int)'l', (int)'l', + (int)'l', (int)'l', (int)'o', (int)' ', (int)'w', (int)'o'); - + IxTestHelper.assertNoRemove(source); } @Test public void rangeChecks() { String s = "Hello world"; - + try { Ix.characters(s, -1, 1); Assert.fail("Failed to throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { Assert.assertEquals("start=-1, end=1, length=11", ex.getMessage()); } - + try { Ix.characters(s, 1, -1); Assert.fail("Failed to throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { Assert.assertEquals("start=1, end=-1, length=11", ex.getMessage()); } - + try { Ix.characters(s, 12, -1); Assert.fail("Failed to throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { Assert.assertEquals("start=12, end=-1, length=11", ex.getMessage()); } - + try { Ix.characters(s, 1, 12); Assert.fail("Failed to throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { Assert.assertEquals("start=1, end=12, length=11", ex.getMessage()); } - + try { Ix.characters(s, 12, 12); Assert.fail("Failed to throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { Assert.assertEquals("start=12, end=12, length=11", ex.getMessage()); } - } + } } diff --git a/src/test/java/ix/CollectTest.java b/src/test/java/ix/CollectTest.java index 4def9d8..9e84a46 100644 --- a/src/test/java/ix/CollectTest.java +++ b/src/test/java/ix/CollectTest.java @@ -16,28 +16,26 @@ package ix; -import org.junit.Test; - -import rx.functions.*; +import static org.junit.Assert.assertEquals; -import static org.junit.Assert.*; +import org.junit.Test; public class CollectTest { @Test public void normal() { - Ix source = Ix.range(1, 10).collect(new Func0() { + Ix source = Ix.range(1, 10).collect(new IxSupplier() { @Override - public Integer[] call() { + public Integer[] get() { return new Integer[] { 0 }; } - }, new Action2() { + }, new IxConsumer2() { @Override - public void call(Integer[] a, Integer b) { + public void accept(Integer[] a, Integer b) { a[0] += b; } }); - + assertEquals(55, source.first()[0].intValue()); } } diff --git a/src/test/java/ix/ConcatArrayTest.java b/src/test/java/ix/ConcatArrayTest.java index b775fd9..0987a3f 100644 --- a/src/test/java/ix/ConcatArrayTest.java +++ b/src/test/java/ix/ConcatArrayTest.java @@ -26,8 +26,8 @@ public class ConcatArrayTest { @Test public void normal() { Ix source = Ix.concatArray(Ix.range(1, 5), Ix.range(6, 5)); - - + + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @@ -35,18 +35,18 @@ public void normal() { @Test public void normalViaMerge() { Ix source = Ix.mergeArray(Ix.range(1, 5), Ix.range(6, 5)); - - + + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } - + @SuppressWarnings("unchecked") @Test public void just() { Ix source = Ix.concatArray(Ix.just(1), Ix.just(2)); - - + + IxTestHelper.assertValues(source, 1, 2); } @@ -54,28 +54,28 @@ public void just() { @Test public void empty() { Ix source = Ix.concatArray(Ix.empty(), Ix.empty()); - - + + IxTestHelper.assertValues(source); } @SuppressWarnings("unchecked") @Test public void mixed() { - Ix source = Ix.concatArray(Ix.empty(), Ix.range(1, 5), + Ix source = Ix.concatArray(Ix.empty(), Ix.range(1, 5), Ix.empty(), Ix.just(6), Ix.empty()); - - + + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6); } @SuppressWarnings("unchecked") @Test public void mixedTwo() { - Ix source = Ix.concatArray(Ix.range(1, 5), + Ix source = Ix.concatArray(Ix.range(1, 5), Ix.empty(), Ix.just(6)); - - + + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6); } @@ -83,7 +83,7 @@ public void mixedTwo() { public void emptyArray() { @SuppressWarnings("unchecked") Ix source = Ix.concatArray(); - + Assert.assertSame(source.getClass().toString(), source, Ix.empty()); } @@ -91,7 +91,7 @@ public void emptyArray() { public void justArray() { @SuppressWarnings("unchecked") Ix source = Ix.concatArray(Ix.just(1)); - + Assert.assertTrue(source.getClass().toString(), source instanceof IxScalarCallable); } @@ -99,8 +99,8 @@ public void justArray() { @Test public void concatIterable() { Ix source = Ix.concat(Arrays.asList(Ix.range(1, 5), Ix.range(6, 5))); - - + + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @@ -108,11 +108,11 @@ public void concatIterable() { @Test public void concatIterableViaMerge() { Ix source = Ix.merge(Arrays.asList(Ix.range(1, 5), Ix.range(6, 5))); - - + + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } - + @Test public void startWith() { Ix source = Ix.range(1, 5).startWith(5, 4, 3, 2, 1); @@ -154,7 +154,7 @@ public void concatWithEmpty() { IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); } - + @Test public void mergeWith() { Ix source = Ix.range(1, 5).mergeWith(Ix.range(6, 5)); @@ -168,25 +168,25 @@ public void mergeWithEmpty() { IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); } - + @Test public void concat2() { Ix source = Ix.concat(Ix.just(1), Ix.just(2)); - + IxTestHelper.assertValues(source, 1, 2); } @Test public void concat3() { Ix source = Ix.concat(Ix.just(1), Ix.just(2), Ix.just(3)); - + IxTestHelper.assertValues(source, 1, 2, 3); } @Test public void concat4() { Ix source = Ix.concat(Ix.just(1), Ix.just(2), Ix.just(3), Ix.just(4)); - + IxTestHelper.assertValues(source, 1, 2, 3, 4); } } diff --git a/src/test/java/ix/ContainsTest.java b/src/test/java/ix/ContainsTest.java index 504520b..85f091d 100644 --- a/src/test/java/ix/ContainsTest.java +++ b/src/test/java/ix/ContainsTest.java @@ -23,63 +23,63 @@ public class ContainsTest { @Test public void normal() { Ix source = Ix.range(1, 5).contains(3); - + IxTestHelper.assertValues(source, true); - + IxTestHelper.assertNoRemove(source); } - + @Test public void normalNoReferenceEquals() { Ix source = Ix.range(1, 5).contains(new Integer(3)); - + IxTestHelper.assertValues(source, true); - + IxTestHelper.assertNoRemove(source); } - + @Test public void doesntContain() { Ix source = Ix.range(1, 5).contains(6); - + IxTestHelper.assertValues(source, false); - + IxTestHelper.assertNoRemove(source); } - + @Test public void doesntContainNull() { Ix source = Ix.range(1, 5).contains(null); - + IxTestHelper.assertValues(source, false); - + IxTestHelper.assertNoRemove(source); } - + @Test public void empty() { Ix source = Ix.empty().contains(6); - + IxTestHelper.assertValues(source, false); - + IxTestHelper.assertNoRemove(source); } - + @Test public void justNull() { Ix source = Ix.just(null).contains(6); - + IxTestHelper.assertValues(source, false); - + IxTestHelper.assertNoRemove(source); } - + @Test public void justNullContains() { Ix source = Ix.just(null).contains(null); - + IxTestHelper.assertValues(source, true); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/CountTest.java b/src/test/java/ix/CountTest.java index 99935ab..c075aa9 100644 --- a/src/test/java/ix/CountTest.java +++ b/src/test/java/ix/CountTest.java @@ -23,54 +23,54 @@ public class CountTest { @Test public void normal() { Ix source = Ix.range(1, 5).count(); - + IxTestHelper.assertValues(source, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void just() { Ix source = Ix.just(1).count(); - + IxTestHelper.assertValues(source, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void empty() { Ix source = Ix.empty().count(); - + IxTestHelper.assertValues(source, 0); - + IxTestHelper.assertNoRemove(source); } @Test public void normalLong() { Ix source = Ix.range(1, 5).countLong(); - + IxTestHelper.assertValues(source, 5L); - + IxTestHelper.assertNoRemove(source); } @Test public void justLong() { Ix source = Ix.just(1).countLong(); - + IxTestHelper.assertValues(source, 1L); - + IxTestHelper.assertNoRemove(source); } - + @Test public void emptyLong() { Ix source = Ix.empty().countLong(); - + IxTestHelper.assertValues(source, 0L); - + IxTestHelper.assertNoRemove(source); } diff --git a/src/test/java/ix/DeferTest.java b/src/test/java/ix/DeferTest.java index 8592d4e..7e35ede 100644 --- a/src/test/java/ix/DeferTest.java +++ b/src/test/java/ix/DeferTest.java @@ -18,20 +18,18 @@ import org.junit.Test; -import rx.functions.Func0; - public class DeferTest { @Test public void normal() { - Ix source = Ix.defer(new Func0>() { + Ix source = Ix.defer(new IxSupplier>() { int count; @Override - public Iterable call() { + public Iterable get() { return Ix.range(++count, 2); } }); - + IxTestHelper.assertValues(source, 1, 2); IxTestHelper.assertValues(source, 2, 3); IxTestHelper.assertValues(source, 3, 4); diff --git a/src/test/java/ix/DistinctTest.java b/src/test/java/ix/DistinctTest.java index 070d9be..159858b 100644 --- a/src/test/java/ix/DistinctTest.java +++ b/src/test/java/ix/DistinctTest.java @@ -18,33 +18,31 @@ import org.junit.Test; -import rx.functions.Func1; - public class DistinctTest { @Test public void normal() { Ix source = Ix.fromArray(1, 2, 2, 1, 3, 4, 2).distinct(); - + IxTestHelper.assertValues(source, 1, 2, 3, 4); } - + @Test public void empty() { Ix source = Ix.empty().distinct(); - + IxTestHelper.assertValues(source); } - + @Test public void normalSelector() { - Ix source = Ix.fromArray(1, 2, 2, 1, 3, 4, 2).distinct(new Func1() { + Ix source = Ix.fromArray(1, 2, 2, 1, 3, 4, 2).distinct(new IxFunction() { @Override - public Object call(Integer v) { + public Object apply(Integer v) { return v & 1; } }); - + IxTestHelper.assertValues(source, 1, 2); } } diff --git a/src/test/java/ix/DistinctUntilChangedTest.java b/src/test/java/ix/DistinctUntilChangedTest.java index 324c97a..591a343 100644 --- a/src/test/java/ix/DistinctUntilChangedTest.java +++ b/src/test/java/ix/DistinctUntilChangedTest.java @@ -18,54 +18,52 @@ import org.junit.Test; -import rx.functions.Func1; - public class DistinctUntilChangedTest { @Test public void normal() { Ix source = Ix.fromArray(1, 2, 2, 1, 3, 1, 1, 4, 4).distinctUntilChanged(); - + IxTestHelper.assertValues(source, 1, 2, 1, 3, 1, 4); - + IxTestHelper.assertNoRemove(source); } - + @Test public void normalComparer() { - Ix source = Ix.fromArray(1, 2, 2, 1, 3, 1, 1, 4, 4).distinctUntilChanged(new Pred2() { + Ix source = Ix.fromArray(1, 2, 2, 1, 3, 1, 1, 4, 4).distinctUntilChanged(new IxPredicate2() { @Override public boolean test(Integer a, Integer b) { return (a & 1) == (b & 1); } }); - + IxTestHelper.assertValues(source, 1, 2, 1, 4); - + IxTestHelper.assertNoRemove(source); } - + @Test public void normalSelector() { Ix source = Ix.fromArray(1, 2, 2, 1, 3, 1, 1, 4, 4) - .distinctUntilChanged(new Func1() { + .distinctUntilChanged(new IxFunction() { @Override - public Object call(Integer v) { + public Object apply(Integer v) { return v & 1; } }); - + IxTestHelper.assertValues(source, 1, 2, 1, 4); - + IxTestHelper.assertNoRemove(source); } - + @Test public void empty() { Ix source = Ix.empty().distinctUntilChanged(); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/DoOnTest.java b/src/test/java/ix/DoOnTest.java index fc6860e..497c77b 100644 --- a/src/test/java/ix/DoOnTest.java +++ b/src/test/java/ix/DoOnTest.java @@ -20,23 +20,21 @@ import org.junit.*; -import rx.functions.*; - public class DoOnTest { @Test public void normal() { final List values = new ArrayList(); Ix source = Ix.range(1, 5) - .doOnNext(new Action1() { + .doOnNext(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { values.add(v); } }) - .doOnCompleted(new Action0() { + .doOnCompleted(new Runnable() { @Override - public void call() { + public void run() { values.add(100); } }) @@ -44,20 +42,20 @@ public void call() { IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5, 100), values); } - + @Test public void empty() { final List values = new ArrayList(); Ix source = Ix.empty() - .doOnNext(new Action1() { + .doOnNext(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { values.add(v); } }) - .doOnCompleted(new Action0() { + .doOnCompleted(new Runnable() { @Override - public void call() { + public void run() { values.add(100); } }) diff --git a/src/test/java/ix/EmptyActionTest.java b/src/test/java/ix/EmptyActionTest.java index 534350f..0f5cc50 100644 --- a/src/test/java/ix/EmptyActionTest.java +++ b/src/test/java/ix/EmptyActionTest.java @@ -16,16 +16,16 @@ package ix; -import org.junit.Test; - import static org.junit.Assert.*; +import org.junit.Test; + public class EmptyActionTest { @Test public void normal() { assertNotNull(IxEmptyAction.valueOf("INSTANCE")); - + assertEquals(1, IxEmptyAction.values().length); } } diff --git a/src/test/java/ix/EmptyTest.java b/src/test/java/ix/EmptyTest.java index 0e9d2ac..4477e3f 100644 --- a/src/test/java/ix/EmptyTest.java +++ b/src/test/java/ix/EmptyTest.java @@ -23,18 +23,18 @@ public class EmptyTest { @Test public void normal() { Ix source = Ix.empty(); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } - + @Test public void removeThrows() { Ix source = Ix.empty(); - + IxTestHelper.assertNoRemove(source); - + try { source.iterator().remove(); Assert.fail("Should have thrown UnsupportedOperationException"); diff --git a/src/test/java/ix/EqualityHelperTest.java b/src/test/java/ix/EqualityHelperTest.java index d3ae6fd..f742000 100644 --- a/src/test/java/ix/EqualityHelperTest.java +++ b/src/test/java/ix/EqualityHelperTest.java @@ -16,10 +16,10 @@ package ix; -import org.junit.Test; - -import static org.junit.Assert.*; import static ix.EqualityHelper.INSTANCE; +import static org.junit.Assert.*; + +import org.junit.Test; public class EqualityHelperTest { @@ -31,9 +31,9 @@ public void normal() { assertFalse(INSTANCE.test(null, 1)); assertFalse(INSTANCE.test(1, null)); assertFalse(INSTANCE.test(1, 2)); - + assertNotNull(EqualityHelper.valueOf("INSTANCE")); - + assertEquals(1, EqualityHelper.values().length); } } diff --git a/src/test/java/ix/ExceptTest.java b/src/test/java/ix/ExceptTest.java index f9e9f20..f166635 100644 --- a/src/test/java/ix/ExceptTest.java +++ b/src/test/java/ix/ExceptTest.java @@ -23,63 +23,63 @@ public class ExceptTest { @Test public void normal() { Ix source = Ix.range(1, 5).except(Ix.range(3, 5)); - + IxTestHelper.assertValues(source, 1, 2, 6, 7); - + IxTestHelper.assertNoRemove(source); } - + @Test public void firstEmpty() { Ix source = Ix.empty().except(Ix.range(3, 5)); - + IxTestHelper.assertValues(source, 3, 4, 5, 6, 7); - + IxTestHelper.assertNoRemove(source); } - + @Test public void secondEmpty() { Ix source = Ix.range(1, 5).except(Ix.empty()); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } - + @Test public void firstInSecond() { Ix source = Ix.range(1, 5).except(Ix.range(1, 3)); - + IxTestHelper.assertValues(source, 4, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void firstInFirst() { Ix source = Ix.range(1, 3).except(Ix.range(1, 5)); - + IxTestHelper.assertValues(source, 4, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void distinct() { Ix source = Ix.range(1, 5).except(Ix.range(6, 5)); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - + IxTestHelper.assertNoRemove(source); } - + @Test public void overlapWithDuplicates() { Ix source = Ix.fromArray(1, 2, 2, 3, 4, 5).except(Ix.range(1, 3)); - + IxTestHelper.assertValues(source, 4, 5); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/FilterTest.java b/src/test/java/ix/FilterTest.java index 80c39f6..db5736d 100644 --- a/src/test/java/ix/FilterTest.java +++ b/src/test/java/ix/FilterTest.java @@ -24,51 +24,51 @@ public class FilterTest { @Test public void normal() { - Ix source = Ix.range(1, 10).filter(new Pred() { + Ix source = Ix.range(1, 10).filter(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) != 0; } }); - + IxTestHelper.assertValues(source, 1, 3, 5, 7, 9); } - + @Test public void empty() { - Ix source = Ix.empty().filter(new Pred() { + Ix source = Ix.empty().filter(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) != 0; } }); - + IxTestHelper.assertValues(source); } @Test public void empty2() { - Ix source = Ix.just(0).filter(new Pred() { + Ix source = Ix.just(0).filter(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) != 0; } }); - + IxTestHelper.assertValues(source); } @Test public void removeComposes() { List list = Ix.range(1, 10).collectToList().first(); - - Ix.from(list).filter(new Pred() { + + Ix.from(list).filter(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) != 0; } }).removeAll(); - + Assert.assertEquals(Arrays.asList(2, 4, 6, 8, 10), list); } } diff --git a/src/test/java/ix/FirstTest.java b/src/test/java/ix/FirstTest.java index e16c444..8a53b07 100644 --- a/src/test/java/ix/FirstTest.java +++ b/src/test/java/ix/FirstTest.java @@ -16,7 +16,7 @@ package ix; -import java.util.*; +import java.util.NoSuchElementException; import org.junit.*; @@ -25,42 +25,42 @@ public class FirstTest { @Test public void normal() { Ix source = Ix.range(1, 10); - + Assert.assertEquals(1, source.first().intValue()); } @Test public void just() { Ix source = Ix.just(1); - + Assert.assertEquals(1, source.first().intValue()); } @Test(expected = NoSuchElementException.class) public void empty() { Ix source = Ix.empty(); - + Assert.assertEquals(1, source.first().intValue()); } @Test public void emptyDefault() { Ix source = Ix.empty(); - + Assert.assertEquals(100, source.first(100).intValue()); } @Test public void justDefault() { Ix source = Ix.just(1); - + Assert.assertEquals(1, source.first(100).intValue()); } @Test public void rangeDefault() { Ix source = Ix.range(1, 10); - + Assert.assertEquals(1, source.first(100).intValue()); } diff --git a/src/test/java/ix/FlattenIterableTest.java b/src/test/java/ix/FlattenIterableTest.java index 0bcf696..f893498 100644 --- a/src/test/java/ix/FlattenIterableTest.java +++ b/src/test/java/ix/FlattenIterableTest.java @@ -18,81 +18,79 @@ import org.junit.Test; -import rx.functions.Func1; - public class FlattenIterableTest { @Test public void normal() { - Ix source = Ix.range(1, 5).flatMap(new Func1>() { + Ix source = Ix.range(1, 5).flatMap(new IxFunction>() { @Override - public Iterable call(Integer v) { + public Iterable apply(Integer v) { return Ix.range(v, 2); } }); - + IxTestHelper.assertValues(source, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6); - + IxTestHelper.assertNoRemove(source); } @Test public void normalViaConcatMap() { - Ix source = Ix.range(1, 5).concatMap(new Func1>() { + Ix source = Ix.range(1, 5).concatMap(new IxFunction>() { @Override - public Iterable call(Integer v) { + public Iterable apply(Integer v) { return Ix.range(v, 2); } }); - + IxTestHelper.assertValues(source, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6); } @Test public void just() { - Ix source = Ix.just(1).flatMap(new Func1>() { + Ix source = Ix.just(1).flatMap(new IxFunction>() { @Override - public Iterable call(Integer v) { + public Iterable apply(Integer v) { return Ix.range(v, 2); } }); - + IxTestHelper.assertValues(source, 1, 2); } @Test public void empty() { - Ix source = Ix.empty().flatMap(new Func1>() { + Ix source = Ix.empty().flatMap(new IxFunction>() { @Override - public Iterable call(Integer v) { + public Iterable apply(Integer v) { return Ix.range(v, 2); } }); - + IxTestHelper.assertValues(source); } @Test public void rangeJust() { - Ix source = Ix.range(1, 2).flatMap(new Func1>() { + Ix source = Ix.range(1, 2).flatMap(new IxFunction>() { @Override - public Iterable call(Integer v) { + public Iterable apply(Integer v) { return Ix.just(v); } }); - + IxTestHelper.assertValues(source, 1, 2); } - + @Test public void rangeEmpty() { - Ix source = Ix.range(1, 2).flatMap(new Func1>() { + Ix source = Ix.range(1, 2).flatMap(new IxFunction>() { @Override - public Iterable call(Integer v) { + public Iterable apply(Integer v) { return Ix.empty(); } }); - + IxTestHelper.assertValues(source); } } diff --git a/src/test/java/ix/ForeachTest.java b/src/test/java/ix/ForeachTest.java index d71dac5..7d82cf9 100644 --- a/src/test/java/ix/ForeachTest.java +++ b/src/test/java/ix/ForeachTest.java @@ -20,57 +20,55 @@ import org.junit.*; -import rx.functions.Action1; - -public class ForeachTest implements Action1, Pred { +public class ForeachTest implements IxConsumer, IxPredicate { List list; - + @Before public void before() { list = new ArrayList(); } - + @Override - public void call(Integer t) { + public void accept(Integer t) { list.add(t); } - + @Override public boolean test(Integer t) { list.add(t); return list.size() < 5; } - + @Test public void normal() { Ix source = Ix.range(1, 10); - + source.foreach(this); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), list); } @Test public void normalWhile() { Ix source = Ix.range(1, 10); - + source.foreachWhile(this); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), list); } @Test public void normalWhileAll() { Ix source = Ix.range(1, 5); - - source.foreachWhile(new Pred() { + + source.foreachWhile(new IxPredicate() { @Override public boolean test(Integer v) { return true; } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); } } diff --git a/src/test/java/ix/ForloopTest.java b/src/test/java/ix/ForloopTest.java index 8db6fdf..fa3d40b 100644 --- a/src/test/java/ix/ForloopTest.java +++ b/src/test/java/ix/ForloopTest.java @@ -18,55 +18,53 @@ import org.junit.Test; -import rx.functions.Func1; - public class ForloopTest { @Test public void normal() { - Ix source = Ix.forloop(1, new Pred() { + Ix source = Ix.forloop(1, new IxPredicate() { @Override public boolean test(Integer i) { return i <= 5; } - }, new Func1() { + }, new IxFunction() { @Override - public Integer call(Integer i) { + public Integer apply(Integer i) { return i + 1; } - }, new Func1() { + }, new IxFunction() { @Override - public Integer call(Integer i) { + public Integer apply(Integer i) { return i * i; } }); - + IxTestHelper.assertValues(source, 1, 4, 9, 16, 25); - + IxTestHelper.assertNoRemove(source); } - + @Test public void empty() { - Ix source = Ix.forloop(1, new Pred() { + Ix source = Ix.forloop(1, new IxPredicate() { @Override public boolean test(Integer i) { return false; } - }, new Func1() { + }, new IxFunction() { @Override - public Integer call(Integer i) { + public Integer apply(Integer i) { return i + 1; } - }, new Func1() { + }, new IxFunction() { @Override - public Integer call(Integer i) { + public Integer apply(Integer i) { return i * i; } }); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/FromArrayTest.java b/src/test/java/ix/FromArrayTest.java index 18d5944..959a440 100644 --- a/src/test/java/ix/FromArrayTest.java +++ b/src/test/java/ix/FromArrayTest.java @@ -23,30 +23,30 @@ public class FromArrayTest { @Test public void normal() { Ix source = Ix.fromArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - + IxTestHelper.assertNoRemove(source); } @Test public void range() { Ix source = Ix.fromArrayRange(1, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - + IxTestHelper.assertValues(source, 2, 3, 4, 5, 6, 7, 8); } - + @Test public void empty() { Ix source = Ix.fromArray(); - + Assert.assertSame(source.getClass().toString(), source, Ix.empty()); } @Test public void just() { Ix source = Ix.fromArray(1); - + Assert.assertTrue(source.getClass().toString(), source instanceof IxScalarCallable); } @@ -58,28 +58,28 @@ public void rangeChecks() { } catch (IndexOutOfBoundsException ex) { Assert.assertEquals("start=-1, end=1, length=10", ex.getMessage()); } - + try { Ix.fromArrayRange(1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Assert.fail("Failed to throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { Assert.assertEquals("start=1, end=-1, length=10", ex.getMessage()); } - + try { Ix.fromArrayRange(12, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Assert.fail("Failed to throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { Assert.assertEquals("start=12, end=-1, length=10", ex.getMessage()); } - + try { Ix.fromArrayRange(1, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Assert.fail("Failed to throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { Assert.assertEquals("start=1, end=12, length=10", ex.getMessage()); } - + try { Ix.fromArrayRange(12, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Assert.fail("Failed to throw IndexOutOfBoundsException"); @@ -87,5 +87,5 @@ public void rangeChecks() { Assert.assertEquals("start=12, end=12, length=10", ex.getMessage()); } - } + } } diff --git a/src/test/java/ix/FromTest.java b/src/test/java/ix/FromTest.java index 82a1d3a..7b31271 100644 --- a/src/test/java/ix/FromTest.java +++ b/src/test/java/ix/FromTest.java @@ -25,18 +25,18 @@ public class FromTest { @Test public void normal() { Ix source = Ix.from(Arrays.asList(1, 2, 3, 4, 5)); - + Assert.assertTrue(source.getClass().toString(), source instanceof IxWrapper); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); } @Test public void noRewrapping() { Ix source = Ix.from(Ix.range(1, 5)); - + Assert.assertFalse(source.getClass().toString(), source instanceof IxWrapper); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); } diff --git a/src/test/java/ix/GenerateStatelessTest.java b/src/test/java/ix/GenerateStatelessTest.java index 6080d0c..70476d7 100644 --- a/src/test/java/ix/GenerateStatelessTest.java +++ b/src/test/java/ix/GenerateStatelessTest.java @@ -20,83 +20,80 @@ import org.junit.Test; -import rx.Observer; -import rx.functions.Action1; - public class GenerateStatelessTest { @Test public void normal() { - Ix source = Ix.generate(new Action1>() { + Ix source = Ix.generate(new IxConsumer>() { int count; @Override - public void call(Observer t) { + public void accept(IxEmitter t) { t.onNext(++count); if (count == 10) { - t.onCompleted(); + t.onComplete(); } } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } - + @Test public void empty() { - Ix source = Ix.generate(new Action1>() { + Ix source = Ix.generate(new IxConsumer>() { @Override - public void call(Observer t) { - t.onCompleted(); + public void accept(IxEmitter t) { + t.onComplete(); } }); - + IxTestHelper.assertValues(source); } - + @Test(expected = IllegalStateException.class) public void never() { - Ix source = Ix.generate(new Action1>() { + Ix source = Ix.generate(new IxConsumer>() { @Override - public void call(Observer t) { + public void accept(IxEmitter t) { } }); - + IxTestHelper.assertValues(source); } @Test(expected = IllegalArgumentException.class) public void runtimeError() { - Ix source = Ix.generate(new Action1>() { + Ix source = Ix.generate(new IxConsumer>() { @Override - public void call(Observer t) { - t.onError(new IllegalArgumentException()); + public void accept(IxEmitter t) { + throw new IllegalArgumentException(); } }); - + IxTestHelper.assertValues(source); } @Test(expected = InternalError.class) public void error() { - Ix source = Ix.generate(new Action1>() { + Ix source = Ix.generate(new IxConsumer>() { @Override - public void call(Observer t) { - t.onError(new InternalError()); + public void accept(IxEmitter t) { + throw new InternalError(); } }); - + IxTestHelper.assertValues(source); } @Test(expected = RuntimeException.class) public void exceptionError() { - Ix source = Ix.generate(new Action1>() { + Ix source = Ix.generate(new IxConsumer>() { @Override - public void call(Observer t) { - t.onError(new IOException()); + public void accept(IxEmitter t) { + throw new RuntimeException(new IOException()); } }); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/GenerateTest.java b/src/test/java/ix/GenerateTest.java index 09e8ab4..2f87eea 100644 --- a/src/test/java/ix/GenerateTest.java +++ b/src/test/java/ix/GenerateTest.java @@ -21,122 +21,116 @@ import org.junit.*; -import rx.Observer; -import rx.functions.*; - public class GenerateTest { - Func0 stateFactory = new Func0() { + IxSupplier stateFactory = new IxSupplier() { @Override - public Integer call() { + public Integer get() { return 0; } }; - + @Test public void normal() { - Ix source = Ix.generate(stateFactory, new Func2, Integer>() { + Ix source = Ix.generate(stateFactory, new IxFunction2, Integer>() { @Override - public Integer call(Integer s, Observer t) { + public Integer apply(Integer s, IxEmitter t) { int i = ++s; t.onNext(i); if (i == 10) { - t.onCompleted(); + t.onComplete(); } return i; } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } - + @Test public void normalState() { final AtomicInteger value = new AtomicInteger(); - - Ix source = Ix.generate(stateFactory, new Func2, Integer>() { + + Ix source = Ix.generate(stateFactory, new IxFunction2, Integer>() { @Override - public Integer call(Integer s, Observer t) { + public Integer apply(Integer s, IxEmitter t) { int i = ++s; t.onNext(i); if (i == 10) { - t.onCompleted(); + t.onComplete(); } return i; } - }, new Action1() { + }, new IxConsumer() { @Override - public void call(Integer t) { + public void accept(Integer t) { value.set(t); } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - + Assert.assertEquals(10, value.get()); } - + @Test public void empty() { - Ix source = Ix.generate(stateFactory, new Func2, Integer>() { + Ix source = Ix.generate(stateFactory, new IxFunction2, Integer>() { @Override - public Integer call(Integer s, Observer t) { - t.onCompleted(); + public Integer apply(Integer s, IxEmitter t) { + t.onComplete(); return s; } }); - + IxTestHelper.assertValues(source); } - + @Test(expected = IllegalStateException.class) public void never() { - Ix source = Ix.generate(stateFactory, new Func2, Integer>() { + Ix source = Ix.generate(stateFactory, new IxFunction2, Integer>() { @Override - public Integer call(Integer s, Observer t) { + public Integer apply(Integer s, IxEmitter t) { return s; } }); - + IxTestHelper.assertValues(source); } @Test(expected = IllegalArgumentException.class) public void runtimeError() { - Ix source = Ix.generate(stateFactory, new Func2, Integer>() { + Ix source = Ix.generate(stateFactory, new IxFunction2, Integer>() { @Override - public Integer call(Integer s, Observer t) { - t.onError(new IllegalArgumentException()); - return s; + public Integer apply(Integer s, IxEmitter t) { + throw new IllegalArgumentException(); } }); - + IxTestHelper.assertValues(source); } @Test(expected = InternalError.class) public void error() { - Ix source = Ix.generate(stateFactory, new Func2, Integer>() { + Ix source = Ix.generate(stateFactory, new IxFunction2, Integer>() { @Override - public Integer call(Integer s, Observer t) { - t.onError(new InternalError()); - return s; + public Integer apply(Integer s, IxEmitter t) { + throw new InternalError(); } }); - + IxTestHelper.assertValues(source); } @Test(expected = RuntimeException.class) public void exceptionError() { - Ix source = Ix.generate(stateFactory, new Func2, Integer>() { + Ix source = Ix.generate(stateFactory, new IxFunction2, Integer>() { @Override - public Integer call(Integer s, Observer t) { - t.onError(new IOException()); - return s; + public Integer apply(Integer s, IxEmitter t) { + throw new RuntimeException(new IOException()); } }); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/GroupByTest.java b/src/test/java/ix/GroupByTest.java index 5e05857..dcdc8ea 100644 --- a/src/test/java/ix/GroupByTest.java +++ b/src/test/java/ix/GroupByTest.java @@ -20,109 +20,107 @@ import org.junit.*; -import rx.functions.*; - public class GroupByTest { @Test public void normal() { - Ix source = Ix.range(1, 10).groupBy(new Func1() { + Ix source = Ix.range(1, 10).groupBy(new IxFunction() { @Override - public Object call(Integer v) { + public Object apply(Integer v) { return v % 3; } - }).flatMap(new Func1, Iterable>() { + }).flatMap(new IxFunction, Iterable>() { @Override - public Iterable call(GroupedIx v) { + public Iterable apply(GroupedIx v) { return v; } }); - + IxTestHelper.assertValues(source, 1, 4, 7, 10, 2, 5, 8, 3, 6, 9); - + IxTestHelper.assertNoRemove(source); } - + @Test public void uniqueGroups() { - Ix source = Ix.range(1, 10).groupBy(new Func1() { + Ix source = Ix.range(1, 10).groupBy(new IxFunction() { @Override - public Object call(Integer v) { + public Object apply(Integer v) { return v; } }, - new Func1() { + new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v * 10; } } - ).flatMap(new Func1, Iterable>() { + ).flatMap(new IxFunction, Iterable>() { @Override - public Iterable call(GroupedIx v) { + public Iterable apply(GroupedIx v) { return v; } }); - + IxTestHelper.assertValues(source, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100); - + IxTestHelper.assertNoRemove(source); } - + @Test public void just() { - Ix source = Ix.just(1).groupBy(new Func1() { + Ix source = Ix.just(1).groupBy(new IxFunction() { @Override - public Object call(Integer v) { + public Object apply(Integer v) { return v % 3; } - }).flatMap(new Func1, Iterable>() { + }).flatMap(new IxFunction, Iterable>() { @Override - public Iterable call(GroupedIx v) { + public Iterable apply(GroupedIx v) { return v; } }); - + IxTestHelper.assertValues(source, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void justNull() { - Ix source = Ix.just(null).groupBy(new Func1() { + Ix source = Ix.just(null).groupBy(new IxFunction() { @Override - public Object call(Integer v) { + public Object apply(Integer v) { return 1; } - }).flatMap(new Func1, Iterable>() { + }).flatMap(new IxFunction, Iterable>() { @Override - public Iterable call(GroupedIx v) { + public Iterable apply(GroupedIx v) { return v; } }); - + IxTestHelper.assertValues(source, (Integer)null); - + IxTestHelper.assertNoRemove(source); } @Test public void empty() { - Ix source = Ix.empty().groupBy(new Func1() { + Ix source = Ix.empty().groupBy(new IxFunction() { @Override - public Object call(Integer v) { + public Object apply(Integer v) { return v % 3; } - }).flatMap(new Func1, Iterable>() { + }).flatMap(new IxFunction, Iterable>() { @Override - public Iterable call(GroupedIx v) { + public Iterable apply(GroupedIx v) { return v; } }); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } @@ -130,15 +128,15 @@ public Iterable call(GroupedIx v) { @Test public void lockstep() { final Iterator[] its = new Iterator[3]; - - Iterator main = Ix.range(1, 10).groupBy(new Func1() { + + Iterator main = Ix.range(1, 10).groupBy(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v % 3; } - }).doOnNext(new Action1>() { + }).doOnNext(new IxConsumer>() { @Override - public void call(GroupedIx g) { + public void accept(GroupedIx g) { its[g.key()] = g.iterator(); } }) @@ -147,49 +145,49 @@ public void call(GroupedIx g) { Assert.assertNotNull(main.next()); Assert.assertEquals(1, its[1].next().intValue()); - + Assert.assertNotNull(main.next()); Assert.assertEquals(2, its[2].next().intValue()); - + Assert.assertTrue(its[2].hasNext()); Assert.assertNotNull(main.next()); - + Assert.assertEquals(3, its[0].next().intValue()); Assert.assertEquals(4, its[1].next().intValue()); Assert.assertEquals(5, its[2].next().intValue()); Assert.assertEquals(6, its[0].next().intValue()); - + Assert.assertEquals(7, its[1].next().intValue()); Assert.assertEquals(8, its[2].next().intValue()); Assert.assertEquals(9, its[0].next().intValue()); Assert.assertEquals(10, its[1].next().intValue()); - + Assert.assertFalse(main.hasNext()); Assert.assertFalse(its[0].hasNext()); Assert.assertFalse(its[1].hasNext()); Assert.assertFalse(its[2].hasNext()); } - - + + @SuppressWarnings("unchecked") @Test public void lockstepNull() { final Iterator[] its = new Iterator[3]; - - Iterator main = Ix.range(1, 10).groupBy(new Func1() { + + Iterator main = Ix.range(1, 10).groupBy(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v % 3; } - }, new Func1() { + }, new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return null; } - }).doOnNext(new Action1>() { + }).doOnNext(new IxConsumer>() { @Override - public void call(GroupedIx g) { + public void accept(GroupedIx g) { its[g.key()] = g.iterator(); } }) @@ -198,24 +196,24 @@ public void call(GroupedIx g) { Assert.assertNotNull(main.next()); Assert.assertNull(its[1].next()); - + Assert.assertNotNull(main.next()); Assert.assertNull(its[2].next()); - + Assert.assertTrue(its[2].hasNext()); Assert.assertNotNull(main.next()); - + Assert.assertNull(its[0].next()); Assert.assertNull(its[1].next()); Assert.assertNull(its[2].next()); Assert.assertNull(its[0].next()); - + Assert.assertNull(its[1].next()); Assert.assertNull(its[2].next()); Assert.assertNull(its[0].next()); Assert.assertNull(its[1].next()); - + Assert.assertFalse(main.hasNext()); Assert.assertFalse(its[0].hasNext()); Assert.assertFalse(its[1].hasNext()); @@ -223,51 +221,51 @@ public void call(GroupedIx g) { } @Test public void sameGroupSubsequently() { - Ix> source = Ix.range(1, 5).groupBy(new Func1() { + Ix> source = Ix.range(1, 5).groupBy(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return 1; } }); - + List> list = source.collectToList().first(); IxTestHelper.assertValues(Ix.concat(list), 1, 2, 3, 4, 5); } - + @Test public void sameGroupSubsequentlyNullValue() { - Ix> source = Ix.range(1, 5).groupBy(new Func1() { + Ix> source = Ix.range(1, 5).groupBy(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return 1; } - }, new Func1() { + }, new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return null; } }); - + List> list = source.collectToList().first(); IxTestHelper.assertValues(Ix.concat(list), null, null, null, null, null); } - + @Test(expected = IllegalStateException.class) public void iteratorOnce() { - Ix> source = Ix.range(1, 5).groupBy(new Func1() { + Ix> source = Ix.range(1, 5).groupBy(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return 1; } - }, new Func1() { + }, new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return null; } }); - + List> list = source.collectToList().first(); Assert.assertEquals("GroupedIterable[key=1, queue=5]", list.get(0).toString()); diff --git a/src/test/java/ix/HasElementsTest.java b/src/test/java/ix/HasElementsTest.java index 18afdca..fb697ea 100644 --- a/src/test/java/ix/HasElementsTest.java +++ b/src/test/java/ix/HasElementsTest.java @@ -23,14 +23,14 @@ public class HasElementsTest { @Test public void empty() { Ix source = Ix.empty().hasElements(); - + IxTestHelper.assertValues(source, false); } @Test public void nonempty() { Ix source = Ix.just(1).hasElements(); - + IxTestHelper.assertValues(source, true); } diff --git a/src/test/java/ix/HelperTest.java b/src/test/java/ix/HelperTest.java index d53fea1..1615271 100644 --- a/src/test/java/ix/HelperTest.java +++ b/src/test/java/ix/HelperTest.java @@ -26,14 +26,14 @@ public void toListHelper() { Assert.assertNotNull(ToListHelper.valueOf("INSTANCE")); } - + @Test public void identityHelper() { Assert.assertEquals(1, IdentityHelper.values().length); Assert.assertNotNull(IdentityHelper.valueOf("INSTANCE")); } - + @Test public void numberToLongHelper() { Assert.assertEquals(1, NumberToLongHelper.values().length); diff --git a/src/test/java/ix/HideTest.java b/src/test/java/ix/HideTest.java index 1e2622f..4089ac9 100644 --- a/src/test/java/ix/HideTest.java +++ b/src/test/java/ix/HideTest.java @@ -25,7 +25,7 @@ public void normal() { Ix source = Ix.just(1); Assert.assertTrue(source instanceof IxScalarCallable); - + Assert.assertFalse((source.hide()) instanceof IxScalarCallable); } } diff --git a/src/test/java/ix/IgnoreElementsTest.java b/src/test/java/ix/IgnoreElementsTest.java index 786186f..fc20800 100644 --- a/src/test/java/ix/IgnoreElementsTest.java +++ b/src/test/java/ix/IgnoreElementsTest.java @@ -23,18 +23,18 @@ public class IgnoreElementsTest { @Test public void range() { Ix source = Ix.range(1, 5).ignoreElements(); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } @Test public void empty() { Ix source = Ix.empty().ignoreElements(); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } diff --git a/src/test/java/ix/IntersectTest.java b/src/test/java/ix/IntersectTest.java index 64ade1e..48df2da 100644 --- a/src/test/java/ix/IntersectTest.java +++ b/src/test/java/ix/IntersectTest.java @@ -23,45 +23,45 @@ public class IntersectTest { @Test public void normal() { Ix source = Ix.range(1, 5).intersect(Ix.range(3, 5)); - + IxTestHelper.assertValues(source, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } - + @Test public void same() { Ix source = Ix.range(1, 5).intersect(Ix.range(1, 5)); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void distinct() { Ix source = Ix.range(1, 5).intersect(Ix.range(6, 5)); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } - + @Test public void distinctEmptyFirst() { Ix source = Ix.empty().intersect(Ix.range(6, 5)); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } @Test public void distinctEmptySecond() { Ix source = Ix.range(1, 5).intersect(Ix.empty()); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } diff --git a/src/test/java/ix/IxOperatorsArePackageFinalTest.java b/src/test/java/ix/IxOperatorsArePackageFinalTest.java new file mode 100644 index 0000000..b33f248 --- /dev/null +++ b/src/test/java/ix/IxOperatorsArePackageFinalTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2011-2016 David Karnok + * + * 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 ix; + +import java.io.File; +import java.lang.reflect.Modifier; +import java.net.URL; + +import org.junit.*; + +public class IxOperatorsArePackageFinalTest { + + @Test + public void checkOperatorsFinal() throws Exception { + + URL u = IxOperatorsArePackageFinalTest.class.getResource(IxOperatorsArePackageFinalTest.class.getSimpleName() + ".class"); + + File f = new File(u.toURI()); + + File g = f.getParentFile(); + + File[] files = g.listFiles(); + + StringBuilder b = new StringBuilder(); + + if (files != null && files.length != 0) { + for (File h : files) { + if (h.getName().contains("Test") + || h.getName().contains("Perf") + || h.getName().contains("$")) { + continue; + } + + Class clazz = Class.forName("ix." + h.getName().replace(".class", "")); + + if ((clazz.getModifiers() & Modifier.FINAL) == 0 + && (clazz.getModifiers() & Modifier.ABSTRACT) == 0 + && (clazz.getModifiers() & Modifier.INTERFACE) == 0) { + b.append("java.lang.RuntimeException: " + h.getName() + " is not final\r\n") + .append(" at ").append(clazz.getName()).append(" (").append(h.getName()).append(":1)\r\n\r\n"); + } + } + } + + if (b.length() != 0) { + System.out.println(b); + + Assert.fail(b.toString()); + } + } +} diff --git a/src/test/java/ix/IxTest.java b/src/test/java/ix/IxTest.java index 3102a19..b413efd 100644 --- a/src/test/java/ix/IxTest.java +++ b/src/test/java/ix/IxTest.java @@ -25,7 +25,7 @@ public class IxTest { @Test(expected = RuntimeException.class) public void checkedCallWraps() { - + Ix.checkedCall(new Callable() { @Override public Integer call() throws Exception { @@ -33,10 +33,10 @@ public Integer call() throws Exception { } }); } - + @Test(expected = InternalError.class) public void checkedCallNoWrapsError() { - + Ix.checkedCall(new Callable() { @Override public Integer call() throws Exception { @@ -47,7 +47,7 @@ public Integer call() throws Exception { @Test(expected = IllegalArgumentException.class) public void checkedCallNoWrapping() { - + Ix.checkedCall(new Callable() { @Override public Integer call() throws Exception { @@ -55,7 +55,7 @@ public Integer call() throws Exception { } }); } - + @Test public void nullCheck() { Ix.nullCheck(1, "Should not fail"); @@ -66,24 +66,24 @@ public void nullCheck() { Assert.assertEquals("Failure", ex.getMessage()); } } - + @Test public void nonNegativeLong() { Ix.nonNegative(0L, "n"); Ix.nonNegative(1L, "n"); - + try { Ix.nonNegative(-99L, "n"); } catch (IllegalArgumentException ex) { Assert.assertEquals("n >= 0 required but it was -99", ex.getMessage()); } } - + @Test public void nonNegativeInt() { Ix.nonNegative(0, "n"); Ix.nonNegative(1, "n"); - + try { Ix.nonNegative(-99, "n"); } catch (IllegalArgumentException ex) { @@ -94,7 +94,7 @@ public void nonNegativeInt() { @Test public void positiveInt() { Ix.nonNegative(1, "n"); - + try { Ix.positive(0, "n"); } catch (IllegalArgumentException ex) { diff --git a/src/test/java/ix/IxTestHelper.java b/src/test/java/ix/IxTestHelper.java index 202c478..d0fa6f9 100644 --- a/src/test/java/ix/IxTestHelper.java +++ b/src/test/java/ix/IxTestHelper.java @@ -22,11 +22,11 @@ public enum IxTestHelper { ; - + static String classOf(Object o) { return o != null ? o.getClass().getSimpleName() : "null"; } - + /** * Asserts that the iterable produces the specified array of values and * verifies if it honors the iterator contract. @@ -37,38 +37,38 @@ static String classOf(Object o) { public static void assertValues(Iterable source, T... values) { Iterator a = source.iterator(); int i = 0; - + for (;;) { boolean b1 = a.hasNext(); boolean b2 = a.hasNext(); - + Assert.assertEquals("Inconsistent hasNext()", b1, b2); if (!b1) { break; } - + if (i == values.length) { throw new AssertionError("The source is longer than " + values.length); } - + T t = a.next(); - + if (t instanceof Object[]) { Assert.assertArrayEquals((Object[])values[i], (Object[])t); } else { - Assert.assertEquals("index=" + i + ", expected class=" - + classOf(values[i]) + Assert.assertEquals("index=" + i + ", expected class=" + + classOf(values[i]) + ", actual class=" + classOf(t), values[i], t); } i++; } - + if (i != values.length) { throw new AssertionError("The source is shorter than " + values.length + ": " + i); } - + try { a.next(); Assert.fail("The next() should have thrown a NoSuchElementException"); @@ -76,7 +76,7 @@ public static void assertValues(Iterable source, T... values) { // expected } } - + /** * Assert that calling remove() on the source's Iterator throws * an UnsupportedOperationException. @@ -84,7 +84,7 @@ public static void assertValues(Iterable source, T... values) { */ public static void assertNoRemove(Iterable source) { Iterator it = source.iterator(); - + if (it.hasNext()) { it.next(); try { @@ -95,7 +95,7 @@ public static void assertNoRemove(Iterable source) { } } } - + public static List range(int start, int count) { return Ix.range(start, count).collectToList().first(); } diff --git a/src/test/java/ix/JoinTest.java b/src/test/java/ix/JoinTest.java index aa97e0d..a94a3a7 100644 --- a/src/test/java/ix/JoinTest.java +++ b/src/test/java/ix/JoinTest.java @@ -23,54 +23,54 @@ public class JoinTest { @Test public void normal() { Ix source = Ix.range(1, 5).join(); - + IxTestHelper.assertValues(source, "1, 2, 3, 4, 5"); - + IxTestHelper.assertNoRemove(source); } @Test public void just() { Ix source = Ix.just(1).join(); - + IxTestHelper.assertValues(source, "1"); - + IxTestHelper.assertNoRemove(source); } @Test public void empty() { Ix source = Ix.empty().join(); - + IxTestHelper.assertValues(source, ""); - + IxTestHelper.assertNoRemove(source); } @Test public void normalSeparator() { Ix source = Ix.range(1, 5).join("|"); - + IxTestHelper.assertValues(source, "1|2|3|4|5"); - + IxTestHelper.assertNoRemove(source); } @Test public void justSeparator() { Ix source = Ix.just(1).join("|"); - + IxTestHelper.assertValues(source, "1"); - + IxTestHelper.assertNoRemove(source); } @Test public void emptySeparator() { Ix source = Ix.empty().join("|"); - + IxTestHelper.assertValues(source, ""); - + IxTestHelper.assertNoRemove(source); } diff --git a/src/test/java/ix/JustTest.java b/src/test/java/ix/JustTest.java index 7fe8359..d2f5a67 100644 --- a/src/test/java/ix/JustTest.java +++ b/src/test/java/ix/JustTest.java @@ -23,9 +23,9 @@ public class JustTest { @Test public void normal() { Ix source = Ix.just(1); - + IxTestHelper.assertValues(source, 1); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/LastTest.java b/src/test/java/ix/LastTest.java index a921b2f..ee54abd 100644 --- a/src/test/java/ix/LastTest.java +++ b/src/test/java/ix/LastTest.java @@ -16,7 +16,7 @@ package ix; -import java.util.*; +import java.util.NoSuchElementException; import org.junit.*; @@ -25,42 +25,42 @@ public class LastTest { @Test public void normal() { Ix source = Ix.range(1, 10); - + Assert.assertEquals(10, source.last().intValue()); } @Test public void just() { Ix source = Ix.just(1); - + Assert.assertEquals(1, source.last().intValue()); } @Test(expected = NoSuchElementException.class) public void empty() { Ix source = Ix.empty(); - + Assert.assertEquals(1, source.last().intValue()); } @Test public void emptyDefault() { Ix source = Ix.empty(); - + Assert.assertEquals(100, source.last(100).intValue()); } @Test public void justDefault() { Ix source = Ix.just(1); - + Assert.assertEquals(1, source.last(100).intValue()); } @Test public void rangeDefault() { Ix source = Ix.range(1, 10); - + Assert.assertEquals(10, source.last(100).intValue()); } diff --git a/src/test/java/ix/LeavingTest.java b/src/test/java/ix/LeavingTest.java index 735af6c..1a21bc5 100644 --- a/src/test/java/ix/LeavingTest.java +++ b/src/test/java/ix/LeavingTest.java @@ -21,20 +21,17 @@ import org.junit.*; -import rx.functions.*; -import rx.observers.TestSubscriber; - public class LeavingTest { @Test public void normal() { List list = new ArrayList(); - + Ix.range(1, 5).into(list); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), list); } - + @Test public void print() throws Exception { PrintStream old = System.out; @@ -42,18 +39,18 @@ public void print() throws Exception { System.setOut(new PrintStream(bout)); try { Ix.range(1, 30).print(); - + System.out.flush(); } finally { System.setOut(old); } - + String[] s = bout.toString("UTF-8").split(System.getProperty("line.separator")); - + Assert.assertEquals(Ix.range(1, 23).join().first() + ", ", s[0]); Assert.assertEquals(Ix.range(24, 7).join().first(), s[1]); } - + @Test public void print40() throws Exception { PrintStream old = System.out; @@ -61,14 +58,14 @@ public void print40() throws Exception { System.setOut(new PrintStream(bout)); try { Ix.range(1, 30).print(",", 40); - + System.out.flush(); } finally { System.setOut(old); } - + String[] s = bout.toString("UTF-8").split(System.getProperty("line.separator")); - + Assert.assertEquals(Ix.range(1, 17).join(",").first() + ",", s[0]); Assert.assertEquals(Ix.range(18, 13).join(",").first(), s[1]); } @@ -80,14 +77,14 @@ public void println() throws Exception { System.setOut(new PrintStream(bout)); try { Ix.range(1, 3).println(); - + System.out.flush(); } finally { System.setOut(old); } - + String[] s = bout.toString("UTF-8").split(System.getProperty("line.separator")); - + Assert.assertEquals("1", s[0]); Assert.assertEquals("2", s[1]); Assert.assertEquals("3", s[2]); @@ -100,318 +97,187 @@ public void printlnPrefix() throws Exception { System.setOut(new PrintStream(bout)); try { Ix.range(1, 3).println("--"); - + System.out.flush(); } finally { System.setOut(old); } - + String[] s = bout.toString("UTF-8").split(System.getProperty("line.separator")); - + Assert.assertEquals("--1", s[0]); Assert.assertEquals("--2", s[1]); Assert.assertEquals("--3", s[2]); } - + @Test public void run() { final List list = new ArrayList(); - - Ix.range(1, 5).doOnNext(new Action1() { + + Ix.range(1, 5).doOnNext(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { list.add(v); } }).run(); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), list); } @Test public void subscribe() { final List list = new ArrayList(); - - Ix.range(1, 5).doOnNext(new Action1() { + + Ix.range(1, 5).doOnNext(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { list.add(v); } }).subscribe(); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), list); } @Test public void subscribeAction1() { final List list = new ArrayList(); - - Ix.range(1, 5).subscribe(new Action1() { + + Ix.range(1, 5).subscribe(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { list.add(v); } }); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), list); } - + @Test public void subscribeAction1Action1() { final List list = new ArrayList(); - - Ix.range(1, 5).subscribe(new Action1() { + + Ix.range(1, 5).subscribe(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { list.add(v); } - }, new Action1() { + }, new IxConsumer() { @Override - public void call(Throwable t) { - + public void accept(Throwable t) { + } }); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), list); } - + @Test public void subscribeAction1Action1Throws() { final List list = new ArrayList(); - + final Throwable[] error = { null }; - - Ix.range(1, 5).subscribe(new Action1() { + + Ix.range(1, 5).subscribe(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { if (v == 5) { throw new IllegalStateException(); } list.add(v); } - }, new Action1() { + }, new IxConsumer() { @Override - public void call(Throwable t) { + public void accept(Throwable t) { error[0] = t; } }); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4), list); Assert.assertTrue(String.valueOf(error[0]), error[0] instanceof IllegalStateException); } - + @Test public void subscribeAction1Action1Action0() { final List list = new ArrayList(); - - Ix.range(1, 5).subscribe(new Action1() { + + Ix.range(1, 5).subscribe(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { list.add(v); } - }, new Action1() { + }, new IxConsumer() { @Override - public void call(Throwable t) { - + public void accept(Throwable t) { + } - }, new Action0() { + }, new Runnable() { @Override - public void call() { + public void run() { list.add(100); } }); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5, 100), list); } - + @Test public void subscribeAction1Action1Action0Throws() { final List list = new ArrayList(); - + final Throwable[] error = { null }; - - Ix.range(1, 5).subscribe(new Action1() { + + Ix.range(1, 5).subscribe(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { if (v == 5) { throw new IllegalStateException(); } list.add(v); } - }, new Action1() { + }, new IxConsumer() { @Override - public void call(Throwable t) { + public void accept(Throwable t) { error[0] = t; } - }, new Action0() { + }, new Runnable() { @Override - public void call() { + public void run() { list.add(100); } }); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4), list); Assert.assertTrue(String.valueOf(error[0]), error[0] instanceof IllegalStateException); } - - @Test - public void subscribeObserver() { - TestSubscriber ts = new TestSubscriber(); - Ix.range(1, 5).subscribe((rx.Observer)ts); - - ts.assertValues(1, 2, 3, 4, 5); - ts.assertNoErrors(); - ts.assertCompleted(); - } - @Test - public void subscribeObserverThrows() { - TestSubscriber ts = new TestSubscriber(); - Ix.range(1, 5) - .doOnNext(new Action1() { - @Override - public void call(Integer v) { - if (v == 5) { - throw new IllegalStateException(); - } - } - }) - .subscribe((rx.Observer)ts); - - ts.assertValues(1, 2, 3, 4); - ts.assertError(IllegalStateException.class); - ts.assertNotCompleted(); - } - - @Test - public void subscribeSubscriber() { - TestSubscriber ts = new TestSubscriber(); - Ix.range(1, 5).subscribe(ts); - - ts.assertValues(1, 2, 3, 4, 5); - ts.assertNoErrors(); - ts.assertCompleted(); - } - - @Test - public void subscribeSubscriberTakeLess() { - TestSubscriber ts = new TestSubscriber() { - @Override - public void onNext(Integer t) { - super.onNext(t); - if (t == 4) { - unsubscribe(); - } - } - }; - Ix.range(1, 5).subscribe(ts); - - ts.assertValues(1, 2, 3, 4); - ts.assertNoErrors(); - ts.assertNotCompleted(); - } - - @Test - public void subscribeSubscriberTakeLessAndThrow() { - TestSubscriber ts = new TestSubscriber() { - @Override - public void onNext(Integer t) { - super.onNext(t); - if (t == 4) { - unsubscribe(); - throw new IllegalStateException(); - } - } - }; - Ix.range(1, 5).subscribe(ts); - - ts.assertValues(1, 2, 3, 4); - ts.assertNoErrors(); - ts.assertNotCompleted(); - } - - @Test - public void subscribeSubscriberThrow() { - TestSubscriber ts = new TestSubscriber() { - @Override - public void onNext(Integer t) { - super.onNext(t); - if (t == 4) { - throw new IllegalStateException(); - } - } - }; - Ix.range(1, 5).subscribe(ts); - - ts.assertValues(1, 2, 3, 4); - ts.assertError(IllegalStateException.class); - ts.assertNotCompleted(); - } - - @Test - public void subscribeSubscriberThrows() { - TestSubscriber ts = new TestSubscriber(); - Ix.range(1, 5) - .doOnNext(new Action1() { - @Override - public void call(Integer v) { - if (v == 5) { - throw new IllegalStateException(); - } - } - }) - .subscribe(ts); - - ts.assertValues(1, 2, 3, 4); - ts.assertError(IllegalStateException.class); - ts.assertNotCompleted(); - } - - @Test - public void subscribeSubscriberTakeExact() { - TestSubscriber ts = new TestSubscriber() { - @Override - public void onNext(Integer t) { - super.onNext(t); - if (t == 5) { - unsubscribe(); - } - } - }; - Ix.range(1, 5).subscribe(ts); - - ts.assertValues(1, 2, 3, 4, 5); - ts.assertNoErrors(); - ts.assertNotCompleted(); - } - @Test public void retainAll() { List list = Ix.range(1, 10).collectToList().first(); - - Ix.from(list).retainAll(new Pred() { + + Ix.from(list).retainAll(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) == 0; } }); - + Assert.assertEquals(Arrays.asList(2, 4, 6, 8, 10), list); } - + @Test public void removeAll() { List list = Ix.range(1, 10).collectToList().first(); - - Ix.from(list).removeAll(new Pred() { + + Ix.from(list).removeAll(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) == 1; } }); - + Assert.assertEquals(Arrays.asList(2, 4, 6, 8, 10), list); } - + @Test public void single() { Assert.assertEquals(1, Ix.just(1).single().intValue()); diff --git a/src/test/java/ix/LiftTest.java b/src/test/java/ix/LiftTest.java index 62e96ee..2fa3413 100644 --- a/src/test/java/ix/LiftTest.java +++ b/src/test/java/ix/LiftTest.java @@ -20,26 +20,24 @@ import org.junit.Test; -import rx.functions.Func1; - public class LiftTest { @Test public void normal() { - Ix source = Ix.just(1).lift(new Func1, Iterator>() { + Ix source = Ix.just(1).lift(new IxFunction, Iterator>() { @Override - public Iterator call(final Iterator it) { + public Iterator apply(final Iterator it) { return new Iterator() { @Override public boolean hasNext() { return it.hasNext(); } - + @Override public Integer next() { return it.next() + 10; } - + @Override public void remove() { throw new UnsupportedOperationException(); @@ -47,9 +45,9 @@ public void remove() { }; } }); - + IxTestHelper.assertValues(source, 11); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/MapTest.java b/src/test/java/ix/MapTest.java index 29c67f9..189a952 100644 --- a/src/test/java/ix/MapTest.java +++ b/src/test/java/ix/MapTest.java @@ -20,33 +20,31 @@ import org.junit.*; -import rx.functions.Func1; - public class MapTest { @Test public void normal() { - Ix source = Ix.range(1, 10).map(new Func1() { + Ix source = Ix.range(1, 10).map(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v + 1; } }); - + IxTestHelper.assertValues(source, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); } - + @Test public void removeComposes() { List list = Ix.range(1, 10).collectToList().first(); - - Ix.from(list).map(new Func1() { + + Ix.from(list).map(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v + 1; } }).removeAll(); - + Assert.assertEquals(Arrays.asList(), list); } } diff --git a/src/test/java/ix/MaxTest.java b/src/test/java/ix/MaxTest.java index 5ad0d65..22c291e 100644 --- a/src/test/java/ix/MaxTest.java +++ b/src/test/java/ix/MaxTest.java @@ -25,42 +25,42 @@ public class MaxTest { @Test public void normal() { Ix source = Ix.range(1, 10).maxInt(); - + assertEquals(10L, source.first().intValue()); } @Test public void just() { Ix source = Ix.just(1).maxInt(); - + assertEquals(1, source.first().intValue()); } @Test public void empty() { Ix source = Ix.empty().maxInt(); - + IxTestHelper.assertValues(source); } @Test public void normalLong() { Ix source = Ix.range(1, 10).toLong().maxLong(); - + assertEquals(10L, source.first().longValue()); } @Test public void justLong() { Ix source = Ix.just(1L).maxLong(); - + assertEquals(1L, source.first().longValue()); } @Test public void emptyLong() { Ix source = Ix.empty().maxLong(); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/MinMaxTest.java b/src/test/java/ix/MinMaxTest.java index 741f8f3..770232e 100644 --- a/src/test/java/ix/MinMaxTest.java +++ b/src/test/java/ix/MinMaxTest.java @@ -30,10 +30,10 @@ public int compare(Integer a, Integer b) { return b.compareTo(a); } }); - + IxTestHelper.assertValues(source, 5); } - + @Test public void minComparatorEmpty() { Ix source = Ix.empty().min(new Comparator() { @@ -42,7 +42,7 @@ public int compare(Integer a, Integer b) { return b.compareTo(a); } }); - + IxTestHelper.assertValues(source); } @@ -54,7 +54,7 @@ public int compare(Integer a, Integer b) { return b.compareTo(a); } }); - + IxTestHelper.assertValues(source, 1); } @@ -66,10 +66,10 @@ public int compare(Integer a, Integer b) { return b.compareTo(a); } }); - + IxTestHelper.assertValues(source, 1); } - + @Test public void maxComparatorEmpty() { Ix source = Ix.empty().max(new Comparator() { @@ -78,7 +78,7 @@ public int compare(Integer a, Integer b) { return b.compareTo(a); } }); - + IxTestHelper.assertValues(source); } @@ -90,49 +90,49 @@ public int compare(Integer a, Integer b) { return b.compareTo(a); } }); - + IxTestHelper.assertValues(source, 1); } - + @Test public void min() { Ix source = Ix.range(1, 5).min(); - + IxTestHelper.assertValues(source, 1); } - + @Test public void minEmpty() { Ix source = Ix.empty().min(); - + IxTestHelper.assertValues(source); } @Test public void minJust() { Ix source = Ix.just(1).min(); - + IxTestHelper.assertValues(source, 1); } @Test public void max() { Ix source = Ix.range(1, 5).max(); - + IxTestHelper.assertValues(source, 5); } - + @Test public void maxEmpty() { Ix source = Ix.empty().max(); - + IxTestHelper.assertValues(source); } @Test public void maxJust() { Ix source = Ix.just(1).max(); - + IxTestHelper.assertValues(source, 1); } } diff --git a/src/test/java/ix/MinTest.java b/src/test/java/ix/MinTest.java index 49d1dd4..79c3e7b 100644 --- a/src/test/java/ix/MinTest.java +++ b/src/test/java/ix/MinTest.java @@ -25,42 +25,42 @@ public class MinTest { @Test public void normal() { Ix source = Ix.range(1, 10).minInt(); - + assertEquals(1, source.first().intValue()); } @Test public void just() { Ix source = Ix.just(1).minInt(); - + assertEquals(1, source.first().intValue()); } @Test public void empty() { Ix source = Ix.empty().minInt(); - + IxTestHelper.assertValues(source); } @Test public void normalLong() { Ix source = Ix.range(1, 10).toLong().minLong(); - + assertEquals(1, source.first().longValue()); } @Test public void justLong() { Ix source = Ix.just(1L).minLong(); - + assertEquals(1L, source.first().longValue()); } @Test public void emptyLong() { Ix source = Ix.empty().minLong(); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/OrderByTest.java b/src/test/java/ix/OrderByTest.java index c3c8e67..22d4867 100644 --- a/src/test/java/ix/OrderByTest.java +++ b/src/test/java/ix/OrderByTest.java @@ -20,16 +20,14 @@ import org.junit.Test; -import rx.functions.Func1; - public class OrderByTest { @Test public void normal() { Ix source = Ix.fromArray(5, 4, 3, 2, 1).orderBy(); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } @@ -41,53 +39,53 @@ public int compare(Integer a, Integer b) { return b.compareTo(a); } }); - + IxTestHelper.assertValues(source, 5, 4, 3, 2, 1); - + IxTestHelper.assertNoRemove(source); } @Test public void normalKeySelector() { - Ix source = Ix.fromArray(1, 2, 3, 4, 5).orderBy(new Func1() { + Ix source = Ix.fromArray(1, 2, 3, 4, 5).orderBy(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return 3 - v; } }); - + IxTestHelper.assertValues(source, 5, 4, 3, 2, 1); - + IxTestHelper.assertNoRemove(source); } @Test public void empty() { Ix source = Ix.empty().orderBy(); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } @Test public void just() { Ix source = Ix.just(1).orderBy(); - + IxTestHelper.assertValues(source, 1); - + IxTestHelper.assertNoRemove(source); } @Test public void normalReverse() { Ix source = Ix.range(1, 5).orderByReverse(); - + IxTestHelper.assertValues(source, 5, 4, 3, 2, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void normalComparatorReverse() { Ix source = Ix.fromArray(1, 2, 3, 4, 5).orderByReverse(new Comparator() { @@ -96,23 +94,23 @@ public int compare(Integer a, Integer b) { return b.compareTo(a); } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void normalKeySelectorReverse() { - Ix source = Ix.fromArray(1, 2, 3, 4, 5).orderByReverse(new Func1() { + Ix source = Ix.fromArray(1, 2, 3, 4, 5).orderByReverse(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return 3 - v; } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/PublishTest.java b/src/test/java/ix/PublishTest.java index 4431c39..c98252d 100644 --- a/src/test/java/ix/PublishTest.java +++ b/src/test/java/ix/PublishTest.java @@ -20,48 +20,46 @@ import org.junit.*; -import rx.functions.*; - public class PublishTest { @Test public void normal() { final int[] counter = { 0 }; Ix source = Ix.range(1, 5) - .doOnNext(new Action1() { + .doOnNext(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { counter[0]++; } }) .publish(); - + Iterator it1 = source.iterator(); Iterator it2 = source.iterator(); - + Assert.assertEquals(1, it1.next().intValue()); Assert.assertEquals(2, it2.next().intValue()); Assert.assertEquals(3, it1.next().intValue()); Assert.assertEquals(4, it2.next().intValue()); Assert.assertEquals(5, it1.next().intValue()); - + Assert.assertFalse(it1.hasNext()); Assert.assertFalse(it2.hasNext()); - + Iterator it3 = source.iterator(); Assert.assertFalse(it3.hasNext()); - + Assert.assertEquals(5, counter[0]); } - + @Test public void selector() { - Ix source = Ix.range(1, 5).publish(new Func1, Iterable>() { + Ix source = Ix.range(1, 5).publish(new IxFunction, Iterable>() { @Override - public Iterable call(Ix o) { - return Ix.zip(o, o.skip(1), new Func2() { + public Iterable apply(Ix o) { + return Ix.zip(o, o.skip(1), new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); @@ -69,25 +67,25 @@ public Integer call(Integer t1, Integer t2) { }) ; source.println(); - + IxTestHelper.assertValues(source, 4, 9); } @Test public void selector2() { - Ix source = Ix.range(1, 5).publish(new Func1, Iterable>() { + Ix source = Ix.range(1, 5).publish(new IxFunction, Iterable>() { @Override - public Iterable call(Ix o) { - return Ix.zip(o, o, new Func2() { + public Iterable apply(Ix o) { + return Ix.zip(o, o, new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); } }) ; - + IxTestHelper.assertValues(source, 3, 7); } diff --git a/src/test/java/ix/RangeTest.java b/src/test/java/ix/RangeTest.java index 5070456..afe4168 100644 --- a/src/test/java/ix/RangeTest.java +++ b/src/test/java/ix/RangeTest.java @@ -25,33 +25,33 @@ public class RangeTest { @Test public void normal() { Ix source = Ix.range(1, 10); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - + IxTestHelper.assertNoRemove(source); } - + @Test(expected = UnsupportedOperationException.class) public void cantRemove() { Iterator it = Ix.range(1, 10).iterator(); it.next(); it.remove(); } - + @Test public void empty() { Ix source = Ix.range(1, 0); - + Assert.assertSame(Ix.empty(), source); } - + @Test public void just() { Ix source = Ix.range(1, 1); - + Assert.assertTrue(source.getClass().toString(), source instanceof IxScalarCallable); } - + @Test public void negativeRange() { try { diff --git a/src/test/java/ix/ReduceTest.java b/src/test/java/ix/ReduceTest.java index 08241e3..4f6008b 100644 --- a/src/test/java/ix/ReduceTest.java +++ b/src/test/java/ix/ReduceTest.java @@ -16,52 +16,50 @@ package ix; -import org.junit.Test; - -import rx.functions.*; +import static org.junit.Assert.assertEquals; -import static org.junit.Assert.*; +import org.junit.Test; public class ReduceTest { @Test public void normal() { - Ix source = Ix.range(1, 10).reduce(new Func0() { + Ix source = Ix.range(1, 10).reduce(new IxSupplier() { @Override - public Integer call() { + public Integer get() { return 0; } - }, new Func2() { + }, new IxFunction2() { @Override - public Integer call(Integer a, Integer b) { + public Integer apply(Integer a, Integer b) { return a + b; } }); - + assertEquals(55, source.first().intValue()); } - + @Test public void aggregate() { - Ix source = Ix.range(1, 10).reduce(new Func2() { + Ix source = Ix.range(1, 10).reduce(new IxFunction2() { @Override - public Integer call(Integer a, Integer b) { + public Integer apply(Integer a, Integer b) { return a + b; } }); - + assertEquals(55, source.first().intValue()); } - + @Test public void aggregateEmpty() { - Ix source = Ix.empty().reduce(new Func2() { + Ix source = Ix.empty().reduce(new IxFunction2() { @Override - public Integer call(Integer a, Integer b) { + public Integer apply(Integer a, Integer b) { return a + b; } }); - + IxTestHelper.assertValues(source); } } diff --git a/src/test/java/ix/RemoveRetainTest.java b/src/test/java/ix/RemoveRetainTest.java index 16448fb..ad541ca 100644 --- a/src/test/java/ix/RemoveRetainTest.java +++ b/src/test/java/ix/RemoveRetainTest.java @@ -25,14 +25,14 @@ public class RemoveRetainTest { @Test public void removeNormal() { List list = IxTestHelper.range(1, 10); - - Ix source = Ix.from(list).remove(new Pred() { + + Ix source = Ix.from(list).remove(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) != 0; } }); - + IxTestHelper.assertValues(source, 2, 4, 6, 8, 10); IxTestHelper.assertValues(list, 2, 4, 6, 8, 10); } @@ -40,29 +40,29 @@ public boolean test(Integer v) { @Test public void removeAll() { List list = IxTestHelper.range(1, 10); - - Ix source = Ix.from(list).remove(new Pred() { + + Ix source = Ix.from(list).remove(new IxPredicate() { @Override public boolean test(Integer v) { return true; } }); - + IxTestHelper.assertValues(source); IxTestHelper.assertValues(list); } - + @Test public void removeNone() { List list = IxTestHelper.range(1, 10); - - Ix source = Ix.from(list).remove(new Pred() { + + Ix source = Ix.from(list).remove(new IxPredicate() { @Override public boolean test(Integer v) { return false; } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); IxTestHelper.assertValues(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @@ -70,14 +70,14 @@ public boolean test(Integer v) { @Test public void removeEmpty() { List list = IxTestHelper.range(1, 0); - - Ix source = Ix.from(list).remove(new Pred() { + + Ix source = Ix.from(list).remove(new IxPredicate() { @Override public boolean test(Integer v) { return true; } }); - + IxTestHelper.assertValues(source); IxTestHelper.assertValues(list); } @@ -85,14 +85,14 @@ public boolean test(Integer v) { @Test public void retainNormal() { List list = IxTestHelper.range(1, 10); - - Ix source = Ix.from(list).retain(new Pred() { + + Ix source = Ix.from(list).retain(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) != 0; } }); - + IxTestHelper.assertValues(source, 1, 3, 5, 7, 9); IxTestHelper.assertValues(list, 1, 3, 5, 7, 9); } @@ -100,29 +100,29 @@ public boolean test(Integer v) { @Test public void retainAll() { List list = IxTestHelper.range(1, 10); - - Ix source = Ix.from(list).retain(new Pred() { + + Ix source = Ix.from(list).retain(new IxPredicate() { @Override public boolean test(Integer v) { return true; } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); IxTestHelper.assertValues(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } - + @Test public void retainNone() { List list = IxTestHelper.range(1, 10); - - Ix source = Ix.from(list).retain(new Pred() { + + Ix source = Ix.from(list).retain(new IxPredicate() { @Override public boolean test(Integer v) { return false; } }); - + IxTestHelper.assertValues(source); IxTestHelper.assertValues(list); } @@ -130,54 +130,54 @@ public boolean test(Integer v) { @Test public void retainEmpty() { List list = IxTestHelper.range(1, 0); - - Ix source = Ix.from(list).retain(new Pred() { + + Ix source = Ix.from(list).retain(new IxPredicate() { @Override public boolean test(Integer v) { return false; } }); - + IxTestHelper.assertValues(source); IxTestHelper.assertValues(list); } - + @Test public void removeAllDouble() { List list = IxTestHelper.range(1, 10); - - Ix source = Ix.from(list).remove(new Pred() { + + Ix source = Ix.from(list).remove(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) != 0; } - }).remove(new Pred() { + }).remove(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) == 0; } }); - + IxTestHelper.assertValues(source); IxTestHelper.assertValues(list); } - + @Test public void retainNoneDouble() { List list = IxTestHelper.range(1, 10); - - Ix source = Ix.from(list).retain(new Pred() { + + Ix source = Ix.from(list).retain(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) != 0; } - }).retain(new Pred() { + }).retain(new IxPredicate() { @Override public boolean test(Integer v) { return (v & 1) == 0; } }); - + IxTestHelper.assertValues(source); IxTestHelper.assertValues(list); } diff --git a/src/test/java/ix/RepeatTest.java b/src/test/java/ix/RepeatTest.java index aa61b48..0f9da8a 100644 --- a/src/test/java/ix/RepeatTest.java +++ b/src/test/java/ix/RepeatTest.java @@ -23,86 +23,86 @@ public class RepeatTest { @Test public void normal() { Ix source = Ix.repeatValue(1).take(5); - + IxTestHelper.assertValues(source, 1, 1, 1, 1, 1); - + IxTestHelper.assertNoRemove(source); } @Test public void normalLimited() { Ix source = Ix.repeatValue(1, 5); - + IxTestHelper.assertValues(source, 1, 1, 1, 1, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void neverRepeat() { Ix source = Ix.repeatValue(1, 0); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } @Test public void repeatOnce() { Ix source = Ix.repeatValue(1, 1); - + IxTestHelper.assertValues(source, 1); - + IxTestHelper.assertNoRemove(source); } @Test public void predicateLimited() { - Ix source = Ix.repeatValue(1, new Pred0() { + Ix source = Ix.repeatValue(1, new IxBooleanSupplier() { int count = 5; @Override public boolean getAsBoolean() { return count-- == 0; } }); - + IxTestHelper.assertValues(source, 1, 1, 1, 1, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void predicateNeverRepeat() { - Ix source = Ix.repeatValue(1, new Pred0() { + Ix source = Ix.repeatValue(1, new IxBooleanSupplier() { @Override public boolean getAsBoolean() { return true; } }); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } @Test public void predicateRepeatOnce() { - Ix source = Ix.repeatValue(1, new Pred0() { + Ix source = Ix.repeatValue(1, new IxBooleanSupplier() { int count = 1; @Override public boolean getAsBoolean() { return count-- == 0; } }); - + IxTestHelper.assertValues(source, 1); - + IxTestHelper.assertNoRemove(source); } @Test public void predicateInfinite() { - Ix source = Ix.repeatValue(1, new Pred0() { + Ix source = Ix.repeatValue(1, new IxBooleanSupplier() { @Override public boolean getAsBoolean() { return false; @@ -110,108 +110,108 @@ public boolean getAsBoolean() { }).take(5); IxTestHelper.assertValues(source, 1, 1, 1, 1, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void predicateCountedLimited() { - Ix source = Ix.repeatValue(1, 3L, new Pred0() { + Ix source = Ix.repeatValue(1, 3L, new IxBooleanSupplier() { int count = 5; @Override public boolean getAsBoolean() { return count-- == 0; } }); - + IxTestHelper.assertValues(source, 1, 1, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void normalInstance() { Ix source = Ix.just(1).repeat().take(5); - + IxTestHelper.assertValues(source, 1, 1, 1, 1, 1); - + IxTestHelper.assertNoRemove(source); } @Test public void normalInstanceLimited() { Ix source = Ix.just(1).repeat(5); - + IxTestHelper.assertValues(source, 1, 1, 1, 1, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void neverRepeatInstance() { Ix source = Ix.just(1).repeat(0); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } @Test public void repeatOnceInstance() { Ix source = Ix.just(1).repeat(1); - + IxTestHelper.assertValues(source, 1); - + IxTestHelper.assertNoRemove(source); } @Test public void predicateLimitedInstance() { - Ix source = Ix.just(1).repeat(new Pred0() { + Ix source = Ix.just(1).repeat(new IxBooleanSupplier() { int count = 5; @Override public boolean getAsBoolean() { return count-- == 0; } }); - + IxTestHelper.assertValues(source, 1, 1, 1, 1, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void predicateNeverRepeatInstance() { - Ix source = Ix.just(1).repeat(new Pred0() { + Ix source = Ix.just(1).repeat(new IxBooleanSupplier() { @Override public boolean getAsBoolean() { return true; } }); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } @Test public void predicateRepeatOnceInstance() { - Ix source = Ix.just(1).repeat(new Pred0() { + Ix source = Ix.just(1).repeat(new IxBooleanSupplier() { int count = 1; @Override public boolean getAsBoolean() { return count-- == 0; } }); - + IxTestHelper.assertValues(source, 1); - + IxTestHelper.assertNoRemove(source); } @Test public void predicateInfiniteInstance() { - Ix source = Ix.just(1).repeat(new Pred0() { + Ix source = Ix.just(1).repeat(new IxBooleanSupplier() { @Override public boolean getAsBoolean() { return false; @@ -219,22 +219,22 @@ public boolean getAsBoolean() { }).take(5); IxTestHelper.assertValues(source, 1, 1, 1, 1, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void predicateCountedLimitedInstance() { - Ix source = Ix.just(1).repeat(3L, new Pred0() { + Ix source = Ix.just(1).repeat(3L, new IxBooleanSupplier() { int count = 5; @Override public boolean getAsBoolean() { return count-- == 0; } }); - + IxTestHelper.assertValues(source, 1, 1, 1); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/ReplayTest.java b/src/test/java/ix/ReplayTest.java index db0ac97..6221375 100644 --- a/src/test/java/ix/ReplayTest.java +++ b/src/test/java/ix/ReplayTest.java @@ -20,17 +20,15 @@ import org.junit.*; -import rx.functions.*; - public class ReplayTest { @Test public void normal() { final int[] counter = { 0 }; Ix source = Ix.range(1, 5) - .doOnNext(new Action1() { + .doOnNext(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { counter[0]++; } }) @@ -39,17 +37,17 @@ public void call(Integer v) { IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + Assert.assertEquals(5, counter[0]); } - + @Test public void lockstep() { final int[] counter = { 0 }; Ix source = Ix.range(1, 5) - .doOnNext(new Action1() { + .doOnNext(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { counter[0]++; } }) @@ -57,7 +55,7 @@ public void call(Integer v) { Iterator it1 = source.iterator(); Iterator it2 = source.iterator(); - + Assert.assertEquals(1, it1.next().intValue()); Assert.assertEquals(1, it2.next().intValue()); @@ -77,25 +75,25 @@ public void call(Integer v) { Assert.assertFalse(it1.hasNext()); Assert.assertEquals(5, counter[0]); - + } - + @Test public void empty() { Ix source = Ix.empty().replay(); - + IxTestHelper.assertValues(source); IxTestHelper.assertValues(source); IxTestHelper.assertValues(source); } - + @Test public void replaySizeNormal() { final int[] counter = { 0 }; Ix source = Ix.range(1, 5) - .doOnNext(new Action1() { + .doOnNext(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { counter[0]++; } }) @@ -104,7 +102,7 @@ public void call(Integer v) { IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + Assert.assertEquals(5, counter[0]); } @@ -112,9 +110,9 @@ public void call(Integer v) { public void replaySizeLimit() { final int[] counter = { 0 }; Ix source = Ix.range(1, 5) - .doOnNext(new Action1() { + .doOnNext(new IxConsumer() { @Override - public void call(Integer v) { + public void accept(Integer v) { counter[0]++; } }) @@ -123,78 +121,78 @@ public void call(Integer v) { IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); IxTestHelper.assertValues(source, 4, 5); IxTestHelper.assertValues(source, 4, 5); - + Assert.assertEquals(5, counter[0]); } @Test public void replaySelectorNormal() { - - Ix source = Ix.range(1, 5).replay(new Func1, Iterable>() { + + Ix source = Ix.range(1, 5).replay(new IxFunction, Iterable>() { @Override - public Iterable call(Ix o) { - return Ix.zip(o, o.skip(1), new Func2() { + public Iterable apply(Ix o) { + return Ix.zip(o, o.skip(1), new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); } }); - + IxTestHelper.assertValues(source, 3, 5, 7, 9); IxTestHelper.assertValues(source, 3, 5, 7, 9); } - + @Test public void replaySizeSelectorLarge() { - - Ix source = Ix.range(1, 5).replay(10, new Func1, Iterable>() { + + Ix source = Ix.range(1, 5).replay(10, new IxFunction, Iterable>() { @Override - public Iterable call(Ix o) { - return Ix.zip(o, o.skip(1), new Func2() { + public Iterable apply(Ix o) { + return Ix.zip(o, o.skip(1), new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); } }); - + IxTestHelper.assertValues(source, 3, 5, 7, 9); IxTestHelper.assertValues(source, 3, 5, 7, 9); } - + @Test public void replaySizeSelectorSmall() { - - Ix source = Ix.range(1, 5).replay(2, new Func1, Iterable>() { + + Ix source = Ix.range(1, 5).replay(2, new IxFunction, Iterable>() { @Override - public Iterable call(Ix o) { - return Ix.zip(o, o.skip(1), new Func2() { + public Iterable apply(Ix o) { + return Ix.zip(o, o.skip(1), new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); } }); - + IxTestHelper.assertValues(source, 3, 5, 7, 9); IxTestHelper.assertValues(source, 3, 5, 7, 9); } - + @Test public void replaySizeSelectorInnerEffect() { - - Ix source = Ix.range(1, 5).replay(2, new Func1, Iterable>() { + + Ix source = Ix.range(1, 5).replay(2, new IxFunction, Iterable>() { @SuppressWarnings("unchecked") @Override - public Iterable call(Ix o) { + public Iterable apply(Ix o) { return Ix.concatArray(o, o); } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 4, 5); IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 4, 5); } diff --git a/src/test/java/ix/ReverseTest.java b/src/test/java/ix/ReverseTest.java index 7e0c1c0..961d36d 100644 --- a/src/test/java/ix/ReverseTest.java +++ b/src/test/java/ix/ReverseTest.java @@ -23,18 +23,18 @@ public class ReverseTest { @Test public void normal() { Ix source = Ix.range(1, 5).reverse(); - + IxTestHelper.assertValues(source, 5, 4, 3, 2, 1); - + IxTestHelper.assertNoRemove(source); } @Test public void empty() { Ix source = Ix.empty().reverse(); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } diff --git a/src/test/java/ix/ScanTest.java b/src/test/java/ix/ScanTest.java index 3b5e3a6..14d1fc9 100644 --- a/src/test/java/ix/ScanTest.java +++ b/src/test/java/ix/ScanTest.java @@ -18,106 +18,104 @@ import org.junit.Test; -import rx.functions.*; - public class ScanTest { @Test public void normal() { - Ix source = Ix.range(1, 5).scan(new Func2() { + Ix source = Ix.range(1, 5).scan(new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); - + IxTestHelper.assertValues(source, 1, 3, 6, 10, 15); - + IxTestHelper.assertNoRemove(source); } - + @Test public void just() { - Ix source = Ix.just(1).scan(new Func2() { + Ix source = Ix.just(1).scan(new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); - + IxTestHelper.assertValues(source, 1); - + IxTestHelper.assertNoRemove(source); } - + @Test public void empty() { - Ix source = Ix.empty().scan(new Func2() { + Ix source = Ix.empty().scan(new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } - + @Test public void normalSeed() { - Ix source = Ix.range(1, 5).scan(new Func0() { + Ix source = Ix.range(1, 5).scan(new IxSupplier() { @Override - public Integer call() { + public Integer get() { return 100; } - },new Func2() { + },new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); - + IxTestHelper.assertValues(source, 100, 101, 103, 106, 110, 115); - + IxTestHelper.assertNoRemove(source); } - + @Test public void justSeed() { - Ix source = Ix.just(1).scan(new Func0() { + Ix source = Ix.just(1).scan(new IxSupplier() { @Override - public Integer call() { + public Integer get() { return 100; } - }, new Func2() { + }, new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); - + IxTestHelper.assertValues(source, 100, 101); - + IxTestHelper.assertNoRemove(source); } - + @Test public void emptySeed() { - Ix source = Ix.empty().scan(new Func0() { + Ix source = Ix.empty().scan(new IxSupplier() { @Override - public Integer call() { + public Integer get() { return 100; } - }, new Func2() { + }, new IxFunction2() { @Override - public Integer call(Integer t1, Integer t2) { + public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }); - + IxTestHelper.assertValues(source, 100); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/SelfComparatorTest.java b/src/test/java/ix/SelfComparatorTest.java index b23c801..bbf9112 100644 --- a/src/test/java/ix/SelfComparatorTest.java +++ b/src/test/java/ix/SelfComparatorTest.java @@ -16,10 +16,10 @@ package ix; -import org.junit.Test; - -import static org.junit.Assert.*; import static ix.SelfComparator.INSTANCE; +import static org.junit.Assert.*; + +import org.junit.Test; public class SelfComparatorTest { @@ -29,11 +29,11 @@ public void normal() { assertEquals(0, INSTANCE.compare(1, new Integer(1))); assertTrue(INSTANCE.compare(1, 2) < 0); - + assertTrue(INSTANCE.compare(2, 1) > 0); assertNotNull(SelfComparator.valueOf("INSTANCE")); - + assertEquals(1, SelfComparator.values().length); } } diff --git a/src/test/java/ix/SequenceEqualTest.java b/src/test/java/ix/SequenceEqualTest.java index 37ee340..efb94df 100644 --- a/src/test/java/ix/SequenceEqualTest.java +++ b/src/test/java/ix/SequenceEqualTest.java @@ -23,48 +23,48 @@ public class SequenceEqualTest { @Test public void normal() { Ix source = Ix.range(1, 5).sequenceEqual(Ix.range(1, 5)); - + IxTestHelper.assertValues(source, true); } @Test public void firstSorter() { Ix source = Ix.range(1, 4).sequenceEqual(Ix.range(1, 5)); - + IxTestHelper.assertValues(source, false); } @Test public void secondSorter() { Ix source = Ix.range(1, 5).sequenceEqual(Ix.range(1, 4)); - + IxTestHelper.assertValues(source, false); } @Test public void firstEmpty() { Ix source = Ix.empty().sequenceEqual(Ix.range(1, 5)); - + IxTestHelper.assertValues(source, false); } @Test public void secondEmpty() { Ix source = Ix.range(1, 5).sequenceEqual(Ix.empty()); - + IxTestHelper.assertValues(source, false); } @Test public void empty() { Ix source = Ix.empty().sequenceEqual(Ix.empty()); - + IxTestHelper.assertValues(source, true); } - + @Test public void different() { Ix source = Ix.fromArray(1, 2, 3, 3, 5).sequenceEqual(Ix.range(1, 5)); - + IxTestHelper.assertValues(source, false); } } diff --git a/src/test/java/ix/SkipLastTest.java b/src/test/java/ix/SkipLastTest.java index d7e5685..732a455 100644 --- a/src/test/java/ix/SkipLastTest.java +++ b/src/test/java/ix/SkipLastTest.java @@ -23,42 +23,42 @@ public class SkipLastTest { @Test public void normal() { Ix source = Ix.range(1, 10).skipLast(5); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); } @Test public void normalTwo() { Ix source = Ix.range(1, 2).skipLast(1); - + IxTestHelper.assertValues(source, 1); } @Test public void normalThree() { Ix source = Ix.range(1, 16).skipLast(1); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); } @Test public void zero() { Ix source = Ix.range(1, 10).skipLast(0); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void all() { Ix source = Ix.range(1, 10).skipLast(10); - + IxTestHelper.assertValues(source); } @Test public void more() { Ix source = Ix.range(1, 10).skipLast(15); - + IxTestHelper.assertValues(source); } @@ -66,21 +66,21 @@ public void more() { @Test public void just() { Ix source = Ix.just(1).skipLast(1); - + IxTestHelper.assertValues(source); } @Test public void empty() { Ix source = Ix.empty().skipLast(1); - + IxTestHelper.assertValues(source); } @Test public void emptyZero() { Ix source = Ix.empty().skipLast(0); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/SkipTest.java b/src/test/java/ix/SkipTest.java index 137aace..f4a32f1 100644 --- a/src/test/java/ix/SkipTest.java +++ b/src/test/java/ix/SkipTest.java @@ -23,35 +23,35 @@ public class SkipTest { @Test public void normal() { Ix source = Ix.range(1, 10).skip(5); - + IxTestHelper.assertValues(source, 6, 7, 8, 9, 10); } @Test public void zero() { Ix source = Ix.range(1, 10).skip(0); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void all() { Ix source = Ix.range(1, 10).skip(10); - + IxTestHelper.assertValues(source); } @Test public void empty() { Ix source = Ix.empty().skip(10); - + IxTestHelper.assertValues(source); } @Test public void emptyZero() { Ix source = Ix.empty().skip(0); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/SkipWhileTest.java b/src/test/java/ix/SkipWhileTest.java index 9dcefcf..51a616e 100644 --- a/src/test/java/ix/SkipWhileTest.java +++ b/src/test/java/ix/SkipWhileTest.java @@ -24,52 +24,52 @@ public class SkipWhileTest { @Test public void normal() { - Ix source = Ix.range(1, 10).skipWhile(new Pred() { + Ix source = Ix.range(1, 10).skipWhile(new IxPredicate() { @Override public boolean test(Integer v) { return v < 6; } }); - + IxTestHelper.assertValues(source, 6, 7, 8, 9, 10); - + IxTestHelper.assertNoRemove(source); } @Test public void skipAll() { - Ix source = Ix.range(1, 10).skipWhile(new Pred() { + Ix source = Ix.range(1, 10).skipWhile(new IxPredicate() { @Override public boolean test(Integer v) { return true; } }); - + IxTestHelper.assertValues(source); } @Test public void skipNone() { - Ix source = Ix.range(1, 10).skipWhile(new Pred() { + Ix source = Ix.range(1, 10).skipWhile(new IxPredicate() { @Override public boolean test(Integer v) { return false; } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void removeUnskipped() { List list = IxTestHelper.range(1, 10); - Ix.from(list).skipWhile(new Pred() { + Ix.from(list).skipWhile(new IxPredicate() { @Override public boolean test(Integer v) { return v < 6; } }).removeAll(); - + Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), list); } diff --git a/src/test/java/ix/SourceQueuedIteratorTest.java b/src/test/java/ix/SourceQueuedIteratorTest.java index a1ab17f..551a9cc 100644 --- a/src/test/java/ix/SourceQueuedIteratorTest.java +++ b/src/test/java/ix/SourceQueuedIteratorTest.java @@ -18,12 +18,10 @@ import org.junit.*; -import rx.functions.Action2; - public class SourceQueuedIteratorTest { IxSourceQueuedIterator it; - + @Before public void before() { it = new IxSourceQueuedIterator(Ix.empty().iterator()) { @@ -34,64 +32,64 @@ protected boolean moveNext() { } }; } - + @Test public void normal() { Assert.assertTrue(it.isEmpty()); Assert.assertEquals(null, it.peek()); it.offer(1); - + Assert.assertFalse(it.isEmpty()); - + Assert.assertEquals(1, it.peek()); Assert.assertEquals(1, it.poll()); Assert.assertTrue(it.isEmpty()); Assert.assertEquals(null, it.peek()); - + Assert.assertNull(it.poll()); Assert.assertTrue(it.isEmpty()); } - + @Test(expected = NullPointerException.class) public void nullOffer() { it.offer(null); } - + @Test public void clear() { Assert.assertTrue(it.isEmpty()); it.offer(1); - + Assert.assertFalse(it.isEmpty()); - + it.clear(); - + Assert.assertNull(it.poll()); Assert.assertTrue(it.isEmpty()); } - + @Test public void nullWraps() { Assert.assertSame(IxSourceQueuedIterator.NULL, it.toObject(null)); } - + @Test public void nullUnwraps() { Assert.assertNull(it.fromObject(IxSourceQueuedIterator.NULL)); } - + @Test public void foreach() { final int[] count = { 0 }; - it.foreach(new Action2() { + it.foreach(new IxConsumer2() { @Override - public void call(Integer a, Object b) { + public void accept(Integer a, Object b) { count[0]++; } }, null); - + Assert.assertEquals(0, count[0]); } } diff --git a/src/test/java/ix/SplitTest.java b/src/test/java/ix/SplitTest.java index da1c4c5..2e75bb7 100644 --- a/src/test/java/ix/SplitTest.java +++ b/src/test/java/ix/SplitTest.java @@ -23,45 +23,45 @@ public class SplitTest { @Test public void normal() { Ix source = Ix.split("a|b|c|d", "|"); - + IxTestHelper.assertValues(source, "a", "b", "c", "d"); - + IxTestHelper.assertNoRemove(source); } - + @Test public void normal2() { Ix source = Ix.split("a|b|c|", "|"); - + IxTestHelper.assertValues(source, "a", "b", "c", ""); - + IxTestHelper.assertNoRemove(source); } - + @Test public void normal3() { Ix source = Ix.split("a1|b2|c3", "|"); - + IxTestHelper.assertValues(source, "a1", "b2", "c3"); - + IxTestHelper.assertNoRemove(source); } - + @Test public void normal4() { Ix source = Ix.split("a1| source = Ix.split("", "|"); - + IxTestHelper.assertValues(source, ""); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/SumTest.java b/src/test/java/ix/SumTest.java index 3221aa4..b758f3d 100644 --- a/src/test/java/ix/SumTest.java +++ b/src/test/java/ix/SumTest.java @@ -25,42 +25,42 @@ public class SumTest { @Test public void normal() { Ix source = Ix.range(1, 10).sumInt(); - + assertEquals(55, source.first().intValue()); } @Test public void just() { Ix source = Ix.just(1).sumInt(); - + assertEquals(1, source.first().intValue()); } @Test public void empty() { Ix source = Ix.empty().sumInt(); - + IxTestHelper.assertValues(source); } @Test public void normalLong() { Ix source = Ix.range(1, 10).toLong().sumLong(); - + assertEquals(55L, source.first().longValue()); } @Test public void justLong() { Ix source = Ix.just(1L).sumLong(); - + assertEquals(1, source.first().intValue()); } @Test public void emptyLong() { Ix source = Ix.empty().sumLong(); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/SwitchIfEmptyTest.java b/src/test/java/ix/SwitchIfEmptyTest.java index 72cedac..9d30a3c 100644 --- a/src/test/java/ix/SwitchIfEmptyTest.java +++ b/src/test/java/ix/SwitchIfEmptyTest.java @@ -25,55 +25,55 @@ public class SwitchIfEmptyTest { @Test public void normal() { Ix source = Ix.range(1, 10).switchIfEmpty(Ix.range(11, 10)); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void empty() { Ix source = Ix.empty().switchIfEmpty(Ix.range(11, 10)); - + IxTestHelper.assertValues(source, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20); } @Test public void emptyOther() { Ix source = Ix.empty().switchIfEmpty(Ix.empty()); - + IxTestHelper.assertValues(source); } @Test public void defaultNormal() { Ix source = Ix.range(1, 10).defaultIfEmpty(100); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void defaultEmpty() { Ix source = Ix.empty().defaultIfEmpty(100); - + IxTestHelper.assertValues(source, 100); } - + @Test public void removeNonEmpty() { List list = IxTestHelper.range(1, 10); List list2 = IxTestHelper.range(11, 10); - + Ix.from(list).switchIfEmpty(Ix.from(list2)).removeAll(); - + IxTestHelper.assertValues(list); IxTestHelper.assertValues(list2, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20); } - + @Test public void removeEmpty() { List list2 = IxTestHelper.range(11, 10); - + Ix.empty().switchIfEmpty(Ix.from(list2)).removeAll(); - + IxTestHelper.assertValues(list2); } } diff --git a/src/test/java/ix/TakeLastTest.java b/src/test/java/ix/TakeLastTest.java index 2bd7988..8f4a8ee 100644 --- a/src/test/java/ix/TakeLastTest.java +++ b/src/test/java/ix/TakeLastTest.java @@ -23,42 +23,42 @@ public class TakeLastTest { @Test public void normal() { Ix source = Ix.range(1, 10).takeLast(5); - + IxTestHelper.assertValues(source, 6, 7, 8, 9, 10); } @Test public void normalTwo() { Ix source = Ix.range(1, 2).takeLast(1); - + IxTestHelper.assertValues(source, 2); } @Test public void normalThree() { Ix source = Ix.range(1, 16).takeLast(15); - + IxTestHelper.assertValues(source, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); } @Test public void zero() { Ix source = Ix.range(1, 10).takeLast(0); - + IxTestHelper.assertValues(source); } @Test public void all() { Ix source = Ix.range(1, 10).takeLast(10); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void more() { Ix source = Ix.range(1, 10).takeLast(15); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @@ -66,21 +66,21 @@ public void more() { @Test public void just() { Ix source = Ix.just(1).takeLast(1); - + IxTestHelper.assertValues(source, 1); } @Test public void empty() { Ix source = Ix.empty().takeLast(1); - + IxTestHelper.assertValues(source); } @Test public void emptyZero() { Ix source = Ix.empty().takeLast(0); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/TakeTest.java b/src/test/java/ix/TakeTest.java index 73cd0b2..ad186bb 100644 --- a/src/test/java/ix/TakeTest.java +++ b/src/test/java/ix/TakeTest.java @@ -25,51 +25,51 @@ public class TakeTest { @Test public void normal() { Ix source = Ix.range(1, 10).take(5); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); } @Test public void all() { Ix source = Ix.range(1, 10).take(10); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void more() { Ix source = Ix.range(1, 10).take(15); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void none() { Ix source = Ix.range(1, 10).take(0); - + IxTestHelper.assertValues(source); } @Test public void just() { Ix source = Ix.just(1).take(5); - + IxTestHelper.assertValues(source, 1); } @Test public void empty() { Ix source = Ix.empty().take(5); - + IxTestHelper.assertValues(source); } - + @Test public void removeComposes() { List list = Ix.range(1, 10).collectToList().first(); - + Ix.from(list).take(5).removeAll(); - + Assert.assertEquals(Arrays.asList(6, 7, 8, 9, 10), list); } diff --git a/src/test/java/ix/TakeUntilTest.java b/src/test/java/ix/TakeUntilTest.java index 1da5893..1217717 100644 --- a/src/test/java/ix/TakeUntilTest.java +++ b/src/test/java/ix/TakeUntilTest.java @@ -24,52 +24,52 @@ public class TakeUntilTest { @Test public void normal() { - Ix source = Ix.range(1, 10).takeUntil(new Pred() { + Ix source = Ix.range(1, 10).takeUntil(new IxPredicate() { @Override public boolean test(Integer v) { return v == 5; } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void takeOne() { - Ix source = Ix.range(1, 10).takeUntil(new Pred() { + Ix source = Ix.range(1, 10).takeUntil(new IxPredicate() { @Override public boolean test(Integer v) { return true; } }); - + IxTestHelper.assertValues(source, 1); } @Test public void takeAll() { - Ix source = Ix.range(1, 10).takeUntil(new Pred() { + Ix source = Ix.range(1, 10).takeUntil(new IxPredicate() { @Override public boolean test(Integer v) { return false; } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void removeUnskipped() { List list = IxTestHelper.range(1, 10); - Ix.from(list).takeUntil(new Pred() { + Ix.from(list).takeUntil(new IxPredicate() { @Override public boolean test(Integer v) { return v == 5; } }).removeAll(); - + Assert.assertEquals(Arrays.asList(6, 7, 8, 9, 10), list); } diff --git a/src/test/java/ix/TakeWhileTest.java b/src/test/java/ix/TakeWhileTest.java index 3fb70c8..662eb13 100644 --- a/src/test/java/ix/TakeWhileTest.java +++ b/src/test/java/ix/TakeWhileTest.java @@ -24,52 +24,52 @@ public class TakeWhileTest { @Test public void normal() { - Ix source = Ix.range(1, 10).takeWhile(new Pred() { + Ix source = Ix.range(1, 10).takeWhile(new IxPredicate() { @Override public boolean test(Integer v) { return v < 6; } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void takeAll() { - Ix source = Ix.range(1, 10).takeWhile(new Pred() { + Ix source = Ix.range(1, 10).takeWhile(new IxPredicate() { @Override public boolean test(Integer v) { return true; } }); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void takeNone() { - Ix source = Ix.range(1, 10).takeWhile(new Pred() { + Ix source = Ix.range(1, 10).takeWhile(new IxPredicate() { @Override public boolean test(Integer v) { return false; } }); - + IxTestHelper.assertValues(source); } @Test public void removeUnskipped() { List list = IxTestHelper.range(1, 10); - Ix.from(list).takeWhile(new Pred() { + Ix.from(list).takeWhile(new IxPredicate() { @Override public boolean test(Integer v) { return v < 6; } }).removeAll(); - + Assert.assertEquals(Arrays.asList(6, 7, 8, 9, 10), list); } diff --git a/src/test/java/ix/ToArrayTest.java b/src/test/java/ix/ToArrayTest.java index 7737f20..ac84213 100644 --- a/src/test/java/ix/ToArrayTest.java +++ b/src/test/java/ix/ToArrayTest.java @@ -23,7 +23,7 @@ public class ToArrayTest { @Test public void normal() { Ix source = Ix.range(1, 10).collectToArray(); - + IxTestHelper.assertValues(source, new Object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); } } diff --git a/src/test/java/ix/ToListTest.java b/src/test/java/ix/ToListTest.java index 30366a9..be0c346 100644 --- a/src/test/java/ix/ToListTest.java +++ b/src/test/java/ix/ToListTest.java @@ -16,17 +16,18 @@ package ix; +import static org.junit.Assert.assertEquals; + import org.junit.Test; -import static org.junit.Assert.*; public class ToListTest { @Test public void normal() { Ix source = Ix.just(1); - + assertEquals(1, source.iterator().next().intValue()); - + IxTestHelper.assertValues(source, 1); } } diff --git a/src/test/java/ix/ToMapTest.java b/src/test/java/ix/ToMapTest.java index 8c68fbc..6c64850 100644 --- a/src/test/java/ix/ToMapTest.java +++ b/src/test/java/ix/ToMapTest.java @@ -20,117 +20,115 @@ import org.junit.Test; -import rx.functions.Func1; - public class ToMapTest { @SuppressWarnings("unchecked") @Test public void normal() { - Ix> source = Ix.range(1, 5).collectToMap(new Func1() { + Ix> source = Ix.range(1, 5).collectToMap(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v % 3; } }); - + Map map = new HashMap(); map.put(1, 4); map.put(0, 3); map.put(2, 5); - + IxTestHelper.assertValues(source, map); } - + @SuppressWarnings("unchecked") @Test public void normalValueSelector() { - Ix> source = Ix.range(1, 5).collectToMap(new Func1() { + Ix> source = Ix.range(1, 5).collectToMap(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v % 3; } - }, new Func1() { + }, new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v * v; } }); - + Map map = new HashMap(); map.put(1, 16); map.put(0, 9); map.put(2, 25); - + IxTestHelper.assertValues(source, map); } @SuppressWarnings("unchecked") @Test public void empty() { - Ix> source = Ix.empty().collectToMap(new Func1() { + Ix> source = Ix.empty().collectToMap(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v % 3; } }); - + Map map = new HashMap(); - + IxTestHelper.assertValues(source, map); } - + @SuppressWarnings("unchecked") @Test public void multimap() { - Ix>> source = Ix.range(1, 5).collectToMultimap(new Func1() { + Ix>> source = Ix.range(1, 5).collectToMultimap(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v % 3; } }); - + Map> map = new HashMap>(); map.put(1, Arrays.asList(1, 4)); map.put(0, Arrays.asList(3)); map.put(2, Arrays.asList(2, 5)); - + IxTestHelper.assertValues(source, map); } - + @SuppressWarnings("unchecked") @Test public void multimapValueSelector() { - Ix>> source = Ix.range(1, 5).collectToMultimap(new Func1() { + Ix>> source = Ix.range(1, 5).collectToMultimap(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v % 3; } - }, new Func1() { + }, new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v * v; } }); - + Map> map = new HashMap>(); map.put(1, Arrays.asList(1, 16)); map.put(0, Arrays.asList(9)); map.put(2, Arrays.asList(4, 25)); - + IxTestHelper.assertValues(source, map); } @SuppressWarnings("unchecked") @Test public void multimapEmpty() { - Ix>> source = Ix.empty().collectToMultimap(new Func1() { + Ix>> source = Ix.empty().collectToMultimap(new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v % 3; } }); - + Map> map = new HashMap>(); - + IxTestHelper.assertValues(source, map); } } diff --git a/src/test/java/ix/ToSetTest.java b/src/test/java/ix/ToSetTest.java index 41ae7f5..535f4b2 100644 --- a/src/test/java/ix/ToSetTest.java +++ b/src/test/java/ix/ToSetTest.java @@ -26,9 +26,9 @@ public class ToSetTest { @Test public void normal() { Ix> source = Ix.range(1, 5).collectToSet(); - + IxTestHelper.assertValues(source, new HashSet(Arrays.asList(1, 2, 3, 4, 5))); - + IxTestHelper.assertNoRemove(source); } @@ -36,19 +36,19 @@ public void normal() { @Test public void empty() { Ix> source = Ix.empty().collectToSet(); - + IxTestHelper.assertValues(source, new HashSet()); - + IxTestHelper.assertNoRemove(source); } - + @SuppressWarnings("unchecked") @Test public void duplicates() { Ix> source = Ix.fromArray(1, 2, 2, 3, 2, 4, 5, 1, 5).collectToSet(); - + IxTestHelper.assertValues(source, new HashSet(Arrays.asList(1, 2, 3, 4, 5))); - + IxTestHelper.assertNoRemove(source); } diff --git a/src/test/java/ix/ToXTest.java b/src/test/java/ix/ToXTest.java index a31d7d5..aac4576 100644 --- a/src/test/java/ix/ToXTest.java +++ b/src/test/java/ix/ToXTest.java @@ -20,119 +20,117 @@ import org.junit.*; -import rx.functions.Func1; - public class ToXTest { @Test public void cast() { Ix source = Ix.just(1).cast(Object.class); - + IxTestHelper.assertValues(source, 1); - + IxTestHelper.assertNoRemove(source); } @Test(expected = ClassCastException.class) public void castInvalid() { Ix source = Ix.just(1).cast(String.class); - + String s = source.first(); - + Assert.assertEquals("1", s); } - + @Test public void toArray() { - + Assert.assertArrayEquals(new Object[] {1, 2, 3, 4, 5}, Ix.range(1, 5).toArray()); - + } @Test public void toArrayTemplate() { - + Assert.assertArrayEquals(new Integer[] {1, 2, 3, 4, 5}, Ix.range(1, 5).toArray(new Integer[5])); - + } - + @Test public void toList() { Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), Ix.range(1, 5).toList()); - + } @Test public void toSet() { Assert.assertEquals(new HashSet(Arrays.asList(1, 2, 3, 4, 5)), Ix.range(1, 5).toSet()); - + } @Test public void toMap() { Map map = Ix.range(1, 5).toMap(IdentityHelper.instance()); - + Map expected = new HashMap(); expected.put(1, 1); expected.put(2, 2); expected.put(3, 3); expected.put(4, 4); expected.put(5, 5); - + Assert.assertEquals(expected, map); } @Test public void toMapCustomValues() { - Map map = Ix.range(1, 5).toMap(IdentityHelper.instance(), new Func1() { + Map map = Ix.range(1, 5).toMap(IdentityHelper.instance(), new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v * v; } }); - + Map expected = new HashMap(); expected.put(1, 1); expected.put(2, 4); expected.put(3, 9); expected.put(4, 16); expected.put(5, 25); - + Assert.assertEquals(expected, map); } @Test public void toMultimap() { Map> map = Ix.range(1, 5).toMultimap(IdentityHelper.instance()); - + Map> expected = new HashMap>(); expected.put(1, Collections.singletonList(1)); expected.put(2, Collections.singletonList(2)); expected.put(3, Collections.singletonList(3)); expected.put(4, Collections.singletonList(4)); expected.put(5, Collections.singletonList(5)); - + Assert.assertEquals(expected, map); } @Test public void toMultimapCustomValues() { - Map> map = Ix.range(1, 5).toMultimap(IdentityHelper.instance(), new Func1() { + Map> map = Ix.range(1, 5).toMultimap(IdentityHelper.instance(), new IxFunction() { @Override - public Integer call(Integer v) { + public Integer apply(Integer v) { return v * v; } }); - + Map> expected = new HashMap>(); expected.put(1, Collections.singletonList(1)); expected.put(2, Collections.singletonList(4)); expected.put(3, Collections.singletonList(9)); expected.put(4, Collections.singletonList(16)); expected.put(5, Collections.singletonList(25)); - + Assert.assertEquals(expected, map); } } diff --git a/src/test/java/ix/TransformTest.java b/src/test/java/ix/TransformTest.java index 450d1dc..f260736 100644 --- a/src/test/java/ix/TransformTest.java +++ b/src/test/java/ix/TransformTest.java @@ -20,75 +20,73 @@ import org.junit.*; -import rx.functions.Action1; - public class TransformTest { @Test public void normal() { Ix source = Ix.just(1).transform(new IxTransform() { @Override - public int moveNext(Iterator it, Action1 out) { + public int moveNext(Iterator it, IxConsumer out) { if (it.hasNext()) { - out.call(it.next() + 10); + out.accept(it.next() + 10); return IxTransform.NEXT; } - out.call(12); + out.accept(12); return IxTransform.LAST; } }); - + IxTestHelper.assertValues(source, 11, 12); - + IxTestHelper.assertNoRemove(source); } - + @Test public void stop() { Ix source = Ix.just(1).transform(new IxTransform() { @Override - public int moveNext(Iterator it, Action1 out) { + public int moveNext(Iterator it, IxConsumer out) { return IxTransform.STOP; } }); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } - + @Test public void doubleNext() { try { Ix source = Ix.just(1).transform(new IxTransform() { @Override - public int moveNext(Iterator it, Action1 out) { - out.call(1); - out.call(2); + public int moveNext(Iterator it, IxConsumer out) { + out.accept(1); + out.accept(2); return IxTransform.NEXT; } }); - + IxTestHelper.assertValues(source); - + Assert.fail("Failed to throw IllegalStateException"); } catch (IllegalStateException ex) { Assert.assertEquals("Value already set in this turn!", ex.getMessage()); } } - + @Test public void returnNextWithoutValue() { try { Ix source = Ix.just(1).transform(new IxTransform() { @Override - public int moveNext(Iterator it, Action1 out) { + public int moveNext(Iterator it, IxConsumer out) { return IxTransform.NEXT; } }); - + IxTestHelper.assertValues(source); - + Assert.fail("Failed to throw IllegalStateException"); } catch (IllegalStateException ex) { Assert.assertEquals("No value set!", ex.getMessage()); diff --git a/src/test/java/ix/UnionTest.java b/src/test/java/ix/UnionTest.java index cbe1be9..2b94546 100644 --- a/src/test/java/ix/UnionTest.java +++ b/src/test/java/ix/UnionTest.java @@ -23,91 +23,91 @@ public class UnionTest { @Test public void distinct() { Ix source = Ix.range(1, 5).union(Ix.range(6, 5)); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - + IxTestHelper.assertNoRemove(source); } @Test public void overlap() { Ix source = Ix.range(1, 5).union(Ix.range(3, 5)); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5, 6, 7); - + IxTestHelper.assertNoRemove(source); } @Test public void overlapReverse() { Ix source = Ix.range(3, 5).union(Ix.range(1, 5)); - + IxTestHelper.assertValues(source, 3, 4, 5, 6, 7, 1, 2); - + IxTestHelper.assertNoRemove(source); } - + @Test public void same() { Ix source = Ix.range(1, 5).union(Ix.range(1, 5)); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void firstInSecond() { Ix source = Ix.range(1, 3).union(Ix.range(1, 5)); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void secondInFirst() { Ix source = Ix.range(1, 5).union(Ix.range(1, 3)); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } - + @Test public void firstEmpty() { Ix source = Ix.empty().union(Ix.range(1, 5)); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void secondEmpty() { Ix source = Ix.range(1, 5).union(Ix.empty()); - + IxTestHelper.assertValues(source, 1, 2, 3, 4, 5); - + IxTestHelper.assertNoRemove(source); } @Test public void bothEmpty() { Ix source = Ix.empty().union(Ix.empty()); - + IxTestHelper.assertValues(source); - + IxTestHelper.assertNoRemove(source); } - + @Test public void duplicates() { Ix source = Ix.fromArray(1, 2, 2, 1, 4, 5).union(Ix.fromArray(2, 3, 1, 5, 4)); - + IxTestHelper.assertValues(source, 1, 2, 4, 5, 3); - + IxTestHelper.assertNoRemove(source); } } diff --git a/src/test/java/ix/WindowTest.java b/src/test/java/ix/WindowTest.java index 00c6c28..2269ad0 100644 --- a/src/test/java/ix/WindowTest.java +++ b/src/test/java/ix/WindowTest.java @@ -27,31 +27,31 @@ public void normal() { Ix> source = Ix.range(1, 5).window(2); List> list = source.collectToList().first(); - + Assert.assertEquals(3, list.size()); IxTestHelper.assertValues(list.get(0), 1, 2); IxTestHelper.assertValues(list.get(1), 3, 4); IxTestHelper.assertValues(list.get(2), 5); } - + @Test public void normalSizeSkipSame() { Ix> source = Ix.range(1, 5).window(2, 2); List> list = source.collectToList().first(); - + Assert.assertEquals(3, list.size()); IxTestHelper.assertValues(list.get(0), 1, 2); IxTestHelper.assertValues(list.get(1), 3, 4); IxTestHelper.assertValues(list.get(2), 5); } - + @Test public void normalOne() { Ix> source = Ix.range(1, 5).window(1); List> list = source.collectToList().first(); - + Assert.assertEquals(5, list.size()); IxTestHelper.assertValues(list.get(0), 1); IxTestHelper.assertValues(list.get(1), 2); @@ -65,7 +65,7 @@ public void normalAll() { Ix> source = Ix.range(1, 5).window(5); List> list = source.collectToList().first(); - + Assert.assertEquals(1, list.size()); IxTestHelper.assertValues(list.get(0), 1, 2, 3, 4, 5); } @@ -75,22 +75,22 @@ public void normalMore() { Ix> source = Ix.range(1, 5).window(10); List> list = source.collectToList().first(); - + Assert.assertEquals(1, list.size()); IxTestHelper.assertValues(list.get(0), 1, 2, 3, 4, 5); } - + @Test public void innerMovesParent() { Ix> source = Ix.range(1, 5).window(3); Iterator> it0 = source.iterator(); - + Ix inner = it0.next(); - + Iterator it1 = inner.iterator(); - + try { inner.iterator(); Assert.fail("Should have thrown IllegalStateException"); @@ -109,18 +109,18 @@ public void normalSkip() { Ix> source = Ix.range(1, 5).window(2, 3); List> list = source.collectToList().first(); - + Assert.assertEquals(2, list.size()); IxTestHelper.assertValues(list.get(0), 1, 2); IxTestHelper.assertValues(list.get(1), 4, 5); } - + @Test public void normalSkip2() { Ix> source = Ix.range(1, 5).window(1, 2); List> list = source.collectToList().first(); - + Assert.assertEquals(3, list.size()); IxTestHelper.assertValues(list.get(0), 1); IxTestHelper.assertValues(list.get(1), 3); @@ -132,7 +132,7 @@ public void normalSkip3() { Ix> source = Ix.range(1, 5).window(1, 6); List> list = source.collectToList().first(); - + Assert.assertEquals(1, list.size()); IxTestHelper.assertValues(list.get(0), 1); } @@ -142,21 +142,21 @@ public void normalAllSkip() { Ix> source = Ix.range(1, 5).window(5, 10); List> list = source.collectToList().first(); - + Assert.assertEquals(1, list.size()); IxTestHelper.assertValues(list.get(0), 1, 2, 3, 4, 5); } - + @Test public void normalMoreSkip() { Ix> source = Ix.range(1, 5).window(10, 15); List> list = source.collectToList().first(); - + Assert.assertEquals(1, list.size()); IxTestHelper.assertValues(list.get(0), 1, 2, 3, 4, 5); } - + @Test public void justSkip() { Ix> source = Ix.just(1).window(2, 3); @@ -166,7 +166,7 @@ public void justSkip() { Assert.assertEquals(1, list.size()); IxTestHelper.assertValues(list.get(0), 1); } - + @Test public void emptySkip() { Ix> source = Ix.empty().window(2, 3); @@ -175,18 +175,18 @@ public void emptySkip() { Assert.assertEquals(0, list.size()); } - + @Test public void skipInnerMovesParent() { Ix> source = Ix.range(1, 5).window(2, 3); Iterator> it0 = source.iterator(); - + Ix inner = it0.next(); - + Iterator it1 = inner.iterator(); - + try { inner.iterator(); Assert.fail("Should have thrown IllegalStateException"); @@ -196,23 +196,23 @@ public void skipInnerMovesParent() { Assert.assertEquals(1, it1.next().intValue()); Assert.assertEquals(2, it1.next().intValue()); Assert.assertFalse(it1.hasNext()); - + inner = it0.next(); it1 = inner.iterator(); - + Assert.assertEquals(4, it1.next().intValue()); Assert.assertEquals(5, it1.next().intValue()); Assert.assertFalse(it1.hasNext()); - + Assert.assertFalse(it0.hasNext()); } - + @Test public void normalOverlap() { Ix> source = Ix.range(1, 5).window(2, 1); List> list = source.collectToList().first(); - + Assert.assertEquals(5, list.size()); IxTestHelper.assertValues(list.get(0), 1, 2); IxTestHelper.assertValues(list.get(1), 2, 3); @@ -220,13 +220,13 @@ public void normalOverlap() { IxTestHelper.assertValues(list.get(3), 4, 5); IxTestHelper.assertValues(list.get(4), 5); } - + @Test public void normalOverlap2() { Ix> source = Ix.range(1, 5).window(3, 1); List> list = source.collectToList().first(); - + Assert.assertEquals(5, list.size()); IxTestHelper.assertValues(list.get(0), 1, 2, 3); IxTestHelper.assertValues(list.get(1), 2, 3, 4); @@ -234,13 +234,13 @@ public void normalOverlap2() { IxTestHelper.assertValues(list.get(3), 4, 5); IxTestHelper.assertValues(list.get(4), 5); } - + @Test public void normalOverlap3() { Ix> source = Ix.range(1, 5).window(3, 2); List> list = source.collectToList().first(); - + Assert.assertEquals(3, list.size()); IxTestHelper.assertValues(list.get(0), 1, 2, 3); IxTestHelper.assertValues(list.get(1), 3, 4, 5); @@ -252,13 +252,13 @@ public void nullExact() { Ix> source = Ix.fromArray(null, null, null, null, null).window(2); List> list = source.collectToList().first(); - + Assert.assertEquals(3, list.size()); IxTestHelper.assertValues(list.get(0), null, null); IxTestHelper.assertValues(list.get(1), null, null); IxTestHelper.assertValues(list.get(2), (Integer)null); } - + @Test public void nullExact2() { Ix> source = Ix.fromArray(null, null, null, null, null).window(6); @@ -278,18 +278,18 @@ public void nullSkip() { Ix> source = Ix.fromArray(null, null, null, null, null).window(2, 3); List> list = source.collectToList().first(); - + Assert.assertEquals(2, list.size()); IxTestHelper.assertValues(list.get(0), null, null); IxTestHelper.assertValues(list.get(1), null, null); } - + @Test public void nullOverlap() { Ix> source = Ix.fromArray(null, null, null, null, null).window(2, 1); List> list = source.collectToList().first(); - + Assert.assertEquals(5, list.size()); IxTestHelper.assertValues(list.get(0), null, null); IxTestHelper.assertValues(list.get(1), null, null); @@ -297,18 +297,18 @@ public void nullOverlap() { IxTestHelper.assertValues(list.get(3), null, null); IxTestHelper.assertValues(list.get(4), (Integer)null); } - + @Test public void overlapInnerMovesParent() { Ix> source = Ix.range(1, 5).window(2, 1); Iterator> it0 = source.iterator(); - + Ix inner = it0.next(); - + Iterator it1 = inner.iterator(); - + try { inner.iterator(); Assert.fail("Should have thrown IllegalStateException"); @@ -318,28 +318,28 @@ public void overlapInnerMovesParent() { Assert.assertEquals(1, it1.next().intValue()); Assert.assertEquals(2, it1.next().intValue()); Assert.assertFalse(it1.hasNext()); - + inner = it0.next(); it1 = inner.iterator(); - + Assert.assertEquals(2, it1.next().intValue()); Assert.assertEquals(3, it1.next().intValue()); Assert.assertFalse(it1.hasNext()); - + Assert.assertTrue(it0.hasNext()); } - + @Test public void overlapInnerMovesParent2() { Ix> source = Ix.range(1, 5).window(3, 2); Iterator> it0 = source.iterator(); - + Ix inner = it0.next(); - + Iterator it1 = inner.iterator(); - + try { inner.iterator(); Assert.fail("Should have thrown IllegalStateException"); @@ -350,10 +350,10 @@ public void overlapInnerMovesParent2() { Assert.assertEquals(2, it1.next().intValue()); Assert.assertEquals(3, it1.next().intValue()); Assert.assertFalse(it1.hasNext()); - + inner = it0.next(); it1 = inner.iterator(); - + Assert.assertEquals(3, it1.next().intValue()); Assert.assertEquals(4, it1.next().intValue()); Assert.assertEquals(5, it1.next().intValue()); @@ -368,10 +368,10 @@ public void overlapParentMoved() { Ix> source = Ix.range(1, 5).window(4, 3); Iterator> it0 = source.iterator(); - + Ix inner1 = it0.next(); Ix inner2 = it0.next(); - + Assert.assertFalse(it0.hasNext()); IxTestHelper.assertValues(inner1, 1, 2, 3, 4); diff --git a/src/test/java/ix/Zip2Test.java b/src/test/java/ix/Zip2Test.java index 1c2f629..c6c5dd6 100644 --- a/src/test/java/ix/Zip2Test.java +++ b/src/test/java/ix/Zip2Test.java @@ -18,58 +18,56 @@ import org.junit.Test; -import rx.functions.*; - public class Zip2Test { - Func2 sum = new Func2() { + IxFunction2 sum = new IxFunction2() { @Override - public Integer call(Integer a, Integer b) { + public Integer apply(Integer a, Integer b) { return a + b; } }; - + @Test public void normal() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 2), Ix.range(10, 2), sum); - + IxTestHelper.assertValues(source, 11, 13); } - + @Test public void firstShorter() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 1), Ix.range(10, 2), sum); - + IxTestHelper.assertValues(source, 11); } @Test public void secondShorter() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 3), Ix.range(10, 2), sum); - + IxTestHelper.assertValues(source, 11, 13); } @Test public void bothEmpty() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.empty(), Ix.empty(), sum); - + IxTestHelper.assertValues(source); } @Test public void normalWith() { - + Ix source = Ix.range(1, 2).zipWith(Ix.range(10, 2), sum); - + IxTestHelper.assertValues(source, 11, 13); } diff --git a/src/test/java/ix/Zip3Test.java b/src/test/java/ix/Zip3Test.java index 96e4fca..32172f7 100644 --- a/src/test/java/ix/Zip3Test.java +++ b/src/test/java/ix/Zip3Test.java @@ -18,59 +18,57 @@ import org.junit.Test; -import rx.functions.*; - public class Zip3Test { - Func3 sum = new Func3() { + IxFunction3 sum = new IxFunction3() { @Override - public Integer call(Integer a, Integer b, Integer c) { + public Integer apply(Integer a, Integer b, Integer c) { return a + b + c; } }; - + @Test public void normal() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 2), Ix.range(10, 2), Ix.range(100, 2), sum); - + IxTestHelper.assertValues(source, 111, 114); } - + @Test public void firstShorter() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 1), Ix.range(10, 2), Ix.range(100, 2), sum); - + IxTestHelper.assertValues(source, 111); } @Test public void secondShorter() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 3), Ix.range(10, 2), Ix.range(100, 2), sum); - + IxTestHelper.assertValues(source, 111, 114); } @Test public void thirdShorter() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 3), Ix.range(10, 3), Ix.range(100, 2), sum); - + IxTestHelper.assertValues(source, 111, 114); } @Test public void allEmpty() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.empty(), Ix.empty(), Ix.empty(), sum); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/Zip4Test.java b/src/test/java/ix/Zip4Test.java index 460fc8e..e859894 100644 --- a/src/test/java/ix/Zip4Test.java +++ b/src/test/java/ix/Zip4Test.java @@ -18,68 +18,66 @@ import org.junit.Test; -import rx.functions.*; - public class Zip4Test { - Func4 sum = new Func4() { + IxFunction4 sum = new IxFunction4() { @Override - public Integer call(Integer a, Integer b, Integer c, Integer d) { + public Integer apply(Integer a, Integer b, Integer c, Integer d) { return a + b + c + d; } }; - + @Test public void normal() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 2), Ix.range(10, 2), Ix.range(100, 2), Ix.range(1000, 2), sum); - + IxTestHelper.assertValues(source, 1111, 1115); } - + @Test public void firstShorter() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 1), Ix.range(10, 2), Ix.range(100, 2), Ix.range(1000, 2), sum); - + IxTestHelper.assertValues(source, 1111); } @Test public void secondShorter() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 3), Ix.range(10, 2), Ix.range(100, 3), Ix.range(1000, 3), sum); - + IxTestHelper.assertValues(source, 1111, 1115); } @Test public void thirdShorter() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 3), Ix.range(10, 3), Ix.range(100, 2), Ix.range(1000, 3), sum); - + IxTestHelper.assertValues(source, 1111, 1115); } @Test public void fourthShorter() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.range(1, 3), Ix.range(10, 3), Ix.range(100, 3), Ix.range(1000, 2), sum); - + IxTestHelper.assertValues(source, 1111, 1115); } @Test public void allEmpty() { - - Ix source = Ix.zip( + + Ix source = Ix.zip( Ix.empty(), Ix.empty(), Ix.empty(), Ix.empty(), sum); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/ZipArrayTest.java b/src/test/java/ix/ZipArrayTest.java index f517c10..6b7d6fa 100644 --- a/src/test/java/ix/ZipArrayTest.java +++ b/src/test/java/ix/ZipArrayTest.java @@ -18,13 +18,11 @@ import org.junit.Test; -import rx.functions.FuncN; - public class ZipArrayTest { - FuncN zipper = new FuncN() { + IxFunction zipper = new IxFunction() { @Override - public Integer call(Object... a) { + public Integer apply(Object[] a) { return (Integer)a[0] + (Integer)a[1]; } }; @@ -32,44 +30,44 @@ public Integer call(Object... a) { @SuppressWarnings("unchecked") @Test public void normal() { - - Ix source = Ix.zip(new Iterable[] { - Ix.range(1, 2), Ix.range(10, 2) }, + + Ix source = Ix.zip(new Iterable[] { + Ix.range(1, 2), Ix.range(10, 2) }, zipper); - + IxTestHelper.assertValues(source, 11, 13); } - + @SuppressWarnings("unchecked") @Test public void firstShorter() { - - Ix source = Ix.zip(new Iterable[] { - Ix.range(1, 1), Ix.range(10, 2) }, + + Ix source = Ix.zip(new Iterable[] { + Ix.range(1, 1), Ix.range(10, 2) }, zipper); - + IxTestHelper.assertValues(source, 11); } @SuppressWarnings("unchecked") @Test public void secondShorter() { - - Ix source = Ix.zip(new Iterable[] { - Ix.range(1, 3), Ix.range(10, 2) }, + + Ix source = Ix.zip(new Iterable[] { + Ix.range(1, 3), Ix.range(10, 2) }, zipper); - + IxTestHelper.assertValues(source, 11, 13); } @SuppressWarnings("unchecked") @Test public void bothEmpty() { - - Ix source = Ix.zip(new Iterable[] { - Ix.empty(), Ix.empty() }, + + Ix source = Ix.zip(new Iterable[] { + Ix.empty(), Ix.empty() }, zipper); - + IxTestHelper.assertValues(source); } diff --git a/src/test/java/ix/ZipIterableTest.java b/src/test/java/ix/ZipIterableTest.java index 7d653d6..6220a93 100644 --- a/src/test/java/ix/ZipIterableTest.java +++ b/src/test/java/ix/ZipIterableTest.java @@ -20,13 +20,11 @@ import org.junit.Test; -import rx.functions.FuncN; - public class ZipIterableTest { - FuncN zipper = new FuncN() { + IxFunction zipper = new IxFunction() { @Override - public Integer call(Object... a) { + public Integer apply(Object[] a) { int s = 0; for (Object o : a) { s += (Integer)o; @@ -38,61 +36,61 @@ public Integer call(Object... a) { @SuppressWarnings("unchecked") @Test public void normal() { - - Ix source = Ix.zip(Arrays.asList( - Ix.range(1, 2), Ix.range(10, 2)), + + Ix source = Ix.zip(Arrays.asList( + Ix.range(1, 2), Ix.range(10, 2)), zipper); - + IxTestHelper.assertValues(source, 11, 13); } - + @SuppressWarnings("unchecked") @Test public void normalMany() { - - Ix source = Ix.zip(Arrays.asList( + + Ix source = Ix.zip(Arrays.asList( Ix.range(1, 2), Ix.range(1, 2), Ix.range(1, 2), Ix.range(1, 2), Ix.range(1, 2), Ix.range(1, 2), Ix.range(1, 2), Ix.range(1, 2), Ix.range(1, 2), Ix.range(1, 2), Ix.range(1, 2), Ix.range(1, 2) - ), + ), zipper); - + IxTestHelper.assertValues(source, 12, 24); } - + @SuppressWarnings("unchecked") @Test public void firstShorter() { - - Ix source = Ix.zip(Arrays.asList( - Ix.range(1, 1), Ix.range(10, 2) ), + + Ix source = Ix.zip(Arrays.asList( + Ix.range(1, 1), Ix.range(10, 2) ), zipper); - + IxTestHelper.assertValues(source, 11); } @SuppressWarnings("unchecked") @Test public void secondShorter() { - - Ix source = Ix.zip(Arrays.asList( - Ix.range(1, 3), Ix.range(10, 2) ), + + Ix source = Ix.zip(Arrays.asList( + Ix.range(1, 3), Ix.range(10, 2) ), zipper); - + IxTestHelper.assertValues(source, 11, 13); } @SuppressWarnings("unchecked") @Test public void bothEmpty() { - - Ix source = Ix.zip(Arrays.asList( - Ix.empty(), Ix.empty() ), + + Ix source = Ix.zip(Arrays.asList( + Ix.empty(), Ix.empty() ), zipper); - + IxTestHelper.assertValues(source); }