├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main └── java │ └── rx │ ├── joins │ ├── ActivePlan0.java │ ├── ActivePlan1.java │ ├── ActivePlan2.java │ ├── ActivePlan3.java │ ├── ActivePlan4.java │ ├── ActivePlan5.java │ ├── ActivePlan6.java │ ├── ActivePlan7.java │ ├── ActivePlan8.java │ ├── ActivePlan9.java │ ├── ActivePlanN.java │ ├── JoinObserver.java │ ├── JoinObserver1.java │ ├── Pattern.java │ ├── Pattern1.java │ ├── Pattern2.java │ ├── Pattern3.java │ ├── Pattern4.java │ ├── Pattern5.java │ ├── Pattern6.java │ ├── Pattern7.java │ ├── Pattern8.java │ ├── Pattern9.java │ ├── PatternN.java │ ├── Plan0.java │ ├── Plan1.java │ ├── Plan2.java │ ├── Plan3.java │ ├── Plan4.java │ ├── Plan5.java │ ├── Plan6.java │ ├── Plan7.java │ ├── Plan8.java │ ├── Plan9.java │ ├── PlanN.java │ └── operators │ │ └── OperatorJoinPatterns.java │ └── observables │ └── JoinObservable.java └── test └── java └── rx └── joins └── operators ├── OperatorJoinsTest.java └── TestException.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.com 4 | *.class 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | 10 | # Packages # 11 | ############ 12 | # it's better to unpack these files and commit the raw source 13 | # git has its own built in compression methods 14 | *.7z 15 | *.dmg 16 | *.gz 17 | *.iso 18 | *.jar 19 | *.rar 20 | *.tar 21 | *.zip 22 | 23 | # Logs and databases # 24 | ###################### 25 | *.log 26 | 27 | # OS generated files # 28 | ###################### 29 | .DS_Store* 30 | ehthumbs.db 31 | Icon? 32 | Thumbs.db 33 | 34 | # Editor Files # 35 | ################ 36 | *~ 37 | *.swp 38 | 39 | # Gradle Files # 40 | ################ 41 | .gradle 42 | .gradletasknamecache 43 | .m2 44 | 45 | # Build output directies 46 | target/ 47 | build/ 48 | 49 | # IntelliJ specific files/directories 50 | out 51 | .idea 52 | *.ipr 53 | *.iws 54 | *.iml 55 | atlassian-ide-plugin.xml 56 | 57 | # Eclipse specific files/directories 58 | .classpath 59 | .project 60 | .settings 61 | .metadata 62 | bin/ 63 | 64 | # NetBeans specific files/directories 65 | .nbattrs 66 | /.nb-gradle/profiles/private/ 67 | .nb-gradle-properties 68 | 69 | # Scala build 70 | *.cache 71 | /.nb-gradle/private/ 72 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk7 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to RxJava 2 | 3 | If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request (on a branch other than `master` or `gh-pages`). 4 | 5 | When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. 6 | 7 | ## License 8 | 9 | By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/ReactiveX/RxJava/blob/master/LICENSE 10 | 11 | All files are released with the Apache 2.0 license. 12 | 13 | If you are adding a new file it should have a header like this: 14 | 15 | ``` 16 | /** 17 | * Copyright 2014 Netflix, Inc. 18 | * 19 | * Licensed under the Apache License, Version 2.0 (the "License"); 20 | * you may not use this file except in compliance with the License. 21 | * You may obtain a copy of the License at 22 | * 23 | * http://www.apache.org/licenses/LICENSE-2.0 24 | * 25 | * Unless required by applicable law or agreed to in writing, software 26 | * distributed under the License is distributed on an "AS IS" BASIS, 27 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 | * See the License for the specific language governing permissions and 29 | * limitations under the License. 30 | */ 31 | ``` 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2012 Netflix, Inc. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RxJava Joins 2 | 3 | Joins operators for [RxJava](https://github.com/ReactiveX/RxJava). 4 | 5 | ## Master Build Status 6 | 7 | 8 | 9 | ## Communication 10 | 11 | - Google Group: [RxJava](http://groups.google.com/d/forum/rxjava) 12 | - Twitter: [@RxJava](http://twitter.com/RxJava) 13 | - [GitHub Issues](https://github.com/ReactiveX/RxJavaJoins/issues) 14 | 15 | 16 | ## Binaries 17 | 18 | Binaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cio.reactivex.rxjava-joins). 19 | 20 | Example for Maven: 21 | 22 | ```xml 23 | 24 | io.reactivex 25 | rxjava-joins 26 | x.y.z 27 | 28 | ``` 29 | for Ivy: 30 | 31 | ```xml 32 | 33 | ``` 34 | 35 | and for Gradle: 36 | ```groovy 37 | compile 'io.reactivex:rxjava-joins:0.22.0' 38 | ``` 39 | ## Build 40 | 41 | To build: 42 | 43 | ``` 44 | $ git clone git@github.com:ReactiveX/RxJavaJoins.git 45 | $ cd RxJavaJoins/ 46 | $ ./gradlew build 47 | ``` 48 | 49 | ## Bugs and Feedback 50 | 51 | For bugs, questions and discussions please use the [Github Issues](https://github.com/ReactiveX/RxJavaJoins/issues). 52 | 53 | 54 | ## LICENSE 55 | 56 | Licensed under the Apache License, Version 2.0 (the "License"); 57 | you may not use this file except in compliance with the License. 58 | You may obtain a copy of the License at 59 | 60 | 61 | 62 | Unless required by applicable law or agreed to in writing, software 63 | distributed under the License is distributed on an "AS IS" BASIS, 64 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 65 | See the License for the specific language governing permissions and 66 | limitations under the License. 67 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { jcenter() } 3 | dependencies { classpath 'com.netflix.nebula:gradle-rxjava-project-plugin:2.+' } 4 | } 5 | 6 | apply plugin: 'rxjava-project' 7 | apply plugin: 'java' 8 | 9 | dependencies { 10 | compile 'io.reactivex:rxjava:1.0.+' 11 | testCompile 'junit:junit-dep:4.10' 12 | testCompile 'org.mockito:mockito-core:1.8.5' 13 | } 14 | 15 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=1.0.0-RC1-SNAPSHOT 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReactiveX/RxJavaJoins/65b5c7fa03bd375c9e1f7906d7143068fde9b714/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Feb 05 12:05:54 CET 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name='rxjava-joins' 2 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlan0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | /** 22 | * Represents an activated plan. 23 | */ 24 | public abstract class ActivePlan0 { 25 | protected final Map joinObservers = new HashMap(); 26 | 27 | protected abstract void match(); 28 | 29 | protected void addJoinObserver(JoinObserver joinObserver) { 30 | joinObservers.put(joinObserver, joinObserver); 31 | } 32 | 33 | protected void dequeue() { 34 | for (JoinObserver jo : joinObservers.values()) { 35 | jo.dequeue(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlan1.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Notification; 19 | import rx.functions.Action0; 20 | import rx.functions.Action1; 21 | 22 | /** 23 | * Represents an active plan. 24 | */ 25 | public final class ActivePlan1 extends ActivePlan0 { 26 | private final Action1 onNext; 27 | private final Action0 onCompleted; 28 | private final JoinObserver1 jo1; 29 | 30 | ActivePlan1(JoinObserver1 jo1, Action1 onNext, Action0 onCompleted) { 31 | this.onNext = onNext; 32 | this.onCompleted = onCompleted; 33 | this.jo1 = jo1; 34 | addJoinObserver(jo1); 35 | } 36 | 37 | @Override 38 | protected void match() { 39 | if (!jo1.queue().isEmpty()) { 40 | Notification n1 = jo1.queue().peek(); 41 | if (n1.isOnCompleted()) { 42 | onCompleted.call(); 43 | } else { 44 | dequeue(); 45 | onNext.call(n1.getValue()); 46 | } 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlan2.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Notification; 19 | import rx.functions.Action0; 20 | import rx.functions.Action2; 21 | 22 | /** 23 | * Represents an active plan. 24 | */ 25 | public final class ActivePlan2 extends ActivePlan0 { 26 | private final Action2 onNext; 27 | private final Action0 onCompleted; 28 | private final JoinObserver1 jo1; 29 | private final JoinObserver1 jo2; 30 | 31 | ActivePlan2(JoinObserver1 jo1, JoinObserver1 jo2, Action2 onNext, Action0 onCompleted) { 32 | this.onNext = onNext; 33 | this.onCompleted = onCompleted; 34 | this.jo1 = jo1; 35 | this.jo2 = jo2; 36 | addJoinObserver(jo1); 37 | addJoinObserver(jo2); 38 | } 39 | 40 | @Override 41 | protected void match() { 42 | if (!jo1.queue().isEmpty() && !jo2.queue().isEmpty()) { 43 | Notification n1 = jo1.queue().peek(); 44 | Notification n2 = jo2.queue().peek(); 45 | 46 | if (n1.isOnCompleted() || n2.isOnCompleted()) { 47 | onCompleted.call(); 48 | } else { 49 | dequeue(); 50 | onNext.call(n1.getValue(), n2.getValue()); 51 | } 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlan3.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Notification; 19 | import rx.functions.Action0; 20 | import rx.functions.Action3; 21 | 22 | /** 23 | * Represents an active plan. 24 | */ 25 | public final class ActivePlan3 extends ActivePlan0 { 26 | private final Action3 onNext; 27 | private final Action0 onCompleted; 28 | private final JoinObserver1 first; 29 | private final JoinObserver1 second; 30 | private final JoinObserver1 third; 31 | 32 | ActivePlan3(JoinObserver1 first, 33 | JoinObserver1 second, 34 | JoinObserver1 third, 35 | Action3 onNext, 36 | Action0 onCompleted) { 37 | this.onNext = onNext; 38 | this.onCompleted = onCompleted; 39 | this.first = first; 40 | this.second = second; 41 | this.third = third; 42 | addJoinObserver(first); 43 | addJoinObserver(second); 44 | addJoinObserver(third); 45 | } 46 | 47 | @Override 48 | protected void match() { 49 | if (!first.queue().isEmpty() 50 | && !second.queue().isEmpty() 51 | && !third.queue().isEmpty()) { 52 | Notification n1 = first.queue().peek(); 53 | Notification n2 = second.queue().peek(); 54 | Notification n3 = third.queue().peek(); 55 | 56 | if (n1.isOnCompleted() || n2.isOnCompleted() || n3.isOnCompleted()) { 57 | onCompleted.call(); 58 | } else { 59 | dequeue(); 60 | onNext.call(n1.getValue(), n2.getValue(), n3.getValue()); 61 | } 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlan4.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Notification; 19 | import rx.functions.Action0; 20 | import rx.functions.Action4; 21 | 22 | /** 23 | * Represents an active plan. 24 | */ 25 | public final class ActivePlan4 extends ActivePlan0 { 26 | private final Action4 onNext; 27 | private final Action0 onCompleted; 28 | private final JoinObserver1 jo1; 29 | private final JoinObserver1 jo2; 30 | private final JoinObserver1 jo3; 31 | private final JoinObserver1 jo4; 32 | 33 | ActivePlan4( 34 | JoinObserver1 jo1, 35 | JoinObserver1 jo2, 36 | JoinObserver1 jo3, 37 | JoinObserver1 jo4, 38 | Action4 onNext, 39 | Action0 onCompleted) { 40 | this.onNext = onNext; 41 | this.onCompleted = onCompleted; 42 | this.jo1 = jo1; 43 | this.jo2 = jo2; 44 | this.jo3 = jo3; 45 | this.jo4 = jo4; 46 | addJoinObserver(jo1); 47 | addJoinObserver(jo2); 48 | addJoinObserver(jo3); 49 | addJoinObserver(jo4); 50 | } 51 | 52 | @Override 53 | protected void match() { 54 | if (!jo1.queue().isEmpty() 55 | && !jo2.queue().isEmpty() 56 | && !jo3.queue().isEmpty() 57 | && !jo4.queue().isEmpty()) { 58 | Notification n1 = jo1.queue().peek(); 59 | Notification n2 = jo2.queue().peek(); 60 | Notification n3 = jo3.queue().peek(); 61 | Notification n4 = jo4.queue().peek(); 62 | 63 | if (n1.isOnCompleted() 64 | || n2.isOnCompleted() 65 | || n3.isOnCompleted() 66 | || n4.isOnCompleted()) { 67 | onCompleted.call(); 68 | } else { 69 | dequeue(); 70 | onNext.call(n1.getValue(), n2.getValue(), n3.getValue(), n4.getValue()); 71 | } 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlan5.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Notification; 19 | import rx.functions.Action0; 20 | import rx.functions.Action5; 21 | 22 | /** 23 | * Represents an active plan. 24 | */ 25 | public final class ActivePlan5 extends ActivePlan0 { 26 | private final Action5 onNext; 27 | private final Action0 onCompleted; 28 | private final JoinObserver1 jo1; 29 | private final JoinObserver1 jo2; 30 | private final JoinObserver1 jo3; 31 | private final JoinObserver1 jo4; 32 | private final JoinObserver1 jo5; 33 | 34 | ActivePlan5( 35 | JoinObserver1 jo1, 36 | JoinObserver1 jo2, 37 | JoinObserver1 jo3, 38 | JoinObserver1 jo4, 39 | JoinObserver1 jo5, 40 | Action5 onNext, 41 | Action0 onCompleted) { 42 | this.onNext = onNext; 43 | this.onCompleted = onCompleted; 44 | this.jo1 = jo1; 45 | this.jo2 = jo2; 46 | this.jo3 = jo3; 47 | this.jo4 = jo4; 48 | this.jo5 = jo5; 49 | addJoinObserver(jo1); 50 | addJoinObserver(jo2); 51 | addJoinObserver(jo3); 52 | addJoinObserver(jo4); 53 | addJoinObserver(jo5); 54 | } 55 | 56 | @Override 57 | protected void match() { 58 | if (!jo1.queue().isEmpty() 59 | && !jo2.queue().isEmpty() 60 | && !jo3.queue().isEmpty() 61 | && !jo4.queue().isEmpty() 62 | && !jo5.queue().isEmpty() 63 | ) { 64 | Notification n1 = jo1.queue().peek(); 65 | Notification n2 = jo2.queue().peek(); 66 | Notification n3 = jo3.queue().peek(); 67 | Notification n4 = jo4.queue().peek(); 68 | Notification n5 = jo5.queue().peek(); 69 | 70 | if (n1.isOnCompleted() 71 | || n2.isOnCompleted() 72 | || n3.isOnCompleted() 73 | || n4.isOnCompleted() 74 | || n5.isOnCompleted() 75 | ) { 76 | onCompleted.call(); 77 | } else { 78 | dequeue(); 79 | onNext.call( 80 | n1.getValue(), 81 | n2.getValue(), 82 | n3.getValue(), 83 | n4.getValue(), 84 | n5.getValue() 85 | ); 86 | } 87 | } 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlan6.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Notification; 19 | import rx.functions.Action0; 20 | import rx.functions.Action6; 21 | 22 | /** 23 | * Represents an active plan. 24 | */ 25 | public final class ActivePlan6 extends ActivePlan0 { 26 | private final Action6 onNext; 27 | private final Action0 onCompleted; 28 | private final JoinObserver1 jo1; 29 | private final JoinObserver1 jo2; 30 | private final JoinObserver1 jo3; 31 | private final JoinObserver1 jo4; 32 | private final JoinObserver1 jo5; 33 | private final JoinObserver1 jo6; 34 | 35 | ActivePlan6( 36 | JoinObserver1 jo1, 37 | JoinObserver1 jo2, 38 | JoinObserver1 jo3, 39 | JoinObserver1 jo4, 40 | JoinObserver1 jo5, 41 | JoinObserver1 jo6, 42 | Action6 onNext, 43 | Action0 onCompleted) { 44 | this.onNext = onNext; 45 | this.onCompleted = onCompleted; 46 | this.jo1 = jo1; 47 | this.jo2 = jo2; 48 | this.jo3 = jo3; 49 | this.jo4 = jo4; 50 | this.jo5 = jo5; 51 | this.jo6 = jo6; 52 | addJoinObserver(jo1); 53 | addJoinObserver(jo2); 54 | addJoinObserver(jo3); 55 | addJoinObserver(jo4); 56 | addJoinObserver(jo5); 57 | addJoinObserver(jo6); 58 | } 59 | 60 | @Override 61 | protected void match() { 62 | if (!jo1.queue().isEmpty() 63 | && !jo2.queue().isEmpty() 64 | && !jo3.queue().isEmpty() 65 | && !jo4.queue().isEmpty() 66 | && !jo5.queue().isEmpty() 67 | && !jo6.queue().isEmpty() 68 | ) { 69 | Notification n1 = jo1.queue().peek(); 70 | Notification n2 = jo2.queue().peek(); 71 | Notification n3 = jo3.queue().peek(); 72 | Notification n4 = jo4.queue().peek(); 73 | Notification n5 = jo5.queue().peek(); 74 | Notification n6 = jo6.queue().peek(); 75 | 76 | if (n1.isOnCompleted() 77 | || n2.isOnCompleted() 78 | || n3.isOnCompleted() 79 | || n4.isOnCompleted() 80 | || n5.isOnCompleted() 81 | || n6.isOnCompleted() 82 | ) { 83 | onCompleted.call(); 84 | } else { 85 | dequeue(); 86 | onNext.call( 87 | n1.getValue(), 88 | n2.getValue(), 89 | n3.getValue(), 90 | n4.getValue(), 91 | n5.getValue(), 92 | n6.getValue() 93 | ); 94 | } 95 | } 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlan7.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Notification; 19 | import rx.functions.Action0; 20 | import rx.functions.Action7; 21 | 22 | /** 23 | * Represents an active plan. 24 | */ 25 | public final class ActivePlan7 extends ActivePlan0 { 26 | private final Action7 onNext; 27 | private final Action0 onCompleted; 28 | private final JoinObserver1 jo1; 29 | private final JoinObserver1 jo2; 30 | private final JoinObserver1 jo3; 31 | private final JoinObserver1 jo4; 32 | private final JoinObserver1 jo5; 33 | private final JoinObserver1 jo6; 34 | private final JoinObserver1 jo7; 35 | 36 | ActivePlan7( 37 | JoinObserver1 jo1, 38 | JoinObserver1 jo2, 39 | JoinObserver1 jo3, 40 | JoinObserver1 jo4, 41 | JoinObserver1 jo5, 42 | JoinObserver1 jo6, 43 | JoinObserver1 jo7, 44 | Action7 onNext, 45 | Action0 onCompleted) { 46 | this.onNext = onNext; 47 | this.onCompleted = onCompleted; 48 | this.jo1 = jo1; 49 | this.jo2 = jo2; 50 | this.jo3 = jo3; 51 | this.jo4 = jo4; 52 | this.jo5 = jo5; 53 | this.jo6 = jo6; 54 | this.jo7 = jo7; 55 | addJoinObserver(jo1); 56 | addJoinObserver(jo2); 57 | addJoinObserver(jo3); 58 | addJoinObserver(jo4); 59 | addJoinObserver(jo5); 60 | addJoinObserver(jo6); 61 | addJoinObserver(jo7); 62 | } 63 | 64 | @Override 65 | protected void match() { 66 | if (!jo1.queue().isEmpty() 67 | && !jo2.queue().isEmpty() 68 | && !jo3.queue().isEmpty() 69 | && !jo4.queue().isEmpty() 70 | && !jo5.queue().isEmpty() 71 | && !jo6.queue().isEmpty() 72 | && !jo7.queue().isEmpty() 73 | ) { 74 | Notification n1 = jo1.queue().peek(); 75 | Notification n2 = jo2.queue().peek(); 76 | Notification n3 = jo3.queue().peek(); 77 | Notification n4 = jo4.queue().peek(); 78 | Notification n5 = jo5.queue().peek(); 79 | Notification n6 = jo6.queue().peek(); 80 | Notification n7 = jo7.queue().peek(); 81 | 82 | if (n1.isOnCompleted() 83 | || n2.isOnCompleted() 84 | || n3.isOnCompleted() 85 | || n4.isOnCompleted() 86 | || n5.isOnCompleted() 87 | || n6.isOnCompleted() 88 | || n7.isOnCompleted() 89 | ) { 90 | onCompleted.call(); 91 | } else { 92 | dequeue(); 93 | onNext.call( 94 | n1.getValue(), 95 | n2.getValue(), 96 | n3.getValue(), 97 | n4.getValue(), 98 | n5.getValue(), 99 | n6.getValue(), 100 | n7.getValue() 101 | ); 102 | } 103 | } 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlan8.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Notification; 19 | import rx.functions.Action0; 20 | import rx.functions.Action8; 21 | 22 | /** 23 | * Represents an active plan. 24 | */ 25 | public final class ActivePlan8 extends ActivePlan0 { 26 | private final Action8 onNext; 27 | private final Action0 onCompleted; 28 | private final JoinObserver1 jo1; 29 | private final JoinObserver1 jo2; 30 | private final JoinObserver1 jo3; 31 | private final JoinObserver1 jo4; 32 | private final JoinObserver1 jo5; 33 | private final JoinObserver1 jo6; 34 | private final JoinObserver1 jo7; 35 | private final JoinObserver1 jo8; 36 | 37 | ActivePlan8( 38 | JoinObserver1 jo1, 39 | JoinObserver1 jo2, 40 | JoinObserver1 jo3, 41 | JoinObserver1 jo4, 42 | JoinObserver1 jo5, 43 | JoinObserver1 jo6, 44 | JoinObserver1 jo7, 45 | JoinObserver1 jo8, 46 | Action8 onNext, 47 | Action0 onCompleted) { 48 | this.onNext = onNext; 49 | this.onCompleted = onCompleted; 50 | this.jo1 = jo1; 51 | this.jo2 = jo2; 52 | this.jo3 = jo3; 53 | this.jo4 = jo4; 54 | this.jo5 = jo5; 55 | this.jo6 = jo6; 56 | this.jo7 = jo7; 57 | this.jo8 = jo8; 58 | addJoinObserver(jo1); 59 | addJoinObserver(jo2); 60 | addJoinObserver(jo3); 61 | addJoinObserver(jo4); 62 | addJoinObserver(jo5); 63 | addJoinObserver(jo6); 64 | addJoinObserver(jo7); 65 | addJoinObserver(jo8); 66 | } 67 | 68 | @Override 69 | protected void match() { 70 | if (!jo1.queue().isEmpty() 71 | && !jo2.queue().isEmpty() 72 | && !jo3.queue().isEmpty() 73 | && !jo4.queue().isEmpty() 74 | && !jo5.queue().isEmpty() 75 | && !jo6.queue().isEmpty() 76 | && !jo7.queue().isEmpty() 77 | && !jo8.queue().isEmpty() 78 | ) { 79 | Notification n1 = jo1.queue().peek(); 80 | Notification n2 = jo2.queue().peek(); 81 | Notification n3 = jo3.queue().peek(); 82 | Notification n4 = jo4.queue().peek(); 83 | Notification n5 = jo5.queue().peek(); 84 | Notification n6 = jo6.queue().peek(); 85 | Notification n7 = jo7.queue().peek(); 86 | Notification n8 = jo8.queue().peek(); 87 | 88 | if (n1.isOnCompleted() 89 | || n2.isOnCompleted() 90 | || n3.isOnCompleted() 91 | || n4.isOnCompleted() 92 | || n5.isOnCompleted() 93 | || n6.isOnCompleted() 94 | || n7.isOnCompleted() 95 | || n8.isOnCompleted() 96 | ) { 97 | onCompleted.call(); 98 | } else { 99 | dequeue(); 100 | onNext.call( 101 | n1.getValue(), 102 | n2.getValue(), 103 | n3.getValue(), 104 | n4.getValue(), 105 | n5.getValue(), 106 | n6.getValue(), 107 | n7.getValue(), 108 | n8.getValue() 109 | ); 110 | } 111 | } 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlan9.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Notification; 19 | import rx.functions.Action0; 20 | import rx.functions.Action9; 21 | 22 | /** 23 | * Represents an active plan. 24 | */ 25 | public final class ActivePlan9 extends ActivePlan0 { 26 | private final Action9 onNext; 27 | private final Action0 onCompleted; 28 | private final JoinObserver1 jo1; 29 | private final JoinObserver1 jo2; 30 | private final JoinObserver1 jo3; 31 | private final JoinObserver1 jo4; 32 | private final JoinObserver1 jo5; 33 | private final JoinObserver1 jo6; 34 | private final JoinObserver1 jo7; 35 | private final JoinObserver1 jo8; 36 | private final JoinObserver1 jo9; 37 | 38 | ActivePlan9( 39 | JoinObserver1 jo1, 40 | JoinObserver1 jo2, 41 | JoinObserver1 jo3, 42 | JoinObserver1 jo4, 43 | JoinObserver1 jo5, 44 | JoinObserver1 jo6, 45 | JoinObserver1 jo7, 46 | JoinObserver1 jo8, 47 | JoinObserver1 jo9, 48 | Action9 onNext, 49 | Action0 onCompleted) { 50 | this.onNext = onNext; 51 | this.onCompleted = onCompleted; 52 | this.jo1 = jo1; 53 | this.jo2 = jo2; 54 | this.jo3 = jo3; 55 | this.jo4 = jo4; 56 | this.jo5 = jo5; 57 | this.jo6 = jo6; 58 | this.jo7 = jo7; 59 | this.jo8 = jo8; 60 | this.jo9 = jo9; 61 | addJoinObserver(jo1); 62 | addJoinObserver(jo2); 63 | addJoinObserver(jo3); 64 | addJoinObserver(jo4); 65 | addJoinObserver(jo5); 66 | addJoinObserver(jo6); 67 | addJoinObserver(jo7); 68 | addJoinObserver(jo8); 69 | addJoinObserver(jo9); 70 | } 71 | 72 | @Override 73 | protected void match() { 74 | if (!jo1.queue().isEmpty() 75 | && !jo2.queue().isEmpty() 76 | && !jo3.queue().isEmpty() 77 | && !jo4.queue().isEmpty() 78 | && !jo5.queue().isEmpty() 79 | && !jo6.queue().isEmpty() 80 | && !jo7.queue().isEmpty() 81 | && !jo8.queue().isEmpty() 82 | && !jo9.queue().isEmpty() 83 | ) { 84 | Notification n1 = jo1.queue().peek(); 85 | Notification n2 = jo2.queue().peek(); 86 | Notification n3 = jo3.queue().peek(); 87 | Notification n4 = jo4.queue().peek(); 88 | Notification n5 = jo5.queue().peek(); 89 | Notification n6 = jo6.queue().peek(); 90 | Notification n7 = jo7.queue().peek(); 91 | Notification n8 = jo8.queue().peek(); 92 | Notification n9 = jo9.queue().peek(); 93 | 94 | if (n1.isOnCompleted() 95 | || n2.isOnCompleted() 96 | || n3.isOnCompleted() 97 | || n4.isOnCompleted() 98 | || n5.isOnCompleted() 99 | || n6.isOnCompleted() 100 | || n7.isOnCompleted() 101 | || n8.isOnCompleted() 102 | || n9.isOnCompleted() 103 | ) { 104 | onCompleted.call(); 105 | } else { 106 | dequeue(); 107 | onNext.call( 108 | n1.getValue(), 109 | n2.getValue(), 110 | n3.getValue(), 111 | n4.getValue(), 112 | n5.getValue(), 113 | n6.getValue(), 114 | n7.getValue(), 115 | n8.getValue(), 116 | n9.getValue() 117 | ); 118 | } 119 | } 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/ActivePlanN.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import rx.Notification; 22 | import rx.functions.Action0; 23 | import rx.functions.ActionN; 24 | 25 | /** 26 | * Represents an active plan. 27 | */ 28 | public final class ActivePlanN extends ActivePlan0 { 29 | private final ActionN onNext; 30 | private final Action0 onCompleted; 31 | private final List> observers; 32 | 33 | ActivePlanN(List> observers, 34 | ActionN onNext, 35 | Action0 onCompleted) { 36 | this.onNext = onNext; 37 | this.onCompleted = onCompleted; 38 | this.observers = new ArrayList>(observers); 39 | for (JoinObserver1 jo : this.observers) { 40 | addJoinObserver(jo); 41 | } 42 | } 43 | 44 | @Override 45 | protected void match() { 46 | Object[] notifications = new Object[this.observers.size()]; 47 | int j = 0; 48 | int completedCount = 0; 49 | for (JoinObserver1 jo : this.observers) { 50 | if (jo.queue().isEmpty()) { 51 | return; 52 | } 53 | Notification n = jo.queue().peek(); 54 | if (n.isOnCompleted()) { 55 | completedCount++; 56 | } 57 | notifications[j] = n.getValue(); 58 | j++; 59 | } 60 | if (completedCount == j) { 61 | onCompleted.call(); 62 | } else { 63 | dequeue(); 64 | onNext.call(notifications); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/JoinObserver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Subscription; 19 | 20 | /** 21 | * Base interface to manage joined observations. 22 | */ 23 | public interface JoinObserver extends Subscription { 24 | void subscribe(Object gate); 25 | 26 | void dequeue(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/JoinObserver1.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.ArrayList; 19 | import java.util.LinkedList; 20 | import java.util.List; 21 | import java.util.Queue; 22 | import java.util.concurrent.atomic.AtomicBoolean; 23 | 24 | import rx.Notification; 25 | import rx.Observable; 26 | import rx.Subscriber; 27 | import rx.functions.Action1; 28 | import rx.observers.SafeSubscriber; 29 | 30 | /** 31 | * Default implementation of a join observer. 32 | */ 33 | final class JoinObserver1 extends Subscriber> implements JoinObserver { 34 | private Object gate; 35 | private final Observable source; 36 | private final Action1 onError; 37 | private final List activePlans; 38 | private final Queue> queue; 39 | private final AtomicBoolean subscribed = new AtomicBoolean(false); 40 | private final SafeSubscriber> safeObserver; 41 | 42 | JoinObserver1(Observable source, Action1 onError) { 43 | this.source = source; 44 | this.onError = onError; 45 | queue = new LinkedList>(); 46 | activePlans = new ArrayList(); 47 | safeObserver = new SafeSubscriber>(new InnerObserver()); 48 | // add this subscription so it gets unsubscribed when the parent does 49 | add(safeObserver); 50 | } 51 | 52 | public Queue> queue() { 53 | return queue; 54 | } 55 | 56 | public void addActivePlan(ActivePlan0 activePlan) { 57 | activePlans.add(activePlan); 58 | } 59 | 60 | @Override 61 | public void subscribe(Object gate) { 62 | if (subscribed.compareAndSet(false, true)) { 63 | this.gate = gate; 64 | source.materialize().unsafeSubscribe(this); 65 | } else { 66 | throw new IllegalStateException("Can only be subscribed to once."); 67 | } 68 | } 69 | 70 | @Override 71 | public void dequeue() { 72 | queue.remove(); 73 | } 74 | 75 | 76 | @Override 77 | public void onNext(Notification args) { 78 | safeObserver.onNext(args); 79 | } 80 | 81 | @Override 82 | public void onError(Throwable e) { 83 | safeObserver.onError(e); 84 | } 85 | 86 | @Override 87 | public void onCompleted() { 88 | safeObserver.onCompleted(); 89 | } 90 | 91 | void removeActivePlan(ActivePlan0 activePlan) { 92 | activePlans.remove(activePlan); 93 | if (activePlans.isEmpty()) { 94 | unsubscribe(); 95 | } 96 | } 97 | 98 | 99 | private final class InnerObserver extends Subscriber> { 100 | 101 | @Override 102 | public void onNext(Notification args) { 103 | synchronized (gate) { 104 | if (!isUnsubscribed()) { 105 | if (args.isOnError()) { 106 | onError.call(args.getThrowable()); 107 | return; 108 | } 109 | queue.add(args); 110 | 111 | // remark: activePlans might change while iterating 112 | for (ActivePlan0 a : new ArrayList(activePlans)) { 113 | a.match(); 114 | } 115 | } 116 | } 117 | } 118 | 119 | @Override 120 | public void onError(Throwable e) { 121 | // not expected 122 | } 123 | 124 | @Override 125 | public void onCompleted() { 126 | // not expected or ignored 127 | } 128 | } 129 | 130 | } -------------------------------------------------------------------------------- /src/main/java/rx/joins/Pattern.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package rx.joins; 18 | 19 | /** 20 | * Base interface for join patterns. 21 | * 22 | * @see MSDN: Pattern 23 | */ 24 | public interface Pattern { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Pattern1.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Observable; 19 | import rx.functions.Func1; 20 | 21 | /** 22 | * Represents a join pattern over one observable sequence. 23 | */ 24 | public final class Pattern1 implements Pattern { 25 | private final Observable o1; 26 | 27 | public Pattern1(Observable o1) { 28 | this.o1 = o1; 29 | } 30 | 31 | Observable o1() { 32 | return o1; 33 | } 34 | 35 | /** 36 | * Matches when all observable sequences have an available 37 | * element and projects the elements by invoking the selector function. 38 | * 39 | * @param selector 40 | * the function that will be invoked for elements in the source sequences. 41 | * @return the plan for the matching 42 | * @throws NullPointerException 43 | * if selector is null 44 | */ 45 | public Plan0 then(Func1 selector) { 46 | if (selector == null) { 47 | throw new NullPointerException(); 48 | } 49 | return new Plan1(this, selector); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Pattern2.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Observable; 19 | import rx.functions.Func2; 20 | 21 | /** 22 | * Represents a join pattern over observable sequences. 23 | */ 24 | public final class Pattern2 implements Pattern { 25 | private final Observable o1; 26 | private final Observable o2; 27 | 28 | public Pattern2(Observable o1, Observable o2) { 29 | this.o1 = o1; 30 | this.o2 = o2; 31 | } 32 | 33 | Observable o1() { 34 | return o1; 35 | } 36 | 37 | Observable o2() { 38 | return o2; 39 | } 40 | 41 | /** 42 | * Creates a pattern that matches when all three observable sequences have an available element. 43 | * 44 | * @param other 45 | * Observable sequence to match with the two previous sequences. 46 | * @return Pattern object that matches when all observable sequences have an available element. 47 | */ 48 | public Pattern3 and(Observable other) { 49 | if (other == null) { 50 | throw new NullPointerException(); 51 | } 52 | return new Pattern3(o1, o2, other); 53 | } 54 | 55 | /** 56 | * Matches when all observable sequences have an available 57 | * element and projects the elements by invoking the selector function. 58 | * 59 | * @param selector 60 | * the function that will be invoked for elements in the source sequences. 61 | * @return the plan for the matching 62 | * @throws NullPointerException 63 | * if selector is null 64 | */ 65 | public Plan0 then(Func2 selector) { 66 | if (selector == null) { 67 | throw new NullPointerException(); 68 | } 69 | return new Plan2(this, selector); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Pattern3.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Observable; 19 | import rx.functions.Func3; 20 | 21 | /** 22 | * Represents a join pattern over observable sequences. 23 | */ 24 | public final class Pattern3 implements Pattern { 25 | private final Observable o1; 26 | private final Observable o2; 27 | private final Observable o3; 28 | 29 | public Pattern3(Observable o1, Observable o2, 30 | Observable o3) { 31 | this.o1 = o1; 32 | this.o2 = o2; 33 | this.o3 = o3; 34 | } 35 | 36 | Observable o1() { 37 | return o1; 38 | } 39 | 40 | Observable o2() { 41 | return o2; 42 | } 43 | 44 | Observable o3() { 45 | return o3; 46 | } 47 | 48 | /** 49 | * Creates a pattern that matches when all three observable sequences have an available element. 50 | * 51 | * @param other 52 | * Observable sequence to match with the two previous sequences. 53 | * @return Pattern object that matches when all observable sequences have an available element. 54 | */ 55 | public Pattern4 and(Observable other) { 56 | if (other == null) { 57 | throw new NullPointerException(); 58 | } 59 | return new Pattern4(o1, o2, o3, other); 60 | } 61 | 62 | /** 63 | * Matches when all observable sequences have an available 64 | * element and projects the elements by invoking the selector function. 65 | * 66 | * @param selector 67 | * the function that will be invoked for elements in the source sequences. 68 | * @return the plan for the matching 69 | * @throws NullPointerException 70 | * if selector is null 71 | */ 72 | public Plan0 then(Func3 selector) { 73 | if (selector == null) { 74 | throw new NullPointerException(); 75 | } 76 | return new Plan3(this, selector); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Pattern4.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Observable; 19 | import rx.functions.Func4; 20 | 21 | /** 22 | * Represents a join pattern over observable sequences. 23 | */ 24 | public final class Pattern4 implements Pattern { 25 | private final Observable o1; 26 | private final Observable o2; 27 | private final Observable o3; 28 | private final Observable o4; 29 | 30 | public Pattern4( 31 | Observable o1, 32 | Observable o2, 33 | Observable o3, 34 | Observable o4 35 | ) { 36 | this.o1 = o1; 37 | this.o2 = o2; 38 | this.o3 = o3; 39 | this.o4 = o4; 40 | } 41 | 42 | Observable o1() { 43 | return o1; 44 | } 45 | 46 | Observable o2() { 47 | return o2; 48 | } 49 | 50 | Observable o3() { 51 | return o3; 52 | } 53 | 54 | Observable o4() { 55 | return o4; 56 | } 57 | 58 | /** 59 | * Creates a pattern that matches when all four observable sequences have an available element. 60 | * 61 | * @param other 62 | * Observable sequence to match with the three previous sequences. 63 | * @return Pattern object that matches when all observable sequences have an available element. 64 | */ 65 | public Pattern5 and(Observable other) { 66 | if (other == null) { 67 | throw new NullPointerException(); 68 | } 69 | return new Pattern5(o1, o2, o3, o4, other); 70 | } 71 | /** 72 | * Matches when all observable sequences have an available 73 | * element and projects the elements by invoking the selector function. 74 | * 75 | * @param selector 76 | * the function that will be invoked for elements in the source sequences. 77 | * @return the plan for the matching 78 | * @throws NullPointerException 79 | * if selector is null 80 | */ 81 | public Plan0 then(Func4 selector) { 82 | if (selector == null) { 83 | throw new NullPointerException(); 84 | } 85 | return new Plan4(this, selector); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Pattern5.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Observable; 19 | import rx.functions.Func5; 20 | 21 | /** 22 | * Represents a join pattern over observable sequences. 23 | */ 24 | public final class Pattern5 implements Pattern { 25 | private final Observable o1; 26 | private final Observable o2; 27 | private final Observable o3; 28 | private final Observable o4; 29 | private final Observable o5; 30 | 31 | public Pattern5( 32 | Observable o1, 33 | Observable o2, 34 | Observable o3, 35 | Observable o4, 36 | Observable o5 37 | ) { 38 | this.o1 = o1; 39 | this.o2 = o2; 40 | this.o3 = o3; 41 | this.o4 = o4; 42 | this.o5 = o5; 43 | } 44 | 45 | Observable o1() { 46 | return o1; 47 | } 48 | 49 | Observable o2() { 50 | return o2; 51 | } 52 | 53 | Observable o3() { 54 | return o3; 55 | } 56 | 57 | Observable o4() { 58 | return o4; 59 | } 60 | 61 | Observable o5() { 62 | return o5; 63 | } 64 | 65 | /** 66 | * Creates a pattern that matches when all five observable sequences have an available element. 67 | * 68 | * @param other 69 | * Observable sequence to match with the four previous sequences. 70 | * @return Pattern object that matches when all observable sequences have an available element. 71 | */ 72 | public Pattern6 and(Observable other) { 73 | if (other == null) { 74 | throw new NullPointerException(); 75 | } 76 | return new Pattern6(o1, o2, o3, o4, o5, other); 77 | } 78 | /** 79 | * Matches when all observable sequences have an available 80 | * element and projects the elements by invoking the selector function. 81 | * 82 | * @param selector 83 | * the function that will be invoked for elements in the source sequences. 84 | * @return the plan for the matching 85 | * @throws NullPointerException 86 | * if selector is null 87 | */ 88 | public Plan0 then(Func5 selector) { 89 | if (selector == null) { 90 | throw new NullPointerException(); 91 | } 92 | return new Plan5(this, selector); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Pattern6.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Observable; 19 | import rx.functions.Func6; 20 | 21 | /** 22 | * Represents a join pattern over observable sequences. 23 | */ 24 | public final class Pattern6 implements Pattern { 25 | private final Observable o1; 26 | private final Observable o2; 27 | private final Observable o3; 28 | private final Observable o4; 29 | private final Observable o5; 30 | private final Observable o6; 31 | 32 | public Pattern6( 33 | Observable o1, 34 | Observable o2, 35 | Observable o3, 36 | Observable o4, 37 | Observable o5, 38 | Observable o6 39 | ) { 40 | this.o1 = o1; 41 | this.o2 = o2; 42 | this.o3 = o3; 43 | this.o4 = o4; 44 | this.o5 = o5; 45 | this.o6 = o6; 46 | } 47 | 48 | Observable o1() { 49 | return o1; 50 | } 51 | 52 | Observable o2() { 53 | return o2; 54 | } 55 | 56 | Observable o3() { 57 | return o3; 58 | } 59 | 60 | Observable o4() { 61 | return o4; 62 | } 63 | 64 | Observable o5() { 65 | return o5; 66 | } 67 | 68 | Observable o6() { 69 | return o6; 70 | } 71 | 72 | /** 73 | * Creates a pattern that matches when all six observable sequences have an available element. 74 | * 75 | * @param other 76 | * Observable sequence to match with the five previous sequences. 77 | * @return Pattern object that matches when all observable sequences have an available element. 78 | */ 79 | public Pattern7 and(Observable other) { 80 | if (other == null) { 81 | throw new NullPointerException(); 82 | } 83 | return new Pattern7(o1, o2, o3, o4, o5, o6, other); 84 | } 85 | /** 86 | * Matches when all observable sequences have an available 87 | * element and projects the elements by invoking the selector function. 88 | * 89 | * @param selector 90 | * the function that will be invoked for elements in the source sequences. 91 | * @return the plan for the matching 92 | * @throws NullPointerException 93 | * if selector is null 94 | */ 95 | public Plan0 then(Func6 selector) { 96 | if (selector == null) { 97 | throw new NullPointerException(); 98 | } 99 | return new Plan6(this, selector); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Pattern7.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Observable; 19 | import rx.functions.Func7; 20 | 21 | /** 22 | * Represents a join pattern over observable sequences. 23 | */ 24 | public final class Pattern7 implements Pattern { 25 | private final Observable o1; 26 | private final Observable o2; 27 | private final Observable o3; 28 | private final Observable o4; 29 | private final Observable o5; 30 | private final Observable o6; 31 | private final Observable o7; 32 | 33 | public Pattern7( 34 | Observable o1, 35 | Observable o2, 36 | Observable o3, 37 | Observable o4, 38 | Observable o5, 39 | Observable o6, 40 | Observable o7 41 | ) { 42 | this.o1 = o1; 43 | this.o2 = o2; 44 | this.o3 = o3; 45 | this.o4 = o4; 46 | this.o5 = o5; 47 | this.o6 = o6; 48 | this.o7 = o7; 49 | } 50 | 51 | Observable o1() { 52 | return o1; 53 | } 54 | 55 | Observable o2() { 56 | return o2; 57 | } 58 | 59 | Observable o3() { 60 | return o3; 61 | } 62 | 63 | Observable o4() { 64 | return o4; 65 | } 66 | 67 | Observable o5() { 68 | return o5; 69 | } 70 | 71 | Observable o6() { 72 | return o6; 73 | } 74 | 75 | Observable o7() { 76 | return o7; 77 | } 78 | 79 | /** 80 | * Creates a pattern that matches when all seven observable sequences have an available element. 81 | * 82 | * @param other 83 | * Observable sequence to match with the six previous sequences. 84 | * @return Pattern object that matches when all observable sequences have an available element. 85 | */ 86 | public Pattern8 and(Observable other) { 87 | if (other == null) { 88 | throw new NullPointerException(); 89 | } 90 | return new Pattern8(o1, o2, o3, o4, o5, o6, o7, other); 91 | } 92 | /** 93 | * Matches when all observable sequences have an available 94 | * element and projects the elements by invoking the selector function. 95 | * 96 | * @param selector 97 | * the function that will be invoked for elements in the source sequences. 98 | * @return the plan for the matching 99 | * @throws NullPointerException 100 | * if selector is null 101 | */ 102 | public Plan0 then(Func7 selector) { 103 | if (selector == null) { 104 | throw new NullPointerException(); 105 | } 106 | return new Plan7(this, selector); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Pattern8.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import rx.Observable; 19 | import rx.functions.Func8; 20 | 21 | /** 22 | * Represents a join pattern over observable sequences. 23 | */ 24 | public final class Pattern8 implements Pattern { 25 | private final Observable o1; 26 | private final Observable o2; 27 | private final Observable o3; 28 | private final Observable o4; 29 | private final Observable o5; 30 | private final Observable o6; 31 | private final Observable o7; 32 | private final Observable o8; 33 | 34 | public Pattern8( 35 | Observable o1, 36 | Observable o2, 37 | Observable o3, 38 | Observable o4, 39 | Observable o5, 40 | Observable o6, 41 | Observable o7, 42 | Observable o8 43 | ) { 44 | this.o1 = o1; 45 | this.o2 = o2; 46 | this.o3 = o3; 47 | this.o4 = o4; 48 | this.o5 = o5; 49 | this.o6 = o6; 50 | this.o7 = o7; 51 | this.o8 = o8; 52 | } 53 | 54 | Observable o1() { 55 | return o1; 56 | } 57 | 58 | Observable o2() { 59 | return o2; 60 | } 61 | 62 | Observable o3() { 63 | return o3; 64 | } 65 | 66 | Observable o4() { 67 | return o4; 68 | } 69 | 70 | Observable o5() { 71 | return o5; 72 | } 73 | 74 | Observable o6() { 75 | return o6; 76 | } 77 | 78 | Observable o7() { 79 | return o7; 80 | } 81 | 82 | Observable o8() { 83 | return o8; 84 | } 85 | 86 | /** 87 | * Creates a pattern that matches when all eight observable sequences have an available element. 88 | * 89 | * @param other 90 | * Observable sequence to match with the seven previous sequences. 91 | * @return Pattern object that matches when all observable sequences have an available element. 92 | */ 93 | public Pattern9 and(Observable other) { 94 | if (other == null) { 95 | throw new NullPointerException(); 96 | } 97 | return new Pattern9(o1, o2, o3, o4, o5, o6, o7, o8, other); 98 | } 99 | /** 100 | * Matches when all observable sequences have an available 101 | * element and projects the elements by invoking the selector function. 102 | * 103 | * @param selector 104 | * the function that will be invoked for elements in the source sequences. 105 | * @return the plan for the matching 106 | * @throws NullPointerException 107 | * if selector is null 108 | */ 109 | public Plan0 then(Func8 selector) { 110 | if (selector == null) { 111 | throw new NullPointerException(); 112 | } 113 | return new Plan8(this, selector); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Pattern9.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import rx.Observable; 22 | import rx.functions.Func9; 23 | 24 | /** 25 | * Represents a join pattern over observable sequences. 26 | */ 27 | public final class Pattern9 implements Pattern { 28 | private final Observable o1; 29 | private final Observable o2; 30 | private final Observable o3; 31 | private final Observable o4; 32 | private final Observable o5; 33 | private final Observable o6; 34 | private final Observable o7; 35 | private final Observable o8; 36 | private final Observable o9; 37 | 38 | public Pattern9( 39 | Observable o1, 40 | Observable o2, 41 | Observable o3, 42 | Observable o4, 43 | Observable o5, 44 | Observable o6, 45 | Observable o7, 46 | Observable o8, 47 | Observable o9 48 | ) { 49 | this.o1 = o1; 50 | this.o2 = o2; 51 | this.o3 = o3; 52 | this.o4 = o4; 53 | this.o5 = o5; 54 | this.o6 = o6; 55 | this.o7 = o7; 56 | this.o8 = o8; 57 | this.o9 = o9; 58 | } 59 | 60 | Observable o1() { 61 | return o1; 62 | } 63 | 64 | Observable o2() { 65 | return o2; 66 | } 67 | 68 | Observable o3() { 69 | return o3; 70 | } 71 | 72 | Observable o4() { 73 | return o4; 74 | } 75 | 76 | Observable o5() { 77 | return o5; 78 | } 79 | 80 | Observable o6() { 81 | return o6; 82 | } 83 | 84 | Observable o7() { 85 | return o7; 86 | } 87 | 88 | Observable o8() { 89 | return o8; 90 | } 91 | 92 | Observable o9() { 93 | return o9; 94 | } 95 | 96 | /** 97 | * Creates a pattern that matches when all nine observable sequences have an available element. 98 | * 99 | * @param other 100 | * Observable sequence to match with the eight previous sequences. 101 | * @return Pattern object that matches when all observable sequences have an available element. 102 | */ 103 | public PatternN and(Observable other) { 104 | if (other == null) { 105 | throw new NullPointerException(); 106 | } 107 | List> list = new ArrayList>(); 108 | list.add(o1); 109 | list.add(o2); 110 | list.add(o3); 111 | list.add(o4); 112 | list.add(o5); 113 | list.add(o6); 114 | list.add(o7); 115 | list.add(o8); 116 | list.add(o9); 117 | list.add(other); 118 | return new PatternN(list); 119 | } 120 | /** 121 | * Matches when all observable sequences have an available 122 | * element and projects the elements by invoking the selector function. 123 | * 124 | * @param selector 125 | * the function that will be invoked for elements in the source sequences. 126 | * @return the plan for the matching 127 | * @throws NullPointerException 128 | * if selector is null 129 | */ 130 | public Plan0 then(Func9 selector) { 131 | if (selector == null) { 132 | throw new NullPointerException(); 133 | } 134 | return new Plan9(this, selector); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/PatternN.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import rx.Observable; 22 | import rx.functions.FuncN; 23 | 24 | /** 25 | * Represents a join pattern over observable sequences. 26 | */ 27 | public final class PatternN implements Pattern { 28 | private final List> observables; 29 | 30 | public PatternN(List> observables) { 31 | this.observables = observables; 32 | } 33 | 34 | public PatternN(List> observables, Observable other) { 35 | this.observables = new ArrayList>(observables); 36 | this.observables.add(other); 37 | } 38 | 39 | /** 40 | * @return the number of observables in this pattern. 41 | */ 42 | int size() { 43 | return observables.size(); 44 | } 45 | /** 46 | * Returns the specific Observable from this pattern. 47 | * @param index the index 48 | * @return the observable 49 | */ 50 | Observable get(int index) { 51 | return observables.get(index); 52 | } 53 | 54 | /** 55 | * Creates a pattern that matches when all previous observable sequences have an available element. 56 | * 57 | * @param other 58 | * Observable sequence to match with the previous sequences. 59 | * @return Pattern object that matches when all observable sequences have an available element. 60 | */ 61 | public PatternN and(Observable other) { 62 | if (other == null) { 63 | throw new NullPointerException(); 64 | } 65 | return new PatternN(observables, other); 66 | } 67 | 68 | /** 69 | * Matches when all observable sequences have an available 70 | * element and projects the elements by invoking the selector function. 71 | * 72 | * @param selector 73 | * the function that will be invoked for elements in the source sequences. 74 | * @return the plan for the matching 75 | * @throws NullPointerException 76 | * if selector is null 77 | */ 78 | public Plan0 then(FuncN selector) { 79 | if (selector == null) { 80 | throw new NullPointerException(); 81 | } 82 | return new PlanN(this, selector); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Plan0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.Map; 19 | 20 | import rx.Observable; 21 | import rx.Observer; 22 | import rx.functions.Action1; 23 | 24 | /** 25 | * Represents an execution plan for join patterns. 26 | */ 27 | public abstract class Plan0 { 28 | public abstract ActivePlan0 activate(Map externalSubscriptions, 29 | Observer observer, Action1 deactivate); 30 | 31 | @SuppressWarnings("unchecked") 32 | public static final JoinObserver1 createObserver( 33 | Map externalSubscriptions, 34 | Observable observable, 35 | Action1 onError 36 | ) { 37 | JoinObserver1 observer; 38 | JoinObserver nonGeneric = externalSubscriptions.get(observable); 39 | if (nonGeneric == null) { 40 | observer = new JoinObserver1(observable, onError); 41 | externalSubscriptions.put(observable, observer); 42 | } else { 43 | observer = (JoinObserver1) nonGeneric; 44 | } 45 | return observer; 46 | } 47 | 48 | /** 49 | * Extracts a method reference to the Observer's {@link Observer#onError(java.lang.Throwable) onError} 50 | * method in the form of an {@link Action1}. 51 | *

