Skip to content

Commit

Permalink
Merge pull request #5 from benjchristensen/language-adaptor-classes
Browse files Browse the repository at this point in the history
Support multiple class types for language adaptors
  • Loading branch information
jcacciatore committed Jan 15, 2013
2 parents b66c0d3 + 686fa1f commit d95439f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.rx.lang.clojure;

import static org.mockito.Mockito.*;

import java.util.Arrays;

import org.junit.Before;
Expand Down Expand Up @@ -82,8 +80,8 @@ public Object call(Object function, Object[] args) {
}

@Override
public Class<?> getFunctionClass() {
return IFn.class;
public Class<?>[] getFunctionClass() {
return new Class<?>[] { IFn.class };
}

public static class UnitTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* 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
*
*
* 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.
Expand Down Expand Up @@ -41,8 +41,8 @@ public Object call(Object function, Object[] args) {
return ((Closure<?>) function).call(args);
}

public Class<?> getFunctionClass() {
return Closure.class;
public Class<?>[] getFunctionClass() {
return new Class<?>[] { Closure.class };
}

public static class UnitTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* 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
*
*
* 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.
Expand Down Expand Up @@ -49,8 +49,8 @@ public Object call(Object function, Object[] args) {
}

@Override
public Class<?> getFunctionClass() {
return RubyProc.class;
public Class<?>[] getFunctionClass() {
return new Class<?>[] { RubyProc.class };
}

public static class UnitTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public interface FunctionLanguageAdaptor {
* The Class of the Function that this adaptor serves.
* <p>
* Example: groovy.lang.Closure
* <p>
* This should not return classes of java.* packages.
*
* @return Class
* @return Class[] of classes that this adaptor should be invoked for.
*/
public Class<?> getFunctionClass();
public Class<?>[] getFunctionClass();
}
17 changes: 11 additions & 6 deletions rxjava-core/src/main/java/org/rx/functions/Functions.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* 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
*
*
* 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.
Expand Down Expand Up @@ -56,8 +56,13 @@ private static void loadLanguageAdaptor(String name) {
}
}

public static void registerLanguageAdaptor(Class<?> functionClass, FunctionLanguageAdaptor adaptor) {
languageAdaptors.put(functionClass, adaptor);
public static void registerLanguageAdaptor(Class<?>[] functionClasses, FunctionLanguageAdaptor adaptor) {
for (Class<?> functionClass : functionClasses) {
if (functionClass.getPackage().getName().startsWith("java.")) {
throw new IllegalArgumentException("FunctionLanguageAdaptor implementations can not specify java.lang.* classes.");
}
languageAdaptors.put(functionClass, adaptor);
}
}

public static void removeLanguageAdaptor(Class<?> functionClass) {
Expand Down

0 comments on commit d95439f

Please sign in to comment.