diff --git a/gradle/doclet-exclude.jar b/gradle/doclet-exclude.jar new file mode 100644 index 00000000000..4e4fd963804 Binary files /dev/null and b/gradle/doclet-exclude.jar differ diff --git a/gradle/javadocStyleSheet.css b/gradle/javadocStyleSheet.css new file mode 100644 index 00000000000..fdaada472e1 --- /dev/null +++ b/gradle/javadocStyleSheet.css @@ -0,0 +1,59 @@ +# originally from http://sensemaya.org/files/stylesheet.css and then modified +# http://sensemaya.org/maya/2009/07/10/making-javadoc-more-legible + +/* Javadoc style sheet */ + +/* Define colors, fonts and other style attributes here to override the defaults */ + +/* Page background color */ +body { background-color: #FFFFFF; color:#333; font-size: 100%; } + +body { font-size: 0.875em; line-height: 1.286em; font-family: "Helvetica", "Arial", sans-serif; } + +code { color: #777; line-height: 1.286em; font-family: "Consolas", "Lucida Console", "Droid Sans Mono", "Andale Mono", "Monaco", "Lucida Sans Typewriter"; } + +a { text-decoration: none; color: #16569A; /* also try #2E85ED, #0033FF, #6C93C6, #1D7BBE, #1D8DD2 */ } +a:hover { text-decoration: underline; } + + +table[border="1"] { border: 1px solid #ddd; } +table[border="1"] td, table[border="1"] th { border: 1px solid #ddd; } +table[cellpadding="3"] td { padding: 0.5em; } + +font[size="-1"] { font-size: 0.85em; line-height: 1.5em; } +font[size="-2"] { font-size: 0.8em; } +font[size="+2"] { font-size: 1.4em; line-height: 1.3em; padding: 0.4em 0; } + +/* Headings */ +h1 { font-size: 1.5em; line-height: 1.286em;} +h2.title { color: #c81f08; } + +/* Table colors */ +.TableHeadingColor { background: #ccc; color:#444; } /* Dark mauve */ +.TableSubHeadingColor { background: #ddd; color:#444; } /* Light mauve */ +.TableRowColor { background: #FFFFFF; color:#666; font-size: 0.95em; } /* White */ +.TableRowColor code { color:#000; } /* White */ + +/* Font used in left-hand frame lists */ +.FrameTitleFont { font-size: 100%; } +.FrameHeadingFont { font-size: 90%; } +.FrameItemFont { font-size: 0.9em; line-height: 1.3em; +} +/* Java Interfaces */ +.FrameItemFont a i { + font-style: normal; color: #16569A; +} +.FrameItemFont a:hover i { + text-decoration: underline; +} + + +/* Navigation bar fonts and colors */ +.NavBarCell1 { background-color:#E0E6DF; } /* Light mauve */ +.NavBarCell1Rev { background-color:#16569A; color:#FFFFFF} /* Dark Blue */ +.NavBarFont1 { } +.NavBarFont1Rev { color:#FFFFFF; } + +.NavBarCell2 { background-color:#FFFFFF; color:#000000} +.NavBarCell3 { background-color:#FFFFFF; color:#000000} + diff --git a/language-adaptors/rxjava-groovy/build.gradle b/language-adaptors/rxjava-groovy/build.gradle new file mode 100644 index 00000000000..8d2b2690478 --- /dev/null +++ b/language-adaptors/rxjava-groovy/build.gradle @@ -0,0 +1,7 @@ +apply plugin: 'java' +dependencies { + compile project(':rxjava-core') + compile 'org.codehaus.groovy:groovy:1.8.8' + provided 'junit:junit:4.10' + provided 'org.mockito:mockito-core:1.9.5' +} diff --git a/language-adaptors/rxjava-groovy/src/main/java/org/rx/lang/groovy/GroovyAdaptor.java b/language-adaptors/rxjava-groovy/src/main/java/org/rx/lang/groovy/GroovyAdaptor.java new file mode 100644 index 00000000000..d8a0b5f8710 --- /dev/null +++ b/language-adaptors/rxjava-groovy/src/main/java/org/rx/lang/groovy/GroovyAdaptor.java @@ -0,0 +1,260 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rx.lang.groovy; + +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.*; +import groovy.lang.Binding; +import groovy.lang.Closure; +import groovy.lang.GroovyClassLoader; + +import java.util.Arrays; + +import org.codehaus.groovy.runtime.InvokerHelper; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.rx.functions.FunctionLanguageAdaptor; +import org.rx.reactive.Notification; +import org.rx.reactive.Observable; +import org.rx.reactive.Observer; +import org.rx.reactive.Subscription; + +public class GroovyAdaptor implements FunctionLanguageAdaptor { + + @Override + public Object call(Object function, Object[] args) { + return ((Closure) function).call(args); + } + + public Class getFunctionClass() { + return Closure.class; + } + + public static class UnitTest { + + @Mock + ScriptAssertion assertion; + + @Mock + Observer w; + + @Before + public void before() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testCreateViaGroovy() { + runGroovyScript("o.create({it.onNext('hello');it.onCompleted();}).subscribe({ result -> a.received(result)});"); + verify(assertion, times(1)).received("hello"); + } + + @Test + public void testFilterViaGroovy() { + runGroovyScript("o.filter(o.toObservable(1, 2, 3), {it >= 2}).subscribe({ result -> a.received(result)});"); + verify(assertion, times(0)).received(1); + verify(assertion, times(1)).received(2); + verify(assertion, times(1)).received(3); + } + + @Test + public void testLast() { + String script = "mockApiCall.getObservable().last().subscribe({ result -> a.received(result)});"; + runGroovyScript(script); + verify(assertion, times(1)).received("hello_1"); + } + + @Test + public void testMap() { + String script = "mockApiCall.getObservable().map({v -> 'say' + v}).subscribe({ result -> a.received(result)});"; + runGroovyScript(script); + verify(assertion, times(1)).received("sayhello_1"); + } + + @Test + public void testMapViaGroovy() { + runGroovyScript("o.map(o.toObservable(1, 2, 3), {'hello_' + it}).subscribe({ result -> a.received(result)});"); + verify(assertion, times(1)).received("hello_" + 1); + verify(assertion, times(1)).received("hello_" + 2); + verify(assertion, times(1)).received("hello_" + 3); + } + + @Test + public void testMaterializeViaGroovy() { + runGroovyScript("o.materialize(o.toObservable(1, 2, 3)).subscribe({ result -> a.received(result)});"); + // we expect 4 onNext calls: 3 for 1, 2, 3 ObservableNotification.OnNext and 1 for ObservableNotification.OnCompleted + verify(assertion, times(4)).received(any(Notification.class)); + verify(assertion, times(0)).error(any(Exception.class)); + } + + @Test + public void testMergeDelayErrorViaGroovy() { + runGroovyScript("o.mergeDelayError(o.toObservable(1, 2, 3), o.merge(o.toObservable(6), o.error(new NullPointerException()), o.toObservable(7)), o.toObservable(4, 5)).subscribe({ result -> a.received(result)}, { exception -> a.error(exception)});"); + verify(assertion, times(1)).received(1); + verify(assertion, times(1)).received(2); + verify(assertion, times(1)).received(3); + verify(assertion, times(1)).received(4); + verify(assertion, times(1)).received(5); + verify(assertion, times(1)).received(6); + verify(assertion, times(0)).received(7); + verify(assertion, times(1)).error(any(NullPointerException.class)); + } + + @Test + public void testMergeViaGroovy() { + runGroovyScript("o.merge(o.toObservable(1, 2, 3), o.merge(o.toObservable(6), o.error(new NullPointerException()), o.toObservable(7)), o.toObservable(4, 5)).subscribe({ result -> a.received(result)}, { exception -> a.error(exception)});"); + // executing synchronously so we can deterministically know what order things will come + verify(assertion, times(1)).received(1); + verify(assertion, times(1)).received(2); + verify(assertion, times(1)).received(3); + verify(assertion, times(0)).received(4); // the NPE will cause this sequence to be skipped + verify(assertion, times(0)).received(5); // the NPE will cause this sequence to be skipped + verify(assertion, times(1)).received(6); // this comes before the NPE so should exist + verify(assertion, times(0)).received(7);// this comes in the sequence after the NPE + verify(assertion, times(1)).error(any(NullPointerException.class)); + } + + @Test + public void testScriptWithMaterialize() { + String script = "mockApiCall.getObservable().materialize().subscribe({ result -> a.received(result)});"; + runGroovyScript(script); + // 2 times: once for hello_1 and once for onCompleted + verify(assertion, times(2)).received(any(Notification.class)); + } + + @Test + public void testScriptWithMerge() { + String script = "o.merge(mockApiCall.getObservable(), mockApiCall.getObservable()).subscribe({ result -> a.received(result)});"; + runGroovyScript(script); + verify(assertion, times(1)).received("hello_1"); + verify(assertion, times(1)).received("hello_2"); + } + + @Test + public void testScriptWithOnNext() { + String script = "mockApiCall.getObservable().subscribe({ result -> a.received(result)})"; + runGroovyScript(script); + verify(assertion).received("hello_1"); + } + + @Test + public void testSkipTakeViaGroovy() { + runGroovyScript("o.skip(o.toObservable(1, 2, 3), 1).take(1).subscribe({ result -> a.received(result)});"); + verify(assertion, times(0)).received(1); + verify(assertion, times(1)).received(2); + verify(assertion, times(0)).received(3); + } + + @Test + public void testSkipViaGroovy() { + runGroovyScript("o.skip(o.toObservable(1, 2, 3), 2).subscribe({ result -> a.received(result)});"); + verify(assertion, times(0)).received(1); + verify(assertion, times(0)).received(2); + verify(assertion, times(1)).received(3); + } + + @Test + public void testTakeViaGroovy() { + runGroovyScript("o.take(o.toObservable(1, 2, 3), 2).subscribe({ result -> a.received(result)});"); + verify(assertion, times(1)).received(1); + verify(assertion, times(1)).received(2); + verify(assertion, times(0)).received(3); + } + + @Test + public void testToSortedList() { + runGroovyScript("mockApiCall.getNumbers().toSortedList().subscribe({ result -> a.received(result)});"); + verify(assertion, times(1)).received(Arrays.asList(1, 2, 3, 4, 5)); + } + + @Test + public void testToSortedListStatic() { + runGroovyScript("o.toSortedList(o.toObservable(1, 3, 2, 5, 4)).subscribe({ result -> a.received(result)});"); + verify(assertion, times(1)).received(Arrays.asList(1, 2, 3, 4, 5)); + } + + @Test + public void testToSortedListWithFunction() { + runGroovyScript("mockApiCall.getNumbers().toSortedList({a, b -> a - b}).subscribe({ result -> a.received(result)});"); + verify(assertion, times(1)).received(Arrays.asList(1, 2, 3, 4, 5)); + } + + @Test + public void testToSortedListWithFunctionStatic() { + runGroovyScript("o.toSortedList(o.toObservable(1, 3, 2, 5, 4), {a, b -> a - b}).subscribe({ result -> a.received(result)});"); + verify(assertion, times(1)).received(Arrays.asList(1, 2, 3, 4, 5)); + } + + private void runGroovyScript(String script) { + ClassLoader parent = getClass().getClassLoader(); + @SuppressWarnings("resource") + GroovyClassLoader loader = new GroovyClassLoader(parent); + + Binding binding = new Binding(); + binding.setVariable("mockApiCall", new TestFactory()); + binding.setVariable("a", assertion); + binding.setVariable("o", org.rx.reactive.Observable.class); + + /* parse the script and execute it */ + InvokerHelper.createScript(loader.parseClass(script), binding).run(); + } + + private static interface ScriptAssertion { + public void error(Exception o); + + public void received(Object o); + } + + private static class TestFactory { + int counter = 1; + + @SuppressWarnings("unused") + public Observable getNumbers() { + return Observable.toObservable(1, 3, 2, 5, 4); + } + + @SuppressWarnings("unused") + public TestObservable getObservable() { + return new TestObservable(counter++); + } + } + + private static class TestObservable extends Observable { + private final int count; + + public TestObservable(int count) { + this.count = count; + } + + public Subscription subscribe(Observer observer) { + + observer.onNext("hello_" + count); + observer.onCompleted(); + + return new Subscription() { + + public void unsubscribe() { + // unregister ... will never be called here since we are executing synchronously + } + + }; + } + } + } + +} diff --git a/language-adaptors/rxjava-jruby/build.gradle b/language-adaptors/rxjava-jruby/build.gradle new file mode 100644 index 00000000000..b170a5769a4 --- /dev/null +++ b/language-adaptors/rxjava-jruby/build.gradle @@ -0,0 +1,7 @@ +apply plugin: 'java' +dependencies { + compile project(':rxjava-core') + compile 'org.jruby:jruby:1.7.2' + provided 'junit:junit:4.10' + provided 'org.mockito:mockito-core:1.9.5' +} diff --git a/language-adaptors/rxjava-jruby/src/main/java/org/rx/lang/jruby/JRubyAdaptor.java b/language-adaptors/rxjava-jruby/src/main/java/org/rx/lang/jruby/JRubyAdaptor.java new file mode 100644 index 00000000000..8a9d53e6999 --- /dev/null +++ b/language-adaptors/rxjava-jruby/src/main/java/org/rx/lang/jruby/JRubyAdaptor.java @@ -0,0 +1,215 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rx.lang.jruby; + +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.*; + +import java.util.Arrays; + +import org.jruby.Ruby; +import org.jruby.RubyProc; +import org.jruby.embed.ScriptingContainer; +import org.jruby.javasupport.JavaEmbedUtils; +import org.jruby.runtime.builtin.IRubyObject; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.rx.functions.FunctionLanguageAdaptor; +import org.rx.reactive.Notification; +import org.rx.reactive.Observable; +import org.rx.reactive.Observer; +import org.rx.reactive.Subscription; + +public class JRubyAdaptor implements FunctionLanguageAdaptor { + + @Override + public Object call(Object function, Object[] args) { + RubyProc rubyProc = ((RubyProc) function); + Ruby ruby = rubyProc.getRuntime(); + IRubyObject rubyArgs[] = new IRubyObject[args.length]; + for (int i = 0; i < args.length; i++) { + rubyArgs[i] = JavaEmbedUtils.javaToRuby(ruby, args[i]); + } + return rubyProc.getBlock().call(ruby.getCurrentContext(), rubyArgs); + } + + @Override + public Class getFunctionClass() { + return RubyProc.class; + } + + public static class UnitTest { + + @Mock + ScriptAssertion assertion; + + @Mock + Observer w; + + @Before + public void before() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testCreateViaGroovy() { + runGroovyScript("Observable.create(lambda{|it| it.onNext('hello');it.onCompleted();}).subscribe(lambda{|result| a.received(result)});"); + verify(assertion, times(1)).received("hello"); + } + + @Test + public void testFilterViaGroovy() { + runGroovyScript("Observable.filter(Observable.toObservable(1, 2, 3), lambda{|it| it >= 2}).subscribe(lambda{|result| a.received(result)});"); + verify(assertion, times(0)).received(1L); + verify(assertion, times(1)).received(2L); + verify(assertion, times(1)).received(3L); + } + + @Test + public void testLast() { + String script = "mockApiCall.getObservable().last().subscribe(lambda{|result| a.received(result)})"; + runGroovyScript(script); + verify(assertion, times(1)).received("hello_1"); + } + + @Test + public void testMap() { + String script = "mockApiCall.getObservable().map(lambda{|v| 'say' + v}).subscribe(lambda{|result| a.received(result)});"; + runGroovyScript(script); + verify(assertion, times(1)).received("sayhello_1"); + } + + @Test + public void testMaterializeViaGroovy() { + runGroovyScript("Observable.materialize(Observable.toObservable(1, 2, 3)).subscribe(lambda{|result| a.received(result)});"); + // we expect 4 onNext calls: 3 for 1, 2, 3 ObservableNotification.OnNext and 1 for ObservableNotification.OnCompleted + verify(assertion, times(4)).received(any(Notification.class)); + verify(assertion, times(0)).error(any(Exception.class)); + } + + @Test + public void testScriptWithMaterialize() { + String script = "mockApiCall.getObservable().materialize().subscribe(lambda{|result| a.received(result)});"; + runGroovyScript(script); + // 2 times: once for hello_1 and once for onCompleted + verify(assertion, times(2)).received(any(Notification.class)); + } + + @Test + public void testScriptWithMerge() { + String script = "Observable.merge(mockApiCall.getObservable(), mockApiCall.getObservable()).subscribe(lambda{|result| a.received(result)});"; + runGroovyScript(script); + verify(assertion, times(1)).received("hello_1"); + verify(assertion, times(1)).received("hello_2"); + } + + @Test + public void testScriptWithOnNext() { + String script = "mockApiCall.getObservable().subscribe(lambda{|result| a.received(result)})"; + runGroovyScript(script); + verify(assertion).received("hello_1"); + } + + @Test + public void testSkipTakeViaGroovy() { + runGroovyScript("Observable.skip(Observable.toObservable(1, 2, 3), 1).take(1).subscribe(lambda{|result| a.received(result)});"); + verify(assertion, times(0)).received(1); + verify(assertion, times(1)).received(2L); + verify(assertion, times(0)).received(3); + } + + @Test + public void testSkipViaGroovy() { + runGroovyScript("Observable.skip(Observable.toObservable(1, 2, 3), 2).subscribe(lambda{|result| a.received(result)});"); + verify(assertion, times(0)).received(1); + verify(assertion, times(0)).received(2); + verify(assertion, times(1)).received(3L); + } + + @Test + public void testTakeViaGroovy() { + runGroovyScript("Observable.take(Observable.toObservable(1, 2, 3), 2).subscribe(lambda{|result| a.received(result)});"); + verify(assertion, times(1)).received(1L); + verify(assertion, times(1)).received(2L); + verify(assertion, times(0)).received(3); + } + + @Test + public void testToSortedList() { + runGroovyScript("mockApiCall.getNumbers().toSortedList().subscribe(lambda{|result| a.received(result)});"); + verify(assertion, times(1)).received(Arrays.asList(1, 2, 3, 4, 5)); + } + + private void runGroovyScript(String script) { + ScriptingContainer container = new ScriptingContainer(); + container.put("mockApiCall", new TestFactory()); + container.put("a", assertion); + + StringBuilder b = new StringBuilder(); + // force JRuby to always use subscribe(Object) + b.append("import org.rx.reactive.Observable").append("\n"); + b.append("class Observable").append("\n"); + b.append(" java_alias :subscribe, :subscribe, [java.lang.Object]").append("\n"); + b.append("end").append("\n"); + b.append(script); + + container.runScriptlet(b.toString()); + } + + private static interface ScriptAssertion { + public void error(Exception o); + + public void received(Object o); + } + + public static class TestFactory { + int counter = 1; + + public Observable getNumbers() { + return Observable.toObservable(1, 3, 2, 5, 4); + } + + public TestObservable getObservable() { + return new TestObservable(counter++); + } + } + + private static class TestObservable extends Observable { + private final int count; + + public TestObservable(int count) { + this.count = count; + } + + public Subscription subscribe(Observer observer) { + + observer.onNext("hello_" + count); + observer.onCompleted(); + + return new Subscription() { + + public void unsubscribe() { + // unregister ... will never be called here since we are executing synchronously + } + + }; + } + } + } + +} diff --git a/rxjava-core/build.gradle b/rxjava-core/build.gradle index 03d0e79e941..450faed0b8f 100644 --- a/rxjava-core/build.gradle +++ b/rxjava-core/build.gradle @@ -10,8 +10,6 @@ dependencies { compile 'com.google.code.findbugs:jsr305:2.0.0' provided 'junit:junit:4.10' provided 'org.mockito:mockito-core:1.9.5' - compile 'org.codehaus.groovy:groovy:1.8.8' - compile 'org.jruby:jruby:1.7.2' } eclipse { @@ -24,3 +22,16 @@ eclipse { } } +javadoc { + // we do not want the org.rx.operations package include + exclude '**/operations/**' + + options { + doclet = "org.benjchristensen.doclet.DocletExclude" + docletpath = [rootProject.file('./gradle/doclet-exclude.jar')] + stylesheetFile = rootProject.file('./gradle/javadocStyleSheet.css') + windowTitle = "RxJava Javadoc ${project.version}" + } + options.addStringOption('top').value = '

RxJava

' +} + diff --git a/rxjava-core/src/main/java/org/rx/functions/Func0.java b/rxjava-core/src/main/java/org/rx/functions/Func0.java index 224ccb1800c..c02326a138b 100644 --- a/rxjava-core/src/main/java/org/rx/functions/Func0.java +++ b/rxjava-core/src/main/java/org/rx/functions/Func0.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.functions; public interface Func0 { diff --git a/rxjava-core/src/main/java/org/rx/functions/Func1.java b/rxjava-core/src/main/java/org/rx/functions/Func1.java index 8bb6b158d19..76203e83c5d 100644 --- a/rxjava-core/src/main/java/org/rx/functions/Func1.java +++ b/rxjava-core/src/main/java/org/rx/functions/Func1.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.functions; public interface Func1 { diff --git a/rxjava-core/src/main/java/org/rx/functions/Func2.java b/rxjava-core/src/main/java/org/rx/functions/Func2.java index afb36490643..312dc983b8c 100644 --- a/rxjava-core/src/main/java/org/rx/functions/Func2.java +++ b/rxjava-core/src/main/java/org/rx/functions/Func2.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.functions; public interface Func2 { diff --git a/rxjava-core/src/main/java/org/rx/functions/Func3.java b/rxjava-core/src/main/java/org/rx/functions/Func3.java index a38a374eb79..9beeb07e75f 100644 --- a/rxjava-core/src/main/java/org/rx/functions/Func3.java +++ b/rxjava-core/src/main/java/org/rx/functions/Func3.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.functions; public interface Func3 { diff --git a/rxjava-core/src/main/java/org/rx/functions/Func4.java b/rxjava-core/src/main/java/org/rx/functions/Func4.java index 6ab1b11d1c9..c23848003dd 100644 --- a/rxjava-core/src/main/java/org/rx/functions/Func4.java +++ b/rxjava-core/src/main/java/org/rx/functions/Func4.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.functions; public interface Func4 { diff --git a/rxjava-core/src/main/java/org/rx/functions/Func5.java b/rxjava-core/src/main/java/org/rx/functions/Func5.java new file mode 100644 index 00000000000..1bc9857e761 --- /dev/null +++ b/rxjava-core/src/main/java/org/rx/functions/Func5.java @@ -0,0 +1,20 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rx.functions; + +public interface Func5 { + public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5); +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/org/rx/functions/Func6.java b/rxjava-core/src/main/java/org/rx/functions/Func6.java new file mode 100644 index 00000000000..7286728aac2 --- /dev/null +++ b/rxjava-core/src/main/java/org/rx/functions/Func6.java @@ -0,0 +1,20 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rx.functions; + +public interface Func6 { + public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6); +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/org/rx/functions/Func7.java b/rxjava-core/src/main/java/org/rx/functions/Func7.java new file mode 100644 index 00000000000..68a5a630106 --- /dev/null +++ b/rxjava-core/src/main/java/org/rx/functions/Func7.java @@ -0,0 +1,20 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rx.functions; + +public interface Func7 { + public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7); +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/org/rx/functions/Func8.java b/rxjava-core/src/main/java/org/rx/functions/Func8.java new file mode 100644 index 00000000000..fc5fd5ed932 --- /dev/null +++ b/rxjava-core/src/main/java/org/rx/functions/Func8.java @@ -0,0 +1,20 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rx.functions; + +public interface Func8 { + public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8); +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/org/rx/functions/Func9.java b/rxjava-core/src/main/java/org/rx/functions/Func9.java new file mode 100644 index 00000000000..933fbc53760 --- /dev/null +++ b/rxjava-core/src/main/java/org/rx/functions/Func9.java @@ -0,0 +1,20 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rx.functions; + +public interface Func9 { + public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9); +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/org/rx/functions/FuncN.java b/rxjava-core/src/main/java/org/rx/functions/FuncN.java index cdc0d16203a..cbbb3dd920c 100644 --- a/rxjava-core/src/main/java/org/rx/functions/FuncN.java +++ b/rxjava-core/src/main/java/org/rx/functions/FuncN.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.functions; public interface FuncN { diff --git a/rxjava-core/src/main/java/org/rx/functions/FunctionLanguageAdaptor.java b/rxjava-core/src/main/java/org/rx/functions/FunctionLanguageAdaptor.java new file mode 100644 index 00000000000..8ec16b390e4 --- /dev/null +++ b/rxjava-core/src/main/java/org/rx/functions/FunctionLanguageAdaptor.java @@ -0,0 +1,37 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rx.functions; + +public interface FunctionLanguageAdaptor { + + /** + * Invoke the function and return the results. + * + * @param function + * @param args + * @return Object results from function execution + */ + Object call(Object function, Object[] args); + + /** + * The Class of the Function that this adaptor serves. + *

+ * Example: groovy.lang.Closure + * + * @return Class + */ + public Class getFunctionClass(); +} diff --git a/rxjava-core/src/main/java/org/rx/functions/Functions.java b/rxjava-core/src/main/java/org/rx/functions/Functions.java index 8300981db92..8ad19497458 100644 --- a/rxjava-core/src/main/java/org/rx/functions/Functions.java +++ b/rxjava-core/src/main/java/org/rx/functions/Functions.java @@ -1,94 +1,156 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.functions; -import groovy.lang.Closure; +import java.util.Collection; +import java.util.concurrent.ConcurrentHashMap; -import org.jruby.Ruby; -import org.jruby.RubyProc; -import org.jruby.javasupport.JavaEmbedUtils; -import org.jruby.runtime.builtin.IRubyObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Allows execution of functions from multiple different languages. + *

+ * Language support is provided via implementations of {@link FunctionLanguageAdaptor}. + *

+ * This class will dynamically look for known language adaptors on the classpath at startup or new ones can be registered using {@link #registerLanguageAdaptor(Class, FunctionLanguageAdaptor)}. + */ public class Functions { private static final Logger logger = LoggerFactory.getLogger(Functions.class); + private final static ConcurrentHashMap, FunctionLanguageAdaptor> languageAdaptors = new ConcurrentHashMap, FunctionLanguageAdaptor>(); + + static { + /* optimistically look for supported languages if they are in the classpath */ + loadLanguageAdaptor("Groovy"); + loadLanguageAdaptor("JRuby"); + loadLanguageAdaptor("Clojure"); + loadLanguageAdaptor("Scala"); + // as new languages arise we can add them here but this does not prevent someone from using 'registerLanguageAdaptor' directly + } + + private static void loadLanguageAdaptor(String name) { + String className = "org.rx.lang." + name.toLowerCase() + "." + name + "Adaptor"; + try { + Class c = Class.forName(className); + FunctionLanguageAdaptor a = (FunctionLanguageAdaptor) c.newInstance(); + registerLanguageAdaptor(a.getFunctionClass(), a); + } catch (ClassNotFoundException e) { + logger.info("Could not found function language adaptor: " + name + " with path: " + className); + } catch (Exception e) { + logger.error("Failed trying to initialize function language adaptor: " + className, e); + } + } + + public static void registerLanguageAdaptor(Class functionClass, FunctionLanguageAdaptor adaptor) { + languageAdaptors.put(functionClass, adaptor); + } + + public static void removeLanguageAdaptor(Class functionClass) { + languageAdaptors.remove(functionClass); + } + + public static Collection getRegisteredLanguageAdaptors() { + return languageAdaptors.values(); + } + /** * Utility method for determining the type of closure/function and executing it. * - * @param closure + * @param function * @param args */ @SuppressWarnings("unchecked") - public static R execute(Object closure, Object... args) { + public static R execute(Object function, Object... args) { // if we have a tracer then log the start long startTime = -1; if (tracer != null && tracer.isTraceEnabled()) { try { startTime = System.nanoTime(); - tracer.traceStart(closure, args); + tracer.traceStart(function, args); } catch (Exception e) { logger.warn("Failed to trace log.", e); } } // perform controller logic to determine what type of function we received and execute it try { - if (closure == null) { - throw new RuntimeException("closure is null. Can't send arguments to null closure."); + if (function == null) { + throw new RuntimeException("function is null. Can't send arguments to null function."); } - if (closure instanceof Closure) { - /* handle Groovy */ - return (R) ((Closure) closure).call(args); - } else if (closure instanceof RubyProc) { - // handle JRuby - RubyProc rubyProc = ((RubyProc) closure); - Ruby ruby = rubyProc.getRuntime(); - IRubyObject rubyArgs[] = new IRubyObject[args.length]; - for (int i = 0; i < args.length; i++) { - rubyArgs[i] = JavaEmbedUtils.javaToRuby(ruby, args[i]); + + /* + * TODO the following code needs to be evaluated for performance + * + * The c.isInstance and keySet() functions may be areas of concern with as often as this will be executed + */ + + // check for language adaptor + for (@SuppressWarnings("rawtypes") + Class c : languageAdaptors.keySet()) { + if (c.isInstance(function)) { + // found the language adaptor so execute + return (R) languageAdaptors.get(c).call(function, args); } - return (R) rubyProc.getBlock().call(ruby.getCurrentContext(), rubyArgs); - } else if (closure instanceof Func0) { - Func0 f = (Func0) closure; + } + // no language adaptor found + + // check Func* classes + if (function instanceof Func0) { + Func0 f = (Func0) function; if (args.length != 0) { throw new RuntimeException("The closure was Func0 and expected no arguments, but we received: " + args.length); } return (R) f.call(); - } else if (closure instanceof Func1) { - Func1 f = (Func1) closure; + } else if (function instanceof Func1) { + Func1 f = (Func1) function; if (args.length != 1) { throw new RuntimeException("The closure was Func1 and expected 1 argument, but we received: " + args.length); } return f.call(args[0]); - } else if (closure instanceof Func2) { - Func2 f = (Func2) closure; + } else if (function instanceof Func2) { + Func2 f = (Func2) function; if (args.length != 2) { throw new RuntimeException("The closure was Func2 and expected 2 arguments, but we received: " + args.length); } return f.call(args[0], args[1]); - } else if (closure instanceof Func3) { - Func3 f = (Func3) closure; + } else if (function instanceof Func3) { + Func3 f = (Func3) function; if (args.length != 3) { throw new RuntimeException("The closure was Func3 and expected 3 arguments, but we received: " + args.length); } return (R) f.call(args[0], args[1], args[2]); - } else if (closure instanceof Func4) { - Func4 f = (Func4) closure; + } else if (function instanceof Func4) { + Func4 f = (Func4) function; if (args.length != 1) { throw new RuntimeException("The closure was Func4 and expected 4 arguments, but we received: " + args.length); } return f.call(args[0], args[1], args[2], args[3]); - } else if (closure instanceof FuncN) { - FuncN f = (FuncN) closure; + } else if (function instanceof FuncN) { + FuncN f = (FuncN) function; return f.call(args); - } else { - throw new RuntimeException("Unsupported closure type: " + closure.getClass().getSimpleName()); } + + // no support found + throw new RuntimeException("Unsupported closure type: " + function.getClass().getSimpleName()); } finally { // if we have a tracer then log the end if (tracer != null && tracer.isTraceEnabled()) { try { - tracer.traceEnd(startTime, System.nanoTime(), closure, args); + tracer.traceEnd(startTime, System.nanoTime(), function, args); } catch (Exception e) { logger.warn("Failed to trace log.", e); } @@ -199,4 +261,5 @@ public static interface FunctionTraceLogger { public static void registerTraceLogger(FunctionTraceLogger tracer) { Functions.tracer = tracer; } + } diff --git a/rxjava-core/src/main/java/org/rx/operations/AtomicObservableSubscription.java b/rxjava-core/src/main/java/org/rx/operations/AtomicObservableSubscription.java index 055d0025dd6..2e73d754daf 100644 --- a/rxjava-core/src/main/java/org/rx/operations/AtomicObservableSubscription.java +++ b/rxjava-core/src/main/java/org/rx/operations/AtomicObservableSubscription.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/rxjava-core/src/main/java/org/rx/operations/AtomicObserver.java b/rxjava-core/src/main/java/org/rx/operations/AtomicObserver.java index aafe260ae08..e8a8b9f3ea6 100644 --- a/rxjava-core/src/main/java/org/rx/operations/AtomicObserver.java +++ b/rxjava-core/src/main/java/org/rx/operations/AtomicObserver.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import javax.annotation.concurrent.ThreadSafe; diff --git a/rxjava-core/src/main/java/org/rx/operations/AtomicObserverMultiThreaded.java b/rxjava-core/src/main/java/org/rx/operations/AtomicObserverMultiThreaded.java index e267950b512..7d20ba14717 100644 --- a/rxjava-core/src/main/java/org/rx/operations/AtomicObserverMultiThreaded.java +++ b/rxjava-core/src/main/java/org/rx/operations/AtomicObserverMultiThreaded.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.junit.Assert.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/AtomicObserverSingleThreaded.java b/rxjava-core/src/main/java/org/rx/operations/AtomicObserverSingleThreaded.java index 74bed86347d..ca139e658d7 100644 --- a/rxjava-core/src/main/java/org/rx/operations/AtomicObserverSingleThreaded.java +++ b/rxjava-core/src/main/java/org/rx/operations/AtomicObserverSingleThreaded.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.junit.Assert.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationCombineLatest.java b/rxjava-core/src/main/java/org/rx/operations/OperationCombineLatest.java index dc601e95689..ccba74236dd 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationCombineLatest.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationCombineLatest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationFilter.java b/rxjava-core/src/main/java/org/rx/operations/OperationFilter.java index 5421a0a0d43..a55624aadb9 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationFilter.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationFilter.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationLast.java b/rxjava-core/src/main/java/org/rx/operations/OperationLast.java index b412c1d76ed..fee302c88e3 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationLast.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationLast.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationMap.java b/rxjava-core/src/main/java/org/rx/operations/OperationMap.java index 18b17ac762e..896e87c3c9c 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationMap.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationMap.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationMaterialize.java b/rxjava-core/src/main/java/org/rx/operations/OperationMaterialize.java index 0964829bf70..0254a0a29a2 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationMaterialize.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationMaterialize.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.junit.Assert.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationMerge.java b/rxjava-core/src/main/java/org/rx/operations/OperationMerge.java index acd3106df64..291f5a4a36b 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationMerge.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationMerge.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.junit.Assert.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationMergeDelayError.java b/rxjava-core/src/main/java/org/rx/operations/OperationMergeDelayError.java index da9c145aea5..8ddd3bff465 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationMergeDelayError.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationMergeDelayError.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.junit.Assert.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorResumeNextViaFunction.java b/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorResumeNextViaFunction.java index 82fff9ca2dc..deeae454353 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorResumeNextViaFunction.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorResumeNextViaFunction.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.junit.Assert.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorResumeNextViaObservable.java b/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorResumeNextViaObservable.java index 9311d5381d5..df7f8de7f21 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorResumeNextViaObservable.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorResumeNextViaObservable.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.junit.Assert.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorReturn.java b/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorReturn.java index 6ab27e6aa18..06be1f61eb7 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorReturn.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationOnErrorReturn.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.junit.Assert.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationScan.java b/rxjava-core/src/main/java/org/rx/operations/OperationScan.java index 2fc34b6dc3c..8bf76140b28 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationScan.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationScan.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationSkip.java b/rxjava-core/src/main/java/org/rx/operations/OperationSkip.java index 45394989fae..c7738efb0cd 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationSkip.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationSkip.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationSynchronize.java b/rxjava-core/src/main/java/org/rx/operations/OperationSynchronize.java index a96d02ddbc6..a2d73db4699 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationSynchronize.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationSynchronize.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationTake.java b/rxjava-core/src/main/java/org/rx/operations/OperationTake.java index 13aed147ad2..1bd404115d4 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationTake.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationTake.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.junit.Assert.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationToObservableFunction.java b/rxjava-core/src/main/java/org/rx/operations/OperationToObservableFunction.java index cfa2501caaf..33f4048e4f5 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationToObservableFunction.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationToObservableFunction.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationToObservableIterable.java b/rxjava-core/src/main/java/org/rx/operations/OperationToObservableIterable.java index a462b5ee954..1338b59a4fb 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationToObservableIterable.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationToObservableIterable.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationToObservableList.java b/rxjava-core/src/main/java/org/rx/operations/OperationToObservableList.java index e8ac558d92e..14977f04a86 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationToObservableList.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationToObservableList.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationToObservableSortedList.java b/rxjava-core/src/main/java/org/rx/operations/OperationToObservableSortedList.java index 29e5f4ed67b..f6afd9bf7e6 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationToObservableSortedList.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationToObservableSortedList.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/OperationZip.java b/rxjava-core/src/main/java/org/rx/operations/OperationZip.java index f453ba9abd7..f7b4efdee70 100644 --- a/rxjava-core/src/main/java/org/rx/operations/OperationZip.java +++ b/rxjava-core/src/main/java/org/rx/operations/OperationZip.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.operations; import static org.mockito.Matchers.*; diff --git a/rxjava-core/src/main/java/org/rx/operations/package.html b/rxjava-core/src/main/java/org/rx/operations/package.html index fbb0cfa3bec..80ba7542bf3 100644 --- a/rxjava-core/src/main/java/org/rx/operations/package.html +++ b/rxjava-core/src/main/java/org/rx/operations/package.html @@ -1,3 +1,20 @@ +

Operators that allow composing Observables to transform and manipulate data in an asynchronous, functional and thread-safe manner.

diff --git a/rxjava-core/src/main/java/org/rx/reactive/CompositeException.java b/rxjava-core/src/main/java/org/rx/reactive/CompositeException.java index 23113e26b6a..ab07c7df79d 100644 --- a/rxjava-core/src/main/java/org/rx/reactive/CompositeException.java +++ b/rxjava-core/src/main/java/org/rx/reactive/CompositeException.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.reactive; import java.util.ArrayList; diff --git a/rxjava-core/src/main/java/org/rx/reactive/Notification.java b/rxjava-core/src/main/java/org/rx/reactive/Notification.java index 9840f230eb9..397fe0ce11a 100644 --- a/rxjava-core/src/main/java/org/rx/reactive/Notification.java +++ b/rxjava-core/src/main/java/org/rx/reactive/Notification.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.reactive; /** diff --git a/rxjava-core/src/main/java/org/rx/reactive/Observable.java b/rxjava-core/src/main/java/org/rx/reactive/Observable.java index dc36981e290..ba40e517516 100644 --- a/rxjava-core/src/main/java/org/rx/reactive/Observable.java +++ b/rxjava-core/src/main/java/org/rx/reactive/Observable.java @@ -1,16 +1,28 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.reactive; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; -import groovy.lang.Binding; -import groovy.lang.GroovyClassLoader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; -import org.codehaus.groovy.runtime.InvokerHelper; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -2087,50 +2099,6 @@ public Observable> toSortedList(final Object sortFunction) { } public static class UnitTest { - private static interface ScriptAssertion { - public void error(Exception o); - - public void received(Object o); - } - - private static class TestFactory { - int counter = 1; - - @SuppressWarnings("unused") - public Observable getNumbers() { - return toObservable(1, 3, 2, 5, 4); - } - - @SuppressWarnings("unused") - public TestObservable getObservable() { - return new TestObservable(counter++); - } - } - - private static class TestObservable extends Observable { - private final int count; - - public TestObservable(int count) { - this.count = count; - } - - public Subscription subscribe(Observer observer) { - - observer.onNext("hello_" + count); - observer.onCompleted(); - - return new Subscription() { - - public void unsubscribe() { - // unregister ... will never be called here since we are executing synchronously - } - - }; - } - } - - @Mock - ScriptAssertion assertion; @Mock Observer w; @@ -2140,91 +2108,6 @@ public void before() { MockitoAnnotations.initMocks(this); } - private void runGroovyScript(String script) { - ClassLoader parent = getClass().getClassLoader(); - @SuppressWarnings("resource") - GroovyClassLoader loader = new GroovyClassLoader(parent); - - Binding binding = new Binding(); - binding.setVariable("mockApiCall", new TestFactory()); - binding.setVariable("a", assertion); - binding.setVariable("o", org.rx.reactive.Observable.class); - - /* parse the script and execute it */ - InvokerHelper.createScript(loader.parseClass(script), binding).run(); - } - - @Test - public void testCreateViaGroovy() { - runGroovyScript("o.create({it.onNext('hello');it.onCompleted();}).subscribe({ result -> a.received(result)});"); - verify(assertion, times(1)).received("hello"); - } - - @Test - public void testFilterViaGroovy() { - runGroovyScript("o.filter(o.toObservable(1, 2, 3), {it >= 2}).subscribe({ result -> a.received(result)});"); - verify(assertion, times(0)).received(1); - verify(assertion, times(1)).received(2); - verify(assertion, times(1)).received(3); - } - - @Test - public void testLast() { - String script = "mockApiCall.getObservable().last().subscribe({ result -> a.received(result)});"; - runGroovyScript(script); - verify(assertion, times(1)).received("hello_1"); - } - - @Test - public void testMap() { - String script = "mockApiCall.getObservable().map({v -> 'say' + v}).subscribe({ result -> a.received(result)});"; - runGroovyScript(script); - verify(assertion, times(1)).received("sayhello_1"); - } - - @Test - public void testMapViaGroovy() { - runGroovyScript("o.map(o.toObservable(1, 2, 3), {'hello_' + it}).subscribe({ result -> a.received(result)});"); - verify(assertion, times(1)).received("hello_" + 1); - verify(assertion, times(1)).received("hello_" + 2); - verify(assertion, times(1)).received("hello_" + 3); - } - - @Test - public void testMaterializeViaGroovy() { - runGroovyScript("o.materialize(o.toObservable(1, 2, 3)).subscribe({ result -> a.received(result)});"); - // we expect 4 onNext calls: 3 for 1, 2, 3 ObservableNotification.OnNext and 1 for ObservableNotification.OnCompleted - verify(assertion, times(4)).received(any(Notification.class)); - verify(assertion, times(0)).error(any(Exception.class)); - } - - @Test - public void testMergeDelayErrorViaGroovy() { - runGroovyScript("o.mergeDelayError(o.toObservable(1, 2, 3), o.merge(o.toObservable(6), o.error(new NullPointerException()), o.toObservable(7)), o.toObservable(4, 5)).subscribe({ result -> a.received(result)}, { exception -> a.error(exception)});"); - verify(assertion, times(1)).received(1); - verify(assertion, times(1)).received(2); - verify(assertion, times(1)).received(3); - verify(assertion, times(1)).received(4); - verify(assertion, times(1)).received(5); - verify(assertion, times(1)).received(6); - verify(assertion, times(0)).received(7); - verify(assertion, times(1)).error(any(NullPointerException.class)); - } - - @Test - public void testMergeViaGroovy() { - runGroovyScript("o.merge(o.toObservable(1, 2, 3), o.merge(o.toObservable(6), o.error(new NullPointerException()), o.toObservable(7)), o.toObservable(4, 5)).subscribe({ result -> a.received(result)}, { exception -> a.error(exception)});"); - // executing synchronously so we can deterministically know what order things will come - verify(assertion, times(1)).received(1); - verify(assertion, times(1)).received(2); - verify(assertion, times(1)).received(3); - verify(assertion, times(0)).received(4); // the NPE will cause this sequence to be skipped - verify(assertion, times(0)).received(5); // the NPE will cause this sequence to be skipped - verify(assertion, times(1)).received(6); // this comes before the NPE so should exist - verify(assertion, times(0)).received(7);// this comes in the sequence after the NPE - verify(assertion, times(1)).error(any(NullPointerException.class)); - } - @Test public void testReduce() { Observable Observable = toObservable(1, 2, 3, 4); @@ -2257,75 +2140,5 @@ public Integer call(Integer t1, Integer t2) { verify(w).onNext(60); } - @Test - public void testScriptWithMaterialize() { - String script = "mockApiCall.getObservable().materialize().subscribe({ result -> a.received(result)});"; - runGroovyScript(script); - // 2 times: once for hello_1 and once for onCompleted - verify(assertion, times(2)).received(any(Notification.class)); - } - - @Test - public void testScriptWithMerge() { - String script = "o.merge(mockApiCall.getObservable(), mockApiCall.getObservable()).subscribe({ result -> a.received(result)});"; - runGroovyScript(script); - verify(assertion, times(1)).received("hello_1"); - verify(assertion, times(1)).received("hello_2"); - } - - @Test - public void testScriptWithOnNext() { - String script = "mockApiCall.getObservable().subscribe({ result -> a.received(result)})"; - runGroovyScript(script); - verify(assertion).received("hello_1"); - } - - @Test - public void testSkipTakeViaGroovy() { - runGroovyScript("o.skip(o.toObservable(1, 2, 3), 1).take(1).subscribe({ result -> a.received(result)});"); - verify(assertion, times(0)).received(1); - verify(assertion, times(1)).received(2); - verify(assertion, times(0)).received(3); - } - - @Test - public void testSkipViaGroovy() { - runGroovyScript("o.skip(o.toObservable(1, 2, 3), 2).subscribe({ result -> a.received(result)});"); - verify(assertion, times(0)).received(1); - verify(assertion, times(0)).received(2); - verify(assertion, times(1)).received(3); - } - - @Test - public void testTakeViaGroovy() { - runGroovyScript("o.take(o.toObservable(1, 2, 3), 2).subscribe({ result -> a.received(result)});"); - verify(assertion, times(1)).received(1); - verify(assertion, times(1)).received(2); - verify(assertion, times(0)).received(3); - } - - @Test - public void testToSortedList() { - runGroovyScript("mockApiCall.getNumbers().toSortedList().subscribe({ result -> a.received(result)});"); - verify(assertion, times(1)).received(Arrays.asList(1, 2, 3, 4, 5)); - } - - @Test - public void testToSortedListStatic() { - runGroovyScript("o.toSortedList(o.toObservable(1, 3, 2, 5, 4)).subscribe({ result -> a.received(result)});"); - verify(assertion, times(1)).received(Arrays.asList(1, 2, 3, 4, 5)); - } - - @Test - public void testToSortedListWithFunction() { - runGroovyScript("mockApiCall.getNumbers().toSortedList({a, b -> a - b}).subscribe({ result -> a.received(result)});"); - verify(assertion, times(1)).received(Arrays.asList(1, 2, 3, 4, 5)); - } - - @Test - public void testToSortedListWithFunctionStatic() { - runGroovyScript("o.toSortedList(o.toObservable(1, 3, 2, 5, 4), {a, b -> a - b}).subscribe({ result -> a.received(result)});"); - verify(assertion, times(1)).received(Arrays.asList(1, 2, 3, 4, 5)); - } } } diff --git a/rxjava-core/src/main/java/org/rx/reactive/Observer.java b/rxjava-core/src/main/java/org/rx/reactive/Observer.java index eca51c7e715..3d14d88a1f8 100644 --- a/rxjava-core/src/main/java/org/rx/reactive/Observer.java +++ b/rxjava-core/src/main/java/org/rx/reactive/Observer.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.reactive; /** diff --git a/rxjava-core/src/main/java/org/rx/reactive/Subscription.java b/rxjava-core/src/main/java/org/rx/reactive/Subscription.java index 659e34396c7..315d6e1f940 100644 --- a/rxjava-core/src/main/java/org/rx/reactive/Subscription.java +++ b/rxjava-core/src/main/java/org/rx/reactive/Subscription.java @@ -1,3 +1,18 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.rx.reactive; public interface Subscription { diff --git a/rxjava-core/src/main/java/org/rx/reactive/package.html b/rxjava-core/src/main/java/org/rx/reactive/package.html index dd99e9f8ddb..f94b00cba8d 100644 --- a/rxjava-core/src/main/java/org/rx/reactive/package.html +++ b/rxjava-core/src/main/java/org/rx/reactive/package.html @@ -1,3 +1,20 @@ +

A library that enables subscribing to and composing asynchronous events and callbacks.

diff --git a/settings.gradle b/settings.gradle index 106c9c9d1d3..1690640a76e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,4 @@ rootProject.name='rxjava' -include 'rxjava-core' +include 'rxjava-core', \ +'language-adaptors:rxjava-groovy', \ +'language-adaptors:rxjava-jruby'