Java 8: observer::onError

52 | * 53 | * @param observer 54 | * the {@link Observer} to use 55 | * @return an action which calls observer's {@code onError} method. 56 | */ 57 | protected static Action1 onErrorFrom(final Observer observer) { 58 | return new Action1() { 59 | @Override 60 | public void call(Throwable t1) { 61 | observer.onError(t1); 62 | } 63 | }; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Plan1.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | import rx.Observer; 22 | import rx.functions.Action0; 23 | import rx.functions.Action1; 24 | import rx.functions.Func1; 25 | 26 | /** 27 | * Represents an execution plan for join patterns. 28 | */ 29 | public final class Plan1 extends Plan0 { 30 | protected final Pattern1 expression; 31 | protected final Func1 selector; 32 | 33 | public Plan1(Pattern1 expression, Func1 selector) { 34 | this.expression = expression; 35 | this.selector = selector; 36 | } 37 | 38 | @Override 39 | public ActivePlan0 activate(Map externalSubscriptions, final Observer observer, final Action1 deactivate) { 40 | Action1 onError = onErrorFrom(observer); 41 | 42 | final JoinObserver1 firstJoinObserver = createObserver(externalSubscriptions, expression.o1(), onError); 43 | 44 | final AtomicReference> self = new AtomicReference>(); 45 | 46 | ActivePlan1 activePlan = new ActivePlan1(firstJoinObserver, new Action1() { 47 | @Override 48 | public void call(T1 t1) { 49 | R result; 50 | try { 51 | result = selector.call(t1); 52 | } catch (Throwable t) { 53 | observer.onError(t); 54 | return; 55 | } 56 | observer.onNext(result); 57 | } 58 | }, 59 | new Action0() { 60 | @Override 61 | public void call() { 62 | ActivePlan0 ap = self.get(); 63 | firstJoinObserver.removeActivePlan(ap); 64 | deactivate.call(ap); 65 | } 66 | }); 67 | 68 | self.set(activePlan); 69 | 70 | firstJoinObserver.addActivePlan(activePlan); 71 | return activePlan; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Plan2.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | import rx.Observer; 22 | import rx.functions.Action0; 23 | import rx.functions.Action1; 24 | import rx.functions.Action2; 25 | import rx.functions.Func2; 26 | 27 | /** 28 | * Represents an execution plan for join patterns. 29 | */ 30 | public final class Plan2 extends Plan0 { 31 | protected final Pattern2 expression; 32 | protected final Func2 selector; 33 | 34 | public Plan2(Pattern2 expression, Func2 selector) { 35 | this.expression = expression; 36 | this.selector = selector; 37 | } 38 | 39 | @Override 40 | public ActivePlan0 activate(Map externalSubscriptions, 41 | final Observer observer, final Action1 deactivate) { 42 | Action1 onError = onErrorFrom(observer); 43 | 44 | final JoinObserver1 jo1 = createObserver(externalSubscriptions, expression.o1(), onError); 45 | final JoinObserver1 jo2 = createObserver(externalSubscriptions, expression.o2(), onError); 46 | 47 | final AtomicReference> self = new AtomicReference>(); 48 | 49 | ActivePlan2 activePlan = new ActivePlan2(jo1, jo2, new Action2() { 50 | @Override 51 | public void call(T1 t1, T2 t2) { 52 | R result; 53 | try { 54 | result = selector.call(t1, t2); 55 | } catch (Throwable t) { 56 | observer.onError(t); 57 | return; 58 | } 59 | observer.onNext(result); 60 | } 61 | }, 62 | new Action0() { 63 | @Override 64 | public void call() { 65 | ActivePlan0 ap = self.get(); 66 | jo1.removeActivePlan(ap); 67 | jo2.removeActivePlan(ap); 68 | deactivate.call(ap); 69 | } 70 | }); 71 | 72 | self.set(activePlan); 73 | 74 | jo1.addActivePlan(activePlan); 75 | jo2.addActivePlan(activePlan); 76 | 77 | return activePlan; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Plan3.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | import rx.Observer; 22 | import rx.functions.Action0; 23 | import rx.functions.Action1; 24 | import rx.functions.Action3; 25 | import rx.functions.Func3; 26 | 27 | /** 28 | * Represents an execution plan for join patterns. 29 | */ 30 | public final class Plan3 extends Plan0 { 31 | protected final Pattern3 expression; 32 | protected final Func3 selector; 33 | 34 | public Plan3(Pattern3 expression, Func3 selector) { 35 | this.expression = expression; 36 | this.selector = selector; 37 | } 38 | 39 | @Override 40 | public ActivePlan0 activate(Map externalSubscriptions, 41 | final Observer observer, final Action1 deactivate) { 42 | Action1 onError = onErrorFrom(observer); 43 | 44 | final JoinObserver1 jo1 = createObserver(externalSubscriptions, expression.o1(), onError); 45 | final JoinObserver1 jo2 = createObserver(externalSubscriptions, expression.o2(), onError); 46 | final JoinObserver1 jo3 = createObserver(externalSubscriptions, expression.o3(), onError); 47 | 48 | final AtomicReference> self = new AtomicReference>(); 49 | 50 | ActivePlan3 activePlan = new ActivePlan3( 51 | jo1, jo2, jo3, 52 | new Action3() { 53 | @Override 54 | public void call(T1 t1, T2 t2, T3 t3) { 55 | R result; 56 | try { 57 | result = selector.call(t1, t2, t3); 58 | } catch (Throwable t) { 59 | observer.onError(t); 60 | return; 61 | } 62 | observer.onNext(result); 63 | } 64 | }, 65 | new Action0() { 66 | @Override 67 | public void call() { 68 | ActivePlan0 ap = self.get(); 69 | jo1.removeActivePlan(ap); 70 | jo2.removeActivePlan(ap); 71 | jo3.removeActivePlan(ap); 72 | deactivate.call(ap); 73 | } 74 | }); 75 | 76 | self.set(activePlan); 77 | 78 | jo1.addActivePlan(activePlan); 79 | jo2.addActivePlan(activePlan); 80 | jo3.addActivePlan(activePlan); 81 | 82 | return activePlan; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Plan4.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | import rx.Observer; 22 | import rx.functions.Action0; 23 | import rx.functions.Action1; 24 | import rx.functions.Action4; 25 | import rx.functions.Func4; 26 | 27 | /** 28 | * Represents an execution plan for join patterns. 29 | */ 30 | public final class Plan4 extends Plan0 { 31 | protected final Pattern4 expression; 32 | protected final Func4 selector; 33 | 34 | public Plan4(Pattern4 expression, Func4 selector) { 35 | this.expression = expression; 36 | this.selector = selector; 37 | } 38 | 39 | @Override 40 | public ActivePlan0 activate(Map externalSubscriptions, 41 | final Observer observer, final Action1 deactivate) { 42 | Action1 onError = onErrorFrom(observer); 43 | 44 | final JoinObserver1 jo1 = createObserver(externalSubscriptions, expression.o1(), onError); 45 | final JoinObserver1 jo2 = createObserver(externalSubscriptions, expression.o2(), onError); 46 | final JoinObserver1 jo3 = createObserver(externalSubscriptions, expression.o3(), onError); 47 | final JoinObserver1 jo4 = createObserver(externalSubscriptions, expression.o4(), onError); 48 | 49 | final AtomicReference self = new AtomicReference(); 50 | 51 | ActivePlan0 activePlan = new ActivePlan4( 52 | jo1, jo2, jo3, jo4, 53 | new Action4() { 54 | @Override 55 | public void call(T1 t1, T2 t2, T3 t3, T4 t4) { 56 | R result; 57 | try { 58 | result = selector.call(t1, t2, t3, t4); 59 | } catch (Throwable t) { 60 | observer.onError(t); 61 | return; 62 | } 63 | observer.onNext(result); 64 | } 65 | }, 66 | new Action0() { 67 | @Override 68 | public void call() { 69 | ActivePlan0 ap = self.get(); 70 | jo1.removeActivePlan(ap); 71 | jo2.removeActivePlan(ap); 72 | jo3.removeActivePlan(ap); 73 | jo4.removeActivePlan(ap); 74 | deactivate.call(ap); 75 | } 76 | }); 77 | 78 | self.set(activePlan); 79 | 80 | jo1.addActivePlan(activePlan); 81 | jo2.addActivePlan(activePlan); 82 | jo3.addActivePlan(activePlan); 83 | jo4.addActivePlan(activePlan); 84 | 85 | return activePlan; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Plan5.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | import rx.Observer; 22 | import rx.functions.Action0; 23 | import rx.functions.Action1; 24 | import rx.functions.Action5; 25 | import rx.functions.Func5; 26 | 27 | /** 28 | * Represents an execution plan for join patterns. 29 | */ 30 | public final class Plan5 extends Plan0 { 31 | protected final Pattern5 expression; 32 | protected final Func5 selector; 33 | 34 | public Plan5(Pattern5 expression, Func5 selector) { 35 | this.expression = expression; 36 | this.selector = selector; 37 | } 38 | 39 | @Override 40 | public ActivePlan0 activate(Map externalSubscriptions, 41 | final Observer observer, final Action1 deactivate) { 42 | Action1 onError = onErrorFrom(observer); 43 | 44 | final JoinObserver1 jo1 = createObserver(externalSubscriptions, expression.o1(), onError); 45 | final JoinObserver1 jo2 = createObserver(externalSubscriptions, expression.o2(), onError); 46 | final JoinObserver1 jo3 = createObserver(externalSubscriptions, expression.o3(), onError); 47 | final JoinObserver1 jo4 = createObserver(externalSubscriptions, expression.o4(), onError); 48 | final JoinObserver1 jo5 = createObserver(externalSubscriptions, expression.o5(), onError); 49 | 50 | final AtomicReference self = new AtomicReference(); 51 | 52 | ActivePlan0 activePlan = new ActivePlan5( 53 | jo1, jo2, jo3, jo4, jo5, 54 | new Action5() { 55 | @Override 56 | public void call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) { 57 | R result; 58 | try { 59 | result = selector.call(t1, t2, t3, t4, t5); 60 | } catch (Throwable t) { 61 | observer.onError(t); 62 | return; 63 | } 64 | observer.onNext(result); 65 | } 66 | }, 67 | new Action0() { 68 | @Override 69 | public void call() { 70 | ActivePlan0 ap = self.get(); 71 | jo1.removeActivePlan(ap); 72 | jo2.removeActivePlan(ap); 73 | jo3.removeActivePlan(ap); 74 | jo4.removeActivePlan(ap); 75 | jo5.removeActivePlan(ap); 76 | deactivate.call(ap); 77 | } 78 | }); 79 | 80 | self.set(activePlan); 81 | 82 | jo1.addActivePlan(activePlan); 83 | jo2.addActivePlan(activePlan); 84 | jo3.addActivePlan(activePlan); 85 | jo4.addActivePlan(activePlan); 86 | jo5.addActivePlan(activePlan); 87 | 88 | return activePlan; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Plan6.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | import rx.Observer; 22 | import rx.functions.Action0; 23 | import rx.functions.Action1; 24 | import rx.functions.Action6; 25 | import rx.functions.Func6; 26 | 27 | /** 28 | * Represents an execution plan for join patterns. 29 | */ 30 | public final class Plan6 extends Plan0 { 31 | protected final Pattern6 expression; 32 | protected final Func6 selector; 33 | 34 | public Plan6(Pattern6 expression, Func6 selector) { 35 | this.expression = expression; 36 | this.selector = selector; 37 | } 38 | 39 | @Override 40 | public ActivePlan0 activate(Map externalSubscriptions, 41 | final Observer observer, final Action1 deactivate) { 42 | Action1 onError = onErrorFrom(observer); 43 | 44 | final JoinObserver1 jo1 = createObserver(externalSubscriptions, expression.o1(), onError); 45 | final JoinObserver1 jo2 = createObserver(externalSubscriptions, expression.o2(), onError); 46 | final JoinObserver1 jo3 = createObserver(externalSubscriptions, expression.o3(), onError); 47 | final JoinObserver1 jo4 = createObserver(externalSubscriptions, expression.o4(), onError); 48 | final JoinObserver1 jo5 = createObserver(externalSubscriptions, expression.o5(), onError); 49 | final JoinObserver1 jo6 = createObserver(externalSubscriptions, expression.o6(), onError); 50 | 51 | final AtomicReference self = new AtomicReference(); 52 | 53 | ActivePlan0 activePlan = new ActivePlan6( 54 | jo1, jo2, jo3, jo4, jo5, jo6, 55 | new Action6() { 56 | @Override 57 | public void call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) { 58 | R result; 59 | try { 60 | result = selector.call(t1, t2, t3, t4, t5, t6); 61 | } catch (Throwable t) { 62 | observer.onError(t); 63 | return; 64 | } 65 | observer.onNext(result); 66 | } 67 | }, 68 | new Action0() { 69 | @Override 70 | public void call() { 71 | ActivePlan0 ap = self.get(); 72 | jo1.removeActivePlan(ap); 73 | jo2.removeActivePlan(ap); 74 | jo3.removeActivePlan(ap); 75 | jo4.removeActivePlan(ap); 76 | jo5.removeActivePlan(ap); 77 | jo6.removeActivePlan(ap); 78 | deactivate.call(ap); 79 | } 80 | }); 81 | 82 | self.set(activePlan); 83 | 84 | jo1.addActivePlan(activePlan); 85 | jo2.addActivePlan(activePlan); 86 | jo3.addActivePlan(activePlan); 87 | jo4.addActivePlan(activePlan); 88 | jo5.addActivePlan(activePlan); 89 | jo6.addActivePlan(activePlan); 90 | 91 | return activePlan; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Plan7.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | import rx.Observer; 22 | import rx.functions.Action0; 23 | import rx.functions.Action1; 24 | import rx.functions.Action7; 25 | import rx.functions.Func7; 26 | 27 | /** 28 | * Represents an execution plan for join patterns. 29 | */ 30 | public final class Plan7 extends Plan0 { 31 | protected final Pattern7 expression; 32 | protected final Func7 selector; 33 | 34 | public Plan7(Pattern7 expression, Func7 selector) { 35 | this.expression = expression; 36 | this.selector = selector; 37 | } 38 | 39 | @Override 40 | public ActivePlan0 activate(Map externalSubscriptions, 41 | final Observer observer, final Action1 deactivate) { 42 | Action1 onError = onErrorFrom(observer); 43 | 44 | final JoinObserver1 jo1 = createObserver(externalSubscriptions, expression.o1(), onError); 45 | final JoinObserver1 jo2 = createObserver(externalSubscriptions, expression.o2(), onError); 46 | final JoinObserver1 jo3 = createObserver(externalSubscriptions, expression.o3(), onError); 47 | final JoinObserver1 jo4 = createObserver(externalSubscriptions, expression.o4(), onError); 48 | final JoinObserver1 jo5 = createObserver(externalSubscriptions, expression.o5(), onError); 49 | final JoinObserver1 jo6 = createObserver(externalSubscriptions, expression.o6(), onError); 50 | final JoinObserver1 jo7 = createObserver(externalSubscriptions, expression.o7(), onError); 51 | 52 | final AtomicReference self = new AtomicReference(); 53 | 54 | ActivePlan0 activePlan = new ActivePlan7( 55 | jo1, jo2, jo3, jo4, jo5, jo6, jo7, 56 | new Action7() { 57 | @Override 58 | public void call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) { 59 | R result; 60 | try { 61 | result = selector.call(t1, t2, t3, t4, t5, t6, t7); 62 | } catch (Throwable t) { 63 | observer.onError(t); 64 | return; 65 | } 66 | observer.onNext(result); 67 | } 68 | }, 69 | new Action0() { 70 | @Override 71 | public void call() { 72 | ActivePlan0 ap = self.get(); 73 | jo1.removeActivePlan(ap); 74 | jo2.removeActivePlan(ap); 75 | jo3.removeActivePlan(ap); 76 | jo4.removeActivePlan(ap); 77 | jo5.removeActivePlan(ap); 78 | jo6.removeActivePlan(ap); 79 | jo7.removeActivePlan(ap); 80 | deactivate.call(ap); 81 | } 82 | }); 83 | 84 | self.set(activePlan); 85 | 86 | jo1.addActivePlan(activePlan); 87 | jo2.addActivePlan(activePlan); 88 | jo3.addActivePlan(activePlan); 89 | jo4.addActivePlan(activePlan); 90 | jo5.addActivePlan(activePlan); 91 | jo6.addActivePlan(activePlan); 92 | jo7.addActivePlan(activePlan); 93 | 94 | return activePlan; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Plan8.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | import rx.Observer; 22 | import rx.functions.Action0; 23 | import rx.functions.Action1; 24 | import rx.functions.Action8; 25 | import rx.functions.Func8; 26 | 27 | /** 28 | * Represents an execution plan for join patterns. 29 | */ 30 | public final class Plan8 extends Plan0 { 31 | protected final Pattern8 expression; 32 | protected final Func8 selector; 33 | 34 | public Plan8(Pattern8 expression, Func8 selector) { 35 | this.expression = expression; 36 | this.selector = selector; 37 | } 38 | 39 | @Override 40 | public ActivePlan0 activate(Map externalSubscriptions, 41 | final Observer observer, final Action1 deactivate) { 42 | Action1 onError = onErrorFrom(observer); 43 | 44 | final JoinObserver1 jo1 = createObserver(externalSubscriptions, expression.o1(), onError); 45 | final JoinObserver1 jo2 = createObserver(externalSubscriptions, expression.o2(), onError); 46 | final JoinObserver1 jo3 = createObserver(externalSubscriptions, expression.o3(), onError); 47 | final JoinObserver1 jo4 = createObserver(externalSubscriptions, expression.o4(), onError); 48 | final JoinObserver1 jo5 = createObserver(externalSubscriptions, expression.o5(), onError); 49 | final JoinObserver1 jo6 = createObserver(externalSubscriptions, expression.o6(), onError); 50 | final JoinObserver1 jo7 = createObserver(externalSubscriptions, expression.o7(), onError); 51 | final JoinObserver1 jo8 = createObserver(externalSubscriptions, expression.o8(), onError); 52 | 53 | final AtomicReference self = new AtomicReference(); 54 | 55 | ActivePlan0 activePlan = new ActivePlan8( 56 | jo1, jo2, jo3, jo4, jo5, jo6, jo7, jo8, 57 | new Action8() { 58 | @Override 59 | public void call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) { 60 | R result; 61 | try { 62 | result = selector.call(t1, t2, t3, t4, t5, t6, t7, t8); 63 | } catch (Throwable t) { 64 | observer.onError(t); 65 | return; 66 | } 67 | observer.onNext(result); 68 | } 69 | }, 70 | new Action0() { 71 | @Override 72 | public void call() { 73 | ActivePlan0 ap = self.get(); 74 | jo1.removeActivePlan(ap); 75 | jo2.removeActivePlan(ap); 76 | jo3.removeActivePlan(ap); 77 | jo4.removeActivePlan(ap); 78 | jo5.removeActivePlan(ap); 79 | jo6.removeActivePlan(ap); 80 | jo7.removeActivePlan(ap); 81 | jo8.removeActivePlan(ap); 82 | deactivate.call(ap); 83 | } 84 | }); 85 | 86 | self.set(activePlan); 87 | 88 | jo1.addActivePlan(activePlan); 89 | jo2.addActivePlan(activePlan); 90 | jo3.addActivePlan(activePlan); 91 | jo4.addActivePlan(activePlan); 92 | jo5.addActivePlan(activePlan); 93 | jo6.addActivePlan(activePlan); 94 | jo7.addActivePlan(activePlan); 95 | jo8.addActivePlan(activePlan); 96 | 97 | return activePlan; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/Plan9.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | import rx.Observer; 22 | import rx.functions.Action0; 23 | import rx.functions.Action1; 24 | import rx.functions.Action9; 25 | import rx.functions.Func9; 26 | 27 | /** 28 | * Represents an execution plan for join patterns. 29 | */ 30 | public final class Plan9 extends Plan0 { 31 | protected final Pattern9 expression; 32 | protected final Func9 selector; 33 | 34 | public Plan9(Pattern9 expression, Func9 selector) { 35 | this.expression = expression; 36 | this.selector = selector; 37 | } 38 | 39 | @Override 40 | public ActivePlan0 activate(Map externalSubscriptions, 41 | final Observer observer, final Action1 deactivate) { 42 | Action1 onError = onErrorFrom(observer); 43 | 44 | final JoinObserver1 jo1 = createObserver(externalSubscriptions, expression.o1(), onError); 45 | final JoinObserver1 jo2 = createObserver(externalSubscriptions, expression.o2(), onError); 46 | final JoinObserver1 jo3 = createObserver(externalSubscriptions, expression.o3(), onError); 47 | final JoinObserver1 jo4 = createObserver(externalSubscriptions, expression.o4(), onError); 48 | final JoinObserver1 jo5 = createObserver(externalSubscriptions, expression.o5(), onError); 49 | final JoinObserver1 jo6 = createObserver(externalSubscriptions, expression.o6(), onError); 50 | final JoinObserver1 jo7 = createObserver(externalSubscriptions, expression.o7(), onError); 51 | final JoinObserver1 jo8 = createObserver(externalSubscriptions, expression.o8(), onError); 52 | final JoinObserver1 jo9 = createObserver(externalSubscriptions, expression.o9(), onError); 53 | 54 | final AtomicReference self = new AtomicReference(); 55 | 56 | ActivePlan0 activePlan = new ActivePlan9( 57 | jo1, jo2, jo3, jo4, jo5, jo6, jo7, jo8, jo9, 58 | new Action9() { 59 | @Override 60 | public void call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) { 61 | R result; 62 | try { 63 | result = selector.call(t1, t2, t3, t4, t5, t6, t7, t8, t9); 64 | } catch (Throwable t) { 65 | observer.onError(t); 66 | return; 67 | } 68 | observer.onNext(result); 69 | } 70 | }, 71 | new Action0() { 72 | @Override 73 | public void call() { 74 | ActivePlan0 ap = self.get(); 75 | jo1.removeActivePlan(ap); 76 | jo2.removeActivePlan(ap); 77 | jo3.removeActivePlan(ap); 78 | jo4.removeActivePlan(ap); 79 | jo5.removeActivePlan(ap); 80 | jo6.removeActivePlan(ap); 81 | jo7.removeActivePlan(ap); 82 | jo8.removeActivePlan(ap); 83 | jo9.removeActivePlan(ap); 84 | deactivate.call(ap); 85 | } 86 | }); 87 | 88 | self.set(activePlan); 89 | 90 | jo1.addActivePlan(activePlan); 91 | jo2.addActivePlan(activePlan); 92 | jo3.addActivePlan(activePlan); 93 | jo4.addActivePlan(activePlan); 94 | jo5.addActivePlan(activePlan); 95 | jo6.addActivePlan(activePlan); 96 | jo7.addActivePlan(activePlan); 97 | jo8.addActivePlan(activePlan); 98 | jo9.addActivePlan(activePlan); 99 | 100 | return activePlan; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/PlanN.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.concurrent.atomic.AtomicReference; 22 | 23 | import rx.Observer; 24 | import rx.functions.Action0; 25 | import rx.functions.Action1; 26 | import rx.functions.ActionN; 27 | import rx.functions.FuncN; 28 | 29 | /** 30 | * Represents an execution plan for join patterns. 31 | */ 32 | public final class PlanN extends Plan0 { 33 | protected final PatternN expression; 34 | protected final FuncN selector; 35 | 36 | public PlanN(PatternN expression, FuncN selector) { 37 | this.expression = expression; 38 | this.selector = selector; 39 | } 40 | 41 | @Override 42 | public ActivePlan0 activate(Map externalSubscriptions, 43 | final Observer observer, final Action1 deactivate) { 44 | Action1 onError = onErrorFrom(observer); 45 | 46 | final List> observers = new ArrayList>(); 47 | for (int i = 0; i < expression.size(); i++) { 48 | observers.add(createObserver(externalSubscriptions, expression.get(i), onError)); 49 | } 50 | final AtomicReference self = new AtomicReference(); 51 | 52 | ActivePlanN activePlan = new ActivePlanN(observers, new ActionN() { 53 | @Override 54 | public void call(Object... args) { 55 | R result; 56 | try { 57 | result = selector.call(args); 58 | } catch (Throwable t) { 59 | observer.onError(t); 60 | return; 61 | } 62 | observer.onNext(result); 63 | } 64 | }, 65 | new Action0() { 66 | @Override 67 | public void call() { 68 | for (JoinObserver1 jo : observers) { 69 | jo.removeActivePlan(self.get()); 70 | } 71 | deactivate.call(self.get()); 72 | } 73 | }); 74 | 75 | self.set(activePlan); 76 | 77 | for (JoinObserver1 jo : observers) { 78 | jo.addActivePlan(activePlan); 79 | } 80 | 81 | return activePlan; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/rx/joins/operators/OperatorJoinPatterns.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins.operators; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import rx.Observable; 25 | import rx.Observable.OnSubscribe; 26 | import rx.Observer; 27 | import rx.Subscriber; 28 | import rx.functions.Action1; 29 | import rx.functions.Func1; 30 | import rx.joins.ActivePlan0; 31 | import rx.joins.JoinObserver; 32 | import rx.joins.Pattern1; 33 | import rx.joins.Pattern2; 34 | import rx.joins.Plan0; 35 | import rx.subscriptions.CompositeSubscription; 36 | 37 | /** 38 | * Join patterns: And, Then, When. 39 | */ 40 | public final class OperatorJoinPatterns { 41 | public OperatorJoinPatterns() { throw new IllegalStateException("No instances!"); } 42 | /** 43 | * Creates a pattern that matches when both observable sequences have an available element. 44 | */ 45 | public static Pattern2 and(/* this */Observable left, Observable right) { 46 | if (left == null) { 47 | throw new NullPointerException("left"); 48 | } 49 | if (right == null) { 50 | throw new NullPointerException("right"); 51 | } 52 | return new Pattern2(left, right); 53 | } 54 | 55 | /** 56 | * Matches when the observable sequence has an available element and projects the element by invoking the selector function. 57 | */ 58 | public static Plan0 then(/* this */Observable source, Func1 selector) { 59 | if (source == null) { 60 | throw new NullPointerException("source"); 61 | } 62 | if (selector == null) { 63 | throw new NullPointerException("selector"); 64 | } 65 | return new Pattern1(source).then(selector); 66 | } 67 | 68 | /** 69 | * Joins together the results from several patterns. 70 | */ 71 | public static OnSubscribe when(Plan0... plans) { 72 | if (plans == null) { 73 | throw new NullPointerException("plans"); 74 | } 75 | return when(Arrays.asList(plans)); 76 | } 77 | 78 | /** 79 | * Joins together the results from several patterns. 80 | */ 81 | public static OnSubscribe when(final Iterable> plans) { 82 | if (plans == null) { 83 | throw new NullPointerException("plans"); 84 | } 85 | return new OnSubscribe() { 86 | @Override 87 | public void call(final Subscriber t1) { 88 | final Map externalSubscriptions = new HashMap(); 89 | final Object gate = new Object(); 90 | final List activePlans = new ArrayList(); 91 | 92 | final Observer out = new Observer() { 93 | @Override 94 | public void onNext(R args) { 95 | t1.onNext(args); 96 | } 97 | 98 | @Override 99 | public void onError(Throwable e) { 100 | for (JoinObserver po : externalSubscriptions.values()) { 101 | po.unsubscribe(); 102 | } 103 | t1.onError(e); 104 | } 105 | 106 | @Override 107 | public void onCompleted() { 108 | t1.onCompleted(); 109 | } 110 | }; 111 | 112 | try { 113 | for (Plan0 plan : plans) { 114 | activePlans.add(plan.activate(externalSubscriptions, out, new Action1() { 115 | @Override 116 | public void call(ActivePlan0 activePlan) { 117 | activePlans.remove(activePlan); 118 | if (activePlans.isEmpty()) { 119 | out.onCompleted(); 120 | } 121 | } 122 | })); 123 | } 124 | } catch (Throwable t) { 125 | Observable. error(t).unsafeSubscribe(t1); 126 | return; 127 | } 128 | CompositeSubscription group = new CompositeSubscription(); 129 | t1.add(group); 130 | for (JoinObserver jo : externalSubscriptions.values()) { 131 | jo.subscribe(gate); 132 | group.add(jo); 133 | } 134 | } 135 | }; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/rx/observables/JoinObservable.java: -------------------------------------------------------------------------------- 1 | package rx.observables; 2 | 3 | import rx.Observable; 4 | import rx.functions.Func1; 5 | import rx.joins.Pattern2; 6 | import rx.joins.Plan0; 7 | import rx.joins.operators.OperatorJoinPatterns; 8 | 9 | /** 10 | * Represents an observable that supports join operations. 11 | * 12 | * @param the value type joined 13 | */ 14 | public final class JoinObservable { 15 | 16 | private final Observable o; 17 | 18 | private JoinObservable(Observable o) { 19 | this.o = o; 20 | } 21 | 22 | /** 23 | * Creates a JoinObservable from a regular Observable. 24 | * @param o the observable to wrap 25 | * @return the created JoinObservable instance 26 | */ 27 | public static JoinObservable from(Observable o) { 28 | return new JoinObservable(o); 29 | } 30 | 31 | /** 32 | * Returns a Pattern that matches when both Observables emit an item. 33 | *

34 | * 35 | * 36 | * @param right 37 | * an Observable to match with the source Observable 38 | * @return a Pattern object that matches when both Observables emit an item 39 | * @throws NullPointerException 40 | * if {@code right} is null 41 | * @see RxJava Wiki: and() 42 | * @see MSDN: Observable.And 43 | */ 44 | public final Pattern2 and(Observable right) { 45 | return OperatorJoinPatterns.and(o, right); 46 | } 47 | 48 | /** 49 | * Joins together the results from several patterns via their plans. 50 | *

51 | * 52 | * 53 | * @param plans 54 | * a series of plans created by use of the {@link #then} Observer on patterns 55 | * @return an Observable that emits the results from matching several patterns 56 | * @throws NullPointerException 57 | * if {@code plans} is null 58 | * @see RxJava Wiki: when() 59 | * @see MSDN: Observable.When 60 | */ 61 | public final static JoinObservable when(Iterable> plans) { 62 | if (plans == null) { 63 | throw new NullPointerException("plans"); 64 | } 65 | return from(Observable.create(OperatorJoinPatterns.when(plans))); 66 | } 67 | 68 | /** 69 | * Joins together the results from several patterns via their plans. 70 | *

71 | * 72 | * 73 | * @param plans 74 | * a series of plans created by use of the {@link #then} Observer on patterns 75 | * @return an Observable that emits the results from matching several patterns 76 | * @throws NullPointerException 77 | * if {@code plans} is null 78 | * @see RxJava Wiki: when() 79 | * @see MSDN: Observable.When 80 | */ 81 | public final static JoinObservable when(Plan0... plans) { 82 | return from(Observable.create(OperatorJoinPatterns.when(plans))); 83 | } 84 | 85 | /** 86 | * Joins the results from a pattern via its plan. 87 | *

88 | * 89 | * 90 | * @param p1 91 | * the plan to join, created by use of the {@link #then} Observer on a pattern 92 | * @return an Observable that emits the results from matching a pattern 93 | * @see RxJava Wiki: when() 94 | * @see MSDN: Observable.When 95 | */ 96 | @SuppressWarnings("unchecked") 97 | public final static JoinObservable when(Plan0 p1) { 98 | return from(Observable.create(OperatorJoinPatterns.when(p1))); 99 | } 100 | 101 | /** 102 | * Joins together the results from two patterns via their plans. 103 | *

104 | * 105 | * 106 | * @param p1 107 | * a plan, created by use of the {@link #then} Observer on a pattern 108 | * @param p2 109 | * a plan, created by use of the {@link #then} Observer on a pattern 110 | * @return an Observable that emits the results from matching two patterns 111 | * @see RxJava Wiki: when() 112 | * @see MSDN: Observable.When 113 | */ 114 | @SuppressWarnings("unchecked") 115 | public final static JoinObservable when(Plan0 p1, Plan0 p2) { 116 | return from(Observable.create(OperatorJoinPatterns.when(p1, p2))); 117 | } 118 | 119 | /** 120 | * Joins together the results from three patterns via their plans. 121 | *

122 | * 123 | * 124 | * @param p1 125 | * a plan, created by use of the {@link #then} Observer on a pattern 126 | * @param p2 127 | * a plan, created by use of the {@link #then} Observer on a pattern 128 | * @param p3 129 | * a plan, created by use of the {@link #then} Observer on a pattern 130 | * @return an Observable that emits the results from matching three patterns 131 | * @see RxJava Wiki: when() 132 | * @see MSDN: Observable.When 133 | */ 134 | @SuppressWarnings("unchecked") 135 | public final static JoinObservable when(Plan0 p1, Plan0 p2, Plan0 p3) { 136 | return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3))); 137 | } 138 | 139 | /** 140 | * Joins together the results from four patterns via their plans. 141 | *

142 | * 143 | * 144 | * @param p1 145 | * a plan, created by use of the {@link #then} Observer on a pattern 146 | * @param p2 147 | * a plan, created by use of the {@link #then} Observer on a pattern 148 | * @param p3 149 | * a plan, created by use of the {@link #then} Observer on a pattern 150 | * @param p4 151 | * a plan, created by use of the {@link #then} Observer on a pattern 152 | * @return an Observable that emits the results from matching four patterns 153 | * @see RxJava Wiki: when() 154 | * @see MSDN: Observable.When 155 | */ 156 | @SuppressWarnings("unchecked") 157 | public final static JoinObservable when(Plan0 p1, Plan0 p2, Plan0 p3, Plan0 p4) { 158 | return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4))); 159 | } 160 | 161 | /** 162 | * Joins together the results from five patterns via their plans. 163 | *

164 | * 165 | * 166 | * @param p1 167 | * a plan, created by use of the {@link #then} Observer on a pattern 168 | * @param p2 169 | * a plan, created by use of the {@link #then} Observer on a pattern 170 | * @param p3 171 | * a plan, created by use of the {@link #then} Observer on a pattern 172 | * @param p4 173 | * a plan, created by use of the {@link #then} Observer on a pattern 174 | * @param p5 175 | * a plan, created by use of the {@link #then} Observer on a pattern 176 | * @return an Observable that emits the results from matching five patterns 177 | * @see RxJava Wiki: when() 178 | * @see MSDN: Observable.When 179 | */ 180 | @SuppressWarnings("unchecked") 181 | public final static JoinObservable when(Plan0 p1, Plan0 p2, Plan0 p3, Plan0 p4, Plan0 p5) { 182 | return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4, p5))); 183 | } 184 | 185 | /** 186 | * Joins together the results from six patterns via their plans. 187 | *

188 | * 189 | * 190 | * @param p1 191 | * a plan, created by use of the {@link #then} Observer on a pattern 192 | * @param p2 193 | * a plan, created by use of the {@link #then} Observer on a pattern 194 | * @param p3 195 | * a plan, created by use of the {@link #then} Observer on a pattern 196 | * @param p4 197 | * a plan, created by use of the {@link #then} Observer on a pattern 198 | * @param p5 199 | * a plan, created by use of the {@link #then} Observer on a pattern 200 | * @param p6 201 | * a plan, created by use of the {@link #then} Observer on a pattern 202 | * @return an Observable that emits the results from matching six patterns 203 | * @see RxJava Wiki: when() 204 | * @see MSDN: Observable.When 205 | */ 206 | @SuppressWarnings("unchecked") 207 | public final static JoinObservable when(Plan0 p1, Plan0 p2, Plan0 p3, Plan0 p4, Plan0 p5, Plan0 p6) { 208 | return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4, p5, p6))); 209 | } 210 | 211 | /** 212 | * Joins together the results from seven patterns via their plans. 213 | *

214 | * 215 | * 216 | * @param p1 217 | * a plan, created by use of the {@link #then} Observer on a pattern 218 | * @param p2 219 | * a plan, created by use of the {@link #then} Observer on a pattern 220 | * @param p3 221 | * a plan, created by use of the {@link #then} Observer on a pattern 222 | * @param p4 223 | * a plan, created by use of the {@link #then} Observer on a pattern 224 | * @param p5 225 | * a plan, created by use of the {@link #then} Observer on a pattern 226 | * @param p6 227 | * a plan, created by use of the {@link #then} Observer on a pattern 228 | * @param p7 229 | * a plan, created by use of the {@link #then} Observer on a pattern 230 | * @return an Observable that emits the results from matching seven patterns 231 | * @see RxJava Wiki: when() 232 | * @see MSDN: Observable.When 233 | */ 234 | @SuppressWarnings("unchecked") 235 | public final static JoinObservable when(Plan0 p1, Plan0 p2, Plan0 p3, Plan0 p4, Plan0 p5, Plan0 p6, Plan0 p7) { 236 | return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4, p5, p6, p7))); 237 | } 238 | 239 | /** 240 | * Joins together the results from eight patterns via their plans. 241 | *

242 | * 243 | * 244 | * @param p1 245 | * a plan, created by use of the {@link #then} Observer on a pattern 246 | * @param p2 247 | * a plan, created by use of the {@link #then} Observer on a pattern 248 | * @param p3 249 | * a plan, created by use of the {@link #then} Observer on a pattern 250 | * @param p4 251 | * a plan, created by use of the {@link #then} Observer on a pattern 252 | * @param p5 253 | * a plan, created by use of the {@link #then} Observer on a pattern 254 | * @param p6 255 | * a plan, created by use of the {@link #then} Observer on a pattern 256 | * @param p7 257 | * a plan, created by use of the {@link #then} Observer on a pattern 258 | * @param p8 259 | * a plan, created by use of the {@link #then} Observer on a pattern 260 | * @return an Observable that emits the results from matching eight patterns 261 | * @see RxJava Wiki: when() 262 | * @see MSDN: Observable.When 263 | */ 264 | @SuppressWarnings("unchecked") 265 | public final static JoinObservable when(Plan0 p1, Plan0 p2, Plan0 p3, Plan0 p4, Plan0 p5, Plan0 p6, Plan0 p7, Plan0 p8) { 266 | return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4, p5, p6, p7, p8))); 267 | } 268 | 269 | /** 270 | * Joins together the results from nine patterns via their plans. 271 | *

272 | * 273 | * 274 | * @param p1 275 | * a plan, created by use of the {@link #then} Observer on a pattern 276 | * @param p2 277 | * a plan, created by use of the {@link #then} Observer on a pattern 278 | * @param p3 279 | * a plan, created by use of the {@link #then} Observer on a pattern 280 | * @param p4 281 | * a plan, created by use of the {@link #then} Observer on a pattern 282 | * @param p5 283 | * a plan, created by use of the {@link #then} Observer on a pattern 284 | * @param p6 285 | * a plan, created by use of the {@link #then} Observer on a pattern 286 | * @param p7 287 | * a plan, created by use of the {@link #then} Observer on a pattern 288 | * @param p8 289 | * a plan, created by use of the {@link #then} Observer on a pattern 290 | * @param p9 291 | * a plan, created by use of the {@link #then} Observer on a pattern 292 | * @return an Observable that emits the results from matching nine patterns 293 | * @see RxJava Wiki: when() 294 | * @see MSDN: Observable.When 295 | */ 296 | @SuppressWarnings("unchecked") 297 | public final static JoinObservable when(Plan0 p1, Plan0 p2, Plan0 p3, Plan0 p4, Plan0 p5, Plan0 p6, Plan0 p7, Plan0 p8, Plan0 p9) { 298 | return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4, p5, p6, p7, p8, p9))); 299 | } 300 | 301 | /** 302 | * Matches when the Observable has an available item and projects the item by invoking the selector 303 | * function. 304 | *

305 | * 306 | * 307 | * @param selector 308 | * selector that will be invoked for items emitted by the source Observable 309 | * @return a {@link Plan0} that produces the projected results, to be fed (with other Plans) to the {@link #when} Observer 310 | * @throws NullPointerException 311 | * if {@code selector} is null 312 | * @see RxJava Wiki: then() 313 | * @see MSDN: Observable.Then 314 | */ 315 | public final Plan0 then(Func1 selector) { 316 | return OperatorJoinPatterns.then(o, selector); 317 | } 318 | 319 | public Observable toObservable() { 320 | return o; 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /src/test/java/rx/joins/operators/OperatorJoinsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package rx.joins.operators; 17 | 18 | import static org.junit.Assert.fail; 19 | import static org.mockito.Matchers.any; 20 | import static org.mockito.Mockito.*; 21 | 22 | import java.util.Arrays; 23 | 24 | import org.junit.*; 25 | import org.mockito.*; 26 | 27 | import rx.*; 28 | import rx.functions.*; 29 | import rx.internal.util.UtilityFunctions; 30 | import rx.joins.*; 31 | import rx.observables.JoinObservable; 32 | import rx.observers.TestSubscriber; 33 | import rx.subjects.PublishSubject; 34 | 35 | public class OperatorJoinsTest { 36 | @Mock 37 | Observer observer; 38 | 39 | static final class Adder implements 40 | Func2, 41 | Func3, 42 | Func4, 43 | Func5, 44 | Func6, 45 | Func7, 46 | Func8, 47 | Func9, 48 | FuncN 49 | { 50 | 51 | @Override 52 | public Integer call(Object... args) { 53 | int sum = 0; 54 | 55 | for(Object o : args) { 56 | sum += (Integer)o; 57 | } 58 | 59 | return sum; 60 | } 61 | 62 | @Override 63 | public Integer call(Integer t1, Integer t2, Integer t3, Integer t4, 64 | Integer t5, Integer t6, Integer t7, Integer t8, Integer t9) { 65 | return t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9; 66 | } 67 | 68 | @Override 69 | public Integer call(Integer t1, Integer t2, Integer t3, Integer t4, 70 | Integer t5, Integer t6, Integer t7, Integer t8) { 71 | return t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8; 72 | } 73 | 74 | @Override 75 | public Integer call(Integer t1, Integer t2, Integer t3, Integer t4, 76 | Integer t5, Integer t6, Integer t7) { 77 | return t1 + t2 + t3 + t4 + t5 + t6 + t7; 78 | } 79 | 80 | @Override 81 | public Integer call(Integer t1, Integer t2, Integer t3, Integer t4, 82 | Integer t5, Integer t6) { 83 | return t1 + t2 + t3 + t4 + t5 + t6; 84 | } 85 | 86 | @Override 87 | public Integer call(Integer t1, Integer t2, Integer t3, Integer t4, 88 | Integer t5) { 89 | return t1 + t2 + t3 + t4 + t5; 90 | } 91 | 92 | @Override 93 | public Integer call(Integer t1, Integer t2, Integer t3, Integer t4) { 94 | return t1 + t2 + t3 + t4; 95 | } 96 | 97 | @Override 98 | public Integer call(Integer t1, Integer t2, Integer t3) { 99 | return t1 + t2 + t3; 100 | } 101 | 102 | @Override 103 | public Integer call(Integer t1, Integer t2) { 104 | return t1 + t2; 105 | } 106 | 107 | } 108 | Adder add = new Adder(); 109 | Func2 mul2 = new Func2() { 110 | @Override 111 | public Integer call(Integer t1, Integer t2) { 112 | return t1 * t2; 113 | } 114 | }; 115 | Func2 sub2 = new Func2() { 116 | @Override 117 | public Integer call(Integer t1, Integer t2) { 118 | return t1 - t2; 119 | } 120 | }; 121 | 122 | static final class ThrowFunc implements 123 | Func0, 124 | Func1, 125 | Func2, 126 | Func3, 127 | Func4, 128 | Func5, 129 | Func6, 130 | Func7, 131 | Func8, 132 | Func9, 133 | FuncN 134 | { 135 | @Override 136 | public R call() { 137 | throw new TestException("Forced failure"); 138 | } 139 | @Override 140 | public R call(Integer t1) { 141 | return call(); 142 | } 143 | @Override 144 | public R call(Object... args) { 145 | return call(); 146 | } 147 | @Override 148 | public R call(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, 149 | Integer t6, Integer t7, Integer t8, Integer t9) { 150 | return call(); 151 | } 152 | @Override 153 | public R call(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, 154 | Integer t6, Integer t7, Integer t8) { 155 | return call(); 156 | } 157 | @Override 158 | public R call(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, 159 | Integer t6, Integer t7) { 160 | return call(); 161 | } 162 | @Override 163 | public R call(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, 164 | Integer t6) { 165 | return call(); 166 | } 167 | @Override 168 | public R call(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5) { 169 | return call(); 170 | } 171 | @Override 172 | public R call(Integer t1, Integer t2, Integer t3, Integer t4) { 173 | return call(); 174 | } 175 | @Override 176 | public R call(Integer t1, Integer t2, Integer t3) { 177 | return call(); 178 | } 179 | @Override 180 | public R call(Integer t1, Integer t2) { 181 | return call(); 182 | } 183 | } 184 | ThrowFunc throwFunc = new ThrowFunc(); 185 | 186 | Observable some = Observable.just(1); 187 | 188 | Observable error = Observable.error(new TestException("Forced failure")); 189 | 190 | @Before 191 | public void before() { 192 | MockitoAnnotations.initMocks(this); 193 | } 194 | 195 | @Test(expected = NullPointerException.class) 196 | public void and2ArgumentNull() { 197 | JoinObservable.from(some).and(null); 198 | } 199 | 200 | @Test(expected = NullPointerException.class) 201 | public void and3argumentNull() { 202 | JoinObservable.from(some).and(some).and(null); 203 | } 204 | 205 | void verifyAnd(JoinObservable m, int count) { 206 | 207 | @SuppressWarnings("unchecked") 208 | Observer o = mock(Observer.class); 209 | 210 | m.toObservable().subscribe(o); 211 | 212 | verify(o, never()).onError(any(Throwable.class)); 213 | verify(o, times(1)).onNext(count); 214 | verify(o, times(1)).onCompleted(); 215 | } 216 | void verifyError(JoinObservable m) { 217 | @SuppressWarnings("unchecked") 218 | Observer o = mock(Observer.class); 219 | 220 | m.toObservable().subscribe(o); 221 | 222 | verify(o, times(1)).onError(any(TestException.class)); 223 | verify(o, never()).onNext(any(Integer.class)); 224 | verify(o, never()).onCompleted(); 225 | } 226 | 227 | @Test 228 | public void and2() { 229 | verifyAnd(JoinObservable.when(JoinObservable.from(some).and(some).then(add)), 2); 230 | } 231 | 232 | @Test 233 | public void and2Error1() { 234 | verifyError(JoinObservable.when(JoinObservable.from(error).and(some).then(add))); 235 | } 236 | 237 | @Test 238 | public void and2Error2() { 239 | verifyError(JoinObservable.when(JoinObservable.from(some).and(error).then(add))); 240 | } 241 | 242 | @Test 243 | public void and3() { 244 | verifyAnd(JoinObservable.when(JoinObservable.from(some).and(some).and(some).then(add)), 3); 245 | } 246 | 247 | @Test 248 | public void and3Error1() { 249 | verifyError(JoinObservable.when(JoinObservable.from(error).and(some).and(some).then(add))); 250 | } 251 | 252 | @Test 253 | public void and3Error2() { 254 | verifyError(JoinObservable.when(JoinObservable.from(some).and(error).and(some).then(add))); 255 | } 256 | 257 | @Test 258 | public void and3Error3() { 259 | verifyError(JoinObservable.when(JoinObservable.from(some).and(some).and(error).then(add))); 260 | } 261 | 262 | @Test(expected = NullPointerException.class) 263 | public void thenArgumentNull() { 264 | JoinObservable.from(some).then(null); 265 | } 266 | 267 | @Test(expected = NullPointerException.class) 268 | public void then2ArgumentNull() { 269 | JoinObservable.from(some).and(some).then(null); 270 | } 271 | 272 | @Test(expected = NullPointerException.class) 273 | public void then3ArgumentNull() { 274 | JoinObservable.from(some).and(some).and(some).then(null); 275 | } 276 | 277 | @Test(expected = NullPointerException.class) 278 | public void then4ArgumentNull() { 279 | JoinObservable.from(some).and(some).and(some).and(some).then(null); 280 | } 281 | 282 | @Test(expected = NullPointerException.class) 283 | public void then5ArgumentNull() { 284 | JoinObservable.from(some).and(some).and(some).and(some).and(some).then(null); 285 | } 286 | 287 | @Test(expected = NullPointerException.class) 288 | public void then6ArgumentNull() { 289 | JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).then(null); 290 | } 291 | 292 | @Test(expected = NullPointerException.class) 293 | public void then7ArgumentNull() { 294 | JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); 295 | } 296 | 297 | @Test(expected = NullPointerException.class) 298 | public void then8ArgumentNull() { 299 | JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); 300 | } 301 | 302 | @Test(expected = NullPointerException.class) 303 | public void then9ArgumentNull() { 304 | JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); 305 | } 306 | 307 | @Test 308 | public void thenNArgumentNull() { 309 | for (int n = 10; n < 100; n++) { 310 | PatternN p = JoinObservable.from(some).and(some) 311 | .and(some).and(some) 312 | .and(some).and(some) 313 | .and(some).and(some) 314 | .and(some).and(some); 315 | try { 316 | for (int j = 0; j < n - 10; j++) { 317 | p = p.and(some); 318 | } 319 | p.then(null); 320 | fail("Failed to throw exception with pattern length " + n); 321 | } catch (NullPointerException ex) { 322 | // expected, continue 323 | } 324 | } 325 | } 326 | 327 | @Test(expected = NullPointerException.class) 328 | public void then10ArgumentNull() { 329 | JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); 330 | } 331 | 332 | @Test 333 | public void then1() { 334 | verifyAnd(JoinObservable.when(JoinObservable.from(some).then(UtilityFunctions. identity())), 1); 335 | } 336 | 337 | @Test 338 | public void then1Error() { 339 | verifyError(JoinObservable.when(JoinObservable.from(error).then(UtilityFunctions. identity()))); 340 | } 341 | 342 | @Test 343 | public void then1Throws() { 344 | verifyError(JoinObservable.when(JoinObservable.from(some).then(throwFunc))); 345 | } 346 | 347 | @Test 348 | public void then2Throws() { 349 | verifyError(JoinObservable.when(JoinObservable.from(some).and(some).then(throwFunc))); 350 | } 351 | 352 | @Test 353 | public void then3Throws() { 354 | verifyError(JoinObservable.when(JoinObservable.from(some).and(some).and(some).then(throwFunc))); 355 | } 356 | 357 | @Test(expected = NullPointerException.class) 358 | public void whenArgumentNull1() { 359 | JoinObservable.when((Plan0[]) null); 360 | } 361 | 362 | @Test(expected = NullPointerException.class) 363 | public void whenArgumentNull2() { 364 | JoinObservable.when((Iterable>) null); 365 | } 366 | 367 | @Test 368 | public void whenMultipleSymmetric() { 369 | Observable source1 = Observable.just(1, 2, 3); 370 | Observable source2 = Observable.just(4, 5, 6); 371 | 372 | Observable m = JoinObservable.when(JoinObservable.from(source1).and(source2).then(add)).toObservable(); 373 | m.subscribe(observer); 374 | 375 | verify(observer, never()).onError(any(Throwable.class)); 376 | verify(observer, times(1)).onNext(1 + 4); 377 | verify(observer, times(1)).onNext(2 + 5); 378 | verify(observer, times(1)).onNext(3 + 6); 379 | verify(observer, times(1)).onCompleted(); 380 | } 381 | 382 | @Test 383 | public void whenMultipleAsymSymmetric() { 384 | Observable source1 = Observable.just(1, 2, 3); 385 | Observable source2 = Observable.just(4, 5); 386 | 387 | Observable m = JoinObservable.when(JoinObservable.from(source1).and(source2).then(add)).toObservable(); 388 | m.subscribe(observer); 389 | 390 | verify(observer, never()).onError(any(Throwable.class)); 391 | verify(observer, times(1)).onNext(1 + 4); 392 | verify(observer, times(1)).onNext(2 + 5); 393 | verify(observer, times(1)).onCompleted(); 394 | } 395 | 396 | @Test 397 | public void whenEmptyEmpty() { 398 | Observable source1 = Observable.empty(); 399 | Observable source2 = Observable.empty(); 400 | 401 | Observable m = JoinObservable.when(JoinObservable.from(source1).and(source2).then(add)).toObservable(); 402 | m.subscribe(observer); 403 | 404 | verify(observer, never()).onError(any(Throwable.class)); 405 | verify(observer, never()).onNext(any(Integer.class)); 406 | verify(observer, times(1)).onCompleted(); 407 | } 408 | 409 | @Test 410 | public void whenNeverNever() { 411 | Observable source1 = Observable.never(); 412 | Observable source2 = Observable.never(); 413 | 414 | Observable m = JoinObservable.when(JoinObservable.from(source1).and(source2).then(add)).toObservable(); 415 | m.subscribe(observer); 416 | 417 | verify(observer, never()).onError(any(Throwable.class)); 418 | verify(observer, never()).onNext(any(Integer.class)); 419 | verify(observer, never()).onCompleted(); 420 | } 421 | 422 | @Test 423 | public void whenThrowNonEmpty() { 424 | Observable source1 = Observable.empty(); 425 | Observable source2 = Observable.error(new TestException("Forced failure")); 426 | 427 | Observable m = JoinObservable.when(JoinObservable.from(source1).and(source2).then(add)).toObservable(); 428 | m.subscribe(observer); 429 | 430 | verify(observer, times(1)).onError(any(Throwable.class)); 431 | verify(observer, never()).onNext(any(Integer.class)); 432 | verify(observer, never()).onCompleted(); 433 | } 434 | 435 | @Test 436 | public void whenComplicated() { 437 | PublishSubject xs = PublishSubject.create(); 438 | PublishSubject ys = PublishSubject.create(); 439 | PublishSubject zs = PublishSubject.create(); 440 | 441 | Observable m = JoinObservable.when( 442 | JoinObservable.from(xs).and(ys).then(add), // 1+4=5, 2+5=7, 3+6=9 443 | JoinObservable.from(xs).and(zs).then(mul2), // 1*7=7, 2*8=16, 3*9=27 444 | JoinObservable.from(ys).and(zs).then(sub2) // 4-7=-3, 5-8=-3, 6-9=-3 445 | ).toObservable(); 446 | 447 | TestSubscriber to = new TestSubscriber(observer); 448 | m.subscribe(to); 449 | 450 | xs.onNext(1); // t == 210, xs[1], ys[], zs[] 451 | 452 | xs.onNext(2); // t == 220, xs[1, 2], ys[], zs[] 453 | zs.onNext(7); // t == 220, xs[1, 2], ys[], zs[7] triggers x and z; emit 1 * 7, remains xs[2], ys[], zs[] 454 | 455 | xs.onNext(3); // t == 230, xs[2,3], ys[], zs[] 456 | zs.onNext(8); // t == 230, xs[2,3], ys[], zs[8] triggers x and z, emit 2 * 8, remains xs[3], ys[], zs[] 457 | 458 | ys.onNext(4); // t == 240, xs[], ys[4], zs[] triggers x and y, emit 3 + 4, remains xs[], ys[], zs[] 459 | zs.onNext(9); // t == 240, xs[], ys[], zs[9] 460 | xs.onCompleted(); // t == 240, completed 1 461 | 462 | ys.onNext(5); // t == 250, xs[], ys[5], zs[9], triggers ys and zs, emits 5 - 9, remains xs[], ys[], zs[] 463 | 464 | ys.onNext(6); // t == 260, xs[], ys[6], zs[] 465 | 466 | ys.onCompleted(); // t == 270, completed 2 467 | 468 | zs.onCompleted(); // t == 300, completed 3, triggers when() oncompleted 469 | 470 | System.out.println("Events: " + to.getOnNextEvents()); 471 | 472 | to.assertReceivedOnNext(Arrays.asList(7, 16, 7, -4)); 473 | to.assertTerminalEvent(); 474 | 475 | InOrder inOrder = inOrder(observer); 476 | 477 | inOrder.verify(observer, times(1)).onNext(1 * 7); 478 | inOrder.verify(observer, times(1)).onNext(2 * 8); 479 | inOrder.verify(observer, times(1)).onNext(3 + 4); 480 | inOrder.verify(observer, times(1)).onNext(5 - 9); 481 | inOrder.verify(observer, times(1)).onCompleted(); 482 | verify(observer, never()).onError(any(Throwable.class)); 483 | } 484 | 485 | // ----------------- 486 | 487 | @Test 488 | public void and4() { 489 | verifyAnd(JoinObservable.when(JoinObservable.from(some) 490 | .and(some) 491 | .and(some) 492 | .and(some) 493 | .then(add)), 4); 494 | } 495 | 496 | @Test 497 | public void and4Error1() { 498 | verifyError(JoinObservable.when( 499 | JoinObservable.from(error) 500 | .and(some) 501 | .and(some) 502 | .and(some) 503 | .then(add))); 504 | } 505 | 506 | @Test 507 | public void and4Error2() { 508 | verifyError(JoinObservable.when( 509 | JoinObservable.from(some) 510 | .and(error) 511 | .and(some) 512 | .and(some) 513 | .then(add))); 514 | } 515 | 516 | @Test 517 | public void and4Error3() { 518 | verifyError(JoinObservable.when( 519 | JoinObservable.from(some) 520 | .and(some) 521 | .and(error) 522 | .and(some) 523 | .then(add))); 524 | } 525 | 526 | @Test 527 | public void and4Error4() { 528 | verifyError(JoinObservable.when( 529 | JoinObservable.from(some) 530 | .and(some) 531 | .and(some) 532 | .and(error) 533 | .then(add))); 534 | } 535 | 536 | @Test 537 | public void then4Throws() { 538 | verifyError(JoinObservable.when( 539 | JoinObservable 540 | .from(some) 541 | .and(some) 542 | .and(some) 543 | .and(some) 544 | .then(throwFunc))); 545 | } 546 | 547 | // ----------------- 548 | 549 | @Test 550 | public void and5() { 551 | verifyAnd(JoinObservable.when(JoinObservable.from(some) 552 | .and(some) 553 | .and(some) 554 | .and(some) 555 | .and(some) 556 | .then(add)), 5); 557 | } 558 | 559 | @Test 560 | public void and5Error1() { 561 | verifyError(JoinObservable.when( 562 | JoinObservable.from(error) 563 | .and(some) 564 | .and(some) 565 | .and(some) 566 | .and(some) 567 | .then(add))); 568 | } 569 | 570 | @Test 571 | public void and5Error2() { 572 | verifyError(JoinObservable.when( 573 | JoinObservable.from(some) 574 | .and(error) 575 | .and(some) 576 | .and(some) 577 | .and(some) 578 | .then(add))); 579 | } 580 | 581 | @Test 582 | public void and5Error3() { 583 | verifyError(JoinObservable.when( 584 | JoinObservable.from(some) 585 | .and(some) 586 | .and(error) 587 | .and(some) 588 | .and(some) 589 | .then(add))); 590 | } 591 | 592 | @Test 593 | public void and5Error4() { 594 | verifyError(JoinObservable.when( 595 | JoinObservable.from(some) 596 | .and(some) 597 | .and(some) 598 | .and(error) 599 | .and(some) 600 | .then(add))); 601 | } 602 | @Test 603 | public void and5Error5() { 604 | verifyError(JoinObservable.when( 605 | JoinObservable.from(some) 606 | .and(some) 607 | .and(some) 608 | .and(some) 609 | .and(error) 610 | .then(add))); 611 | } 612 | 613 | @Test 614 | public void then5Throws() { 615 | verifyError(JoinObservable.when( 616 | JoinObservable 617 | .from(some) 618 | .and(some) 619 | .and(some) 620 | .and(some) 621 | .and(some) 622 | .then(throwFunc))); 623 | } 624 | 625 | // ----------------- 626 | 627 | @Test 628 | public void and6() { 629 | verifyAnd(JoinObservable.when(JoinObservable.from(some) 630 | .and(some) 631 | .and(some) 632 | .and(some) 633 | .and(some) 634 | .and(some) 635 | .then(add)), 6); 636 | } 637 | 638 | @Test 639 | public void and6Error1() { 640 | verifyError(JoinObservable.when( 641 | JoinObservable.from(error) 642 | .and(some) 643 | .and(some) 644 | .and(some) 645 | .and(some) 646 | .and(some) 647 | .then(add))); 648 | } 649 | 650 | @Test 651 | public void and6Error2() { 652 | verifyError(JoinObservable.when( 653 | JoinObservable.from(some) 654 | .and(error) 655 | .and(some) 656 | .and(some) 657 | .and(some) 658 | .and(some) 659 | .then(add))); 660 | } 661 | 662 | @Test 663 | public void and6Error3() { 664 | verifyError(JoinObservable.when( 665 | JoinObservable.from(some) 666 | .and(some) 667 | .and(error) 668 | .and(some) 669 | .and(some) 670 | .and(some) 671 | .then(add))); 672 | } 673 | 674 | @Test 675 | public void and6Error4() { 676 | verifyError(JoinObservable.when( 677 | JoinObservable.from(some) 678 | .and(some) 679 | .and(some) 680 | .and(error) 681 | .and(some) 682 | .and(some) 683 | .then(add))); 684 | } 685 | @Test 686 | public void and6Error5() { 687 | verifyError(JoinObservable.when( 688 | JoinObservable.from(some) 689 | .and(some) 690 | .and(some) 691 | .and(some) 692 | .and(error) 693 | .and(some) 694 | .then(add))); 695 | } 696 | 697 | @Test 698 | public void and6Error6() { 699 | verifyError(JoinObservable.when( 700 | JoinObservable.from(some) 701 | .and(some) 702 | .and(some) 703 | .and(some) 704 | .and(some) 705 | .and(error) 706 | .then(add))); 707 | } 708 | 709 | @Test 710 | public void then6Throws() { 711 | verifyError(JoinObservable.when( 712 | JoinObservable 713 | .from(some) 714 | .and(some) 715 | .and(some) 716 | .and(some) 717 | .and(some) 718 | .and(some) 719 | .then(throwFunc))); 720 | } 721 | // ----------------- 722 | 723 | @Test 724 | public void and7() { 725 | verifyAnd(JoinObservable.when(JoinObservable.from(some) 726 | .and(some) 727 | .and(some) 728 | .and(some) 729 | .and(some) 730 | .and(some) 731 | .and(some) 732 | .then(add)), 7); 733 | } 734 | 735 | @Test 736 | public void and7Error1() { 737 | verifyError(JoinObservable.when( 738 | JoinObservable.from(error) 739 | .and(some) 740 | .and(some) 741 | .and(some) 742 | .and(some) 743 | .and(some) 744 | .and(some) 745 | .then(add))); 746 | } 747 | 748 | @Test 749 | public void and7Error2() { 750 | verifyError(JoinObservable.when( 751 | JoinObservable.from(some) 752 | .and(error) 753 | .and(some) 754 | .and(some) 755 | .and(some) 756 | .and(some) 757 | .and(some) 758 | .then(add))); 759 | } 760 | 761 | @Test 762 | public void and7Error3() { 763 | verifyError(JoinObservable.when( 764 | JoinObservable.from(some) 765 | .and(some) 766 | .and(error) 767 | .and(some) 768 | .and(some) 769 | .and(some) 770 | .and(some) 771 | .then(add))); 772 | } 773 | 774 | @Test 775 | public void and7Error4() { 776 | verifyError(JoinObservable.when( 777 | JoinObservable.from(some) 778 | .and(some) 779 | .and(some) 780 | .and(error) 781 | .and(some) 782 | .and(some) 783 | .and(some) 784 | .then(add))); 785 | } 786 | @Test 787 | public void and7Error5() { 788 | verifyError(JoinObservable.when( 789 | JoinObservable.from(some) 790 | .and(some) 791 | .and(some) 792 | .and(some) 793 | .and(error) 794 | .and(some) 795 | .and(some) 796 | .then(add))); 797 | } 798 | 799 | @Test 800 | public void and7Error6() { 801 | verifyError(JoinObservable.when( 802 | JoinObservable.from(some) 803 | .and(some) 804 | .and(some) 805 | .and(some) 806 | .and(some) 807 | .and(error) 808 | .and(some) 809 | .then(add))); 810 | } 811 | 812 | @Test 813 | public void and7Error7() { 814 | verifyError(JoinObservable.when( 815 | JoinObservable.from(some) 816 | .and(some) 817 | .and(some) 818 | .and(some) 819 | .and(some) 820 | .and(some) 821 | .and(error) 822 | .then(add))); 823 | } 824 | 825 | @Test 826 | public void then7Throws() { 827 | verifyError(JoinObservable.when( 828 | JoinObservable 829 | .from(some) 830 | .and(some) 831 | .and(some) 832 | .and(some) 833 | .and(some) 834 | .and(some) 835 | .and(some) 836 | .then(throwFunc))); 837 | } 838 | // ----------------- 839 | 840 | @Test 841 | public void and8() { 842 | verifyAnd(JoinObservable.when(JoinObservable.from(some) 843 | .and(some) 844 | .and(some) 845 | .and(some) 846 | .and(some) 847 | .and(some) 848 | .and(some) 849 | .and(some) 850 | .then(add)), 8); 851 | } 852 | 853 | @Test 854 | public void and8Error1() { 855 | verifyError(JoinObservable.when( 856 | JoinObservable.from(error) 857 | .and(some) 858 | .and(some) 859 | .and(some) 860 | .and(some) 861 | .and(some) 862 | .and(some) 863 | .and(some) 864 | .then(add))); 865 | } 866 | 867 | @Test 868 | public void and8Error2() { 869 | verifyError(JoinObservable.when( 870 | JoinObservable.from(some) 871 | .and(error) 872 | .and(some) 873 | .and(some) 874 | .and(some) 875 | .and(some) 876 | .and(some) 877 | .and(some) 878 | .then(add))); 879 | } 880 | 881 | @Test 882 | public void and8Error3() { 883 | verifyError(JoinObservable.when( 884 | JoinObservable.from(some) 885 | .and(some) 886 | .and(error) 887 | .and(some) 888 | .and(some) 889 | .and(some) 890 | .and(some) 891 | .and(some) 892 | .then(add))); 893 | } 894 | 895 | @Test 896 | public void and8Error4() { 897 | verifyError(JoinObservable.when( 898 | JoinObservable.from(some) 899 | .and(some) 900 | .and(some) 901 | .and(error) 902 | .and(some) 903 | .and(some) 904 | .and(some) 905 | .and(some) 906 | .then(add))); 907 | } 908 | @Test 909 | public void and8Error5() { 910 | verifyError(JoinObservable.when( 911 | JoinObservable.from(some) 912 | .and(some) 913 | .and(some) 914 | .and(some) 915 | .and(error) 916 | .and(some) 917 | .and(some) 918 | .and(some) 919 | .then(add))); 920 | } 921 | 922 | @Test 923 | public void and8Error6() { 924 | verifyError(JoinObservable.when( 925 | JoinObservable.from(some) 926 | .and(some) 927 | .and(some) 928 | .and(some) 929 | .and(some) 930 | .and(error) 931 | .and(some) 932 | .and(some) 933 | .then(add))); 934 | } 935 | 936 | @Test 937 | public void and8Error7() { 938 | verifyError(JoinObservable.when( 939 | JoinObservable.from(some) 940 | .and(some) 941 | .and(some) 942 | .and(some) 943 | .and(some) 944 | .and(some) 945 | .and(error) 946 | .and(some) 947 | .then(add))); 948 | } 949 | 950 | @Test 951 | public void and8Error8() { 952 | verifyError(JoinObservable.when( 953 | JoinObservable.from(some) 954 | .and(some) 955 | .and(some) 956 | .and(some) 957 | .and(some) 958 | .and(some) 959 | .and(some) 960 | .and(error) 961 | .then(add))); 962 | } 963 | 964 | @Test 965 | public void then8Throws() { 966 | verifyError(JoinObservable.when( 967 | JoinObservable 968 | .from(some) 969 | .and(some) 970 | .and(some) 971 | .and(some) 972 | .and(some) 973 | .and(some) 974 | .and(some) 975 | .and(some) 976 | .then(throwFunc))); 977 | } 978 | // ----------------- 979 | 980 | @Test 981 | public void and9() { 982 | verifyAnd(JoinObservable.when(JoinObservable.from(some) 983 | .and(some) 984 | .and(some) 985 | .and(some) 986 | .and(some) 987 | .and(some) 988 | .and(some) 989 | .and(some) 990 | .and(some) 991 | .then(add)), 9); 992 | } 993 | 994 | @Test 995 | public void and9Error1() { 996 | verifyError(JoinObservable.when( 997 | JoinObservable.from(error) 998 | .and(some) 999 | .and(some) 1000 | .and(some) 1001 | .and(some) 1002 | .and(some) 1003 | .and(some) 1004 | .and(some) 1005 | .and(some) 1006 | .then(add))); 1007 | } 1008 | 1009 | @Test 1010 | public void and9Error2() { 1011 | verifyError(JoinObservable.when( 1012 | JoinObservable.from(some) 1013 | .and(error) 1014 | .and(some) 1015 | .and(some) 1016 | .and(some) 1017 | .and(some) 1018 | .and(some) 1019 | .and(some) 1020 | .and(some) 1021 | .then(add))); 1022 | } 1023 | 1024 | @Test 1025 | public void and9Error3() { 1026 | verifyError(JoinObservable.when( 1027 | JoinObservable.from(some) 1028 | .and(some) 1029 | .and(error) 1030 | .and(some) 1031 | .and(some) 1032 | .and(some) 1033 | .and(some) 1034 | .and(some) 1035 | .and(some) 1036 | .then(add))); 1037 | } 1038 | 1039 | @Test 1040 | public void and9Error4() { 1041 | verifyError(JoinObservable.when( 1042 | JoinObservable.from(some) 1043 | .and(some) 1044 | .and(some) 1045 | .and(error) 1046 | .and(some) 1047 | .and(some) 1048 | .and(some) 1049 | .and(some) 1050 | .and(some) 1051 | .then(add))); 1052 | } 1053 | @Test 1054 | public void and9Error5() { 1055 | verifyError(JoinObservable.when( 1056 | JoinObservable.from(some) 1057 | .and(some) 1058 | .and(some) 1059 | .and(some) 1060 | .and(error) 1061 | .and(some) 1062 | .and(some) 1063 | .and(some) 1064 | .and(some) 1065 | .then(add))); 1066 | } 1067 | 1068 | @Test 1069 | public void and9Error6() { 1070 | verifyError(JoinObservable.when( 1071 | JoinObservable.from(some) 1072 | .and(some) 1073 | .and(some) 1074 | .and(some) 1075 | .and(some) 1076 | .and(error) 1077 | .and(some) 1078 | .and(some) 1079 | .and(some) 1080 | .then(add))); 1081 | } 1082 | 1083 | @Test 1084 | public void and9Error7() { 1085 | verifyError(JoinObservable.when( 1086 | JoinObservable.from(some) 1087 | .and(some) 1088 | .and(some) 1089 | .and(some) 1090 | .and(some) 1091 | .and(some) 1092 | .and(error) 1093 | .and(some) 1094 | .and(some) 1095 | .then(add))); 1096 | } 1097 | 1098 | @Test 1099 | public void and9Error8() { 1100 | verifyError(JoinObservable.when( 1101 | JoinObservable.from(some) 1102 | .and(some) 1103 | .and(some) 1104 | .and(some) 1105 | .and(some) 1106 | .and(some) 1107 | .and(some) 1108 | .and(error) 1109 | .and(some) 1110 | .then(add))); 1111 | } 1112 | @Test 1113 | public void and9Error9() { 1114 | verifyError(JoinObservable.when( 1115 | JoinObservable.from(some) 1116 | .and(some) 1117 | .and(some) 1118 | .and(some) 1119 | .and(some) 1120 | .and(some) 1121 | .and(some) 1122 | .and(some) 1123 | .and(error) 1124 | .then(add))); 1125 | } 1126 | 1127 | @Test 1128 | public void then9Throws() { 1129 | verifyError(JoinObservable.when( 1130 | JoinObservable 1131 | .from(some) 1132 | .and(some) 1133 | .and(some) 1134 | .and(some) 1135 | .and(some) 1136 | .and(some) 1137 | .and(some) 1138 | .and(some) 1139 | .and(some) 1140 | .then(throwFunc))); 1141 | } 1142 | // ----------------- 1143 | 1144 | @Test 1145 | public void andN() { 1146 | int s = 10; 1147 | for (int n = s; n < 100; n++) { 1148 | System.out.println("AndN(" + n + ")"); 1149 | PatternN p = JoinObservable.from(some) 1150 | .and(some) 1151 | .and(some) 1152 | .and(some) 1153 | .and(some) 1154 | .and(some) 1155 | .and(some) 1156 | .and(some) 1157 | .and(some) 1158 | .and(some); 1159 | 1160 | for (int j = 0; j < n - s; j++) { 1161 | p = p.and(some); 1162 | } 1163 | verifyAnd(JoinObservable.when(p.then(add)), n); 1164 | } 1165 | } 1166 | 1167 | @Test 1168 | public void andNError1() { 1169 | verifyError(JoinObservable.when( 1170 | JoinObservable.from(error) 1171 | .and(some) 1172 | .and(some) 1173 | .and(some) 1174 | .and(some) 1175 | .and(some) 1176 | .and(some) 1177 | .and(some) 1178 | .and(some) 1179 | .then(add))); 1180 | } 1181 | 1182 | @Test 1183 | public void andNError2() { 1184 | verifyError(JoinObservable.when( 1185 | JoinObservable.from(some) 1186 | .and(error) 1187 | .and(some) 1188 | .and(some) 1189 | .and(some) 1190 | .and(some) 1191 | .and(some) 1192 | .and(some) 1193 | .and(some) 1194 | .and(some) 1195 | .then(add))); 1196 | } 1197 | 1198 | @Test 1199 | public void andNError3() { 1200 | verifyError(JoinObservable.when( 1201 | JoinObservable.from(some) 1202 | .and(some) 1203 | .and(error) 1204 | .and(some) 1205 | .and(some) 1206 | .and(some) 1207 | .and(some) 1208 | .and(some) 1209 | .and(some) 1210 | .and(some) 1211 | .then(add))); 1212 | } 1213 | 1214 | @Test 1215 | public void andNError4() { 1216 | verifyError(JoinObservable.when( 1217 | JoinObservable.from(some) 1218 | .and(some) 1219 | .and(some) 1220 | .and(error) 1221 | .and(some) 1222 | .and(some) 1223 | .and(some) 1224 | .and(some) 1225 | .and(some) 1226 | .and(some) 1227 | .then(add))); 1228 | } 1229 | @Test 1230 | public void andNError5() { 1231 | verifyError(JoinObservable.when( 1232 | JoinObservable.from(some) 1233 | .and(some) 1234 | .and(some) 1235 | .and(some) 1236 | .and(error) 1237 | .and(some) 1238 | .and(some) 1239 | .and(some) 1240 | .and(some) 1241 | .and(some) 1242 | .then(add))); 1243 | } 1244 | 1245 | @Test 1246 | public void andNError6() { 1247 | verifyError(JoinObservable.when( 1248 | JoinObservable.from(some) 1249 | .and(some) 1250 | .and(some) 1251 | .and(some) 1252 | .and(some) 1253 | .and(error) 1254 | .and(some) 1255 | .and(some) 1256 | .and(some) 1257 | .and(some) 1258 | .then(add))); 1259 | } 1260 | 1261 | @Test 1262 | public void andNError7() { 1263 | verifyError(JoinObservable.when( 1264 | JoinObservable.from(some) 1265 | .and(some) 1266 | .and(some) 1267 | .and(some) 1268 | .and(some) 1269 | .and(some) 1270 | .and(error) 1271 | .and(some) 1272 | .and(some) 1273 | .and(some) 1274 | .then(add))); 1275 | } 1276 | 1277 | @Test 1278 | public void andNError8() { 1279 | verifyError(JoinObservable.when( 1280 | JoinObservable.from(some) 1281 | .and(some) 1282 | .and(some) 1283 | .and(some) 1284 | .and(some) 1285 | .and(some) 1286 | .and(some) 1287 | .and(error) 1288 | .and(some) 1289 | .and(some) 1290 | .then(add))); 1291 | } 1292 | 1293 | @Test 1294 | public void andNError9() { 1295 | verifyError(JoinObservable.when( 1296 | JoinObservable.from(some) 1297 | .and(some) 1298 | .and(some) 1299 | .and(some) 1300 | .and(some) 1301 | .and(some) 1302 | .and(some) 1303 | .and(some) 1304 | .and(error) 1305 | .and(some) 1306 | .then(add))); 1307 | } 1308 | 1309 | @Test 1310 | public void andNErrorN() { 1311 | verifyError(JoinObservable.when( 1312 | JoinObservable.from(some) 1313 | .and(some) 1314 | .and(some) 1315 | .and(some) 1316 | .and(some) 1317 | .and(some) 1318 | .and(some) 1319 | .and(some) 1320 | .and(some) 1321 | .and(error) 1322 | .then(add))); 1323 | } 1324 | 1325 | @Test 1326 | public void andNErrorNRange() { 1327 | for (int n = 10; n < 100; n++) { 1328 | PatternN p = JoinObservable.from(some) 1329 | .and(some) 1330 | .and(some) 1331 | .and(some) 1332 | .and(some) 1333 | .and(some) 1334 | .and(some) 1335 | .and(some) 1336 | .and(some) 1337 | .and(some); 1338 | 1339 | for (int j = 0; j < n - 10; j++) { 1340 | p = p.and(some); 1341 | } 1342 | p = p.and(error); 1343 | 1344 | verifyError(JoinObservable.when(p.then(add))); 1345 | } 1346 | } 1347 | 1348 | 1349 | @Test 1350 | public void thenNThrows() { 1351 | for (int n = 10; n < 100; n++) { 1352 | PatternN p = JoinObservable.from(some) 1353 | .and(some) 1354 | .and(some) 1355 | .and(some) 1356 | .and(some) 1357 | .and(some) 1358 | .and(some) 1359 | .and(some) 1360 | .and(some) 1361 | .and(some); 1362 | 1363 | for (int j = 0; j < n - 10; j++) { 1364 | p = p.and(some); 1365 | } 1366 | verifyError(JoinObservable.when(p.then(throwFunc))); 1367 | } 1368 | } 1369 | } 1370 | -------------------------------------------------------------------------------- /src/test/java/rx/joins/operators/TestException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package rx.joins.operators; 17 | 18 | /** 19 | * Custom exception for operator testing; makes sure an unwanted exception is 20 | * not mixed up with a wanted exception. 21 | */ 22 | public final class TestException extends RuntimeException { 23 | /** */ 24 | private static final long serialVersionUID = -1138830497957801910L; 25 | /** Create the test exception without any message. */ 26 | public TestException() { 27 | super(); 28 | } 29 | /** 30 | * Create the test exception with the provided message. 31 | * @param message the mesage to use 32 | */ 33 | public TestException(String message) { 34 | super(message); 35 | } 36 | } 37 | --------------------------------------------------------------------------------