forked from apache/calcite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix https://github.com/julianhyde/optiq/issues/141, "Downgrade to gua…
…va-11.0.2". This is necessary for Hadoop compatibility. Later versions of Guava can also be used.
- Loading branch information
1 parent
4530bc2
commit 24cd792
Showing
5 changed files
with
537 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
core/src/main/java/net/hydromatic/optiq/util/Compatible.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
// Licensed to Julian Hyde under one or more contributor license | ||
// agreements. See the NOTICE file distributed with this work for | ||
// additional information regarding copyright ownership. | ||
// | ||
// Julian Hyde licenses this file to you 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 net.hydromatic.optiq.util; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.collect.*; | ||
|
||
import java.lang.reflect.*; | ||
import java.util.*; | ||
|
||
/** Compatibility layer. | ||
* | ||
* <p>Allows to use advanced functionality if the latest JDK or Guava version | ||
* is present.</p> | ||
*/ | ||
public interface Compatible { | ||
Compatible INSTANCE = new Factory().create(); | ||
|
||
/** Same as Guava {@code Maps.asMap(set, function)}. */ | ||
<K, V> Map<K, V> asMap(Set<K> set, Function<? super K, V> function); | ||
|
||
/** Creates the implementation of Compatible suitable for the | ||
* current environment. */ | ||
class Factory { | ||
Compatible create() { | ||
return (Compatible) Proxy.newProxyInstance( | ||
Compatible.class.getClassLoader(), | ||
new Class<?>[] {Compatible.class}, | ||
new InvocationHandler() { | ||
public Object invoke(Object proxy, Method method, Object[] args) | ||
throws Throwable { | ||
if (method.getName().equals("asMap")) { | ||
// Use the Guava implementation Maps.asMap if it is available | ||
try { | ||
final Method guavaMethod = Maps.class.getMethod( | ||
method.getName(), method.getParameterTypes()); | ||
return guavaMethod.invoke(null, args); | ||
} catch (NoSuchMethodException e) { | ||
Set set = (Set) args[0]; | ||
Function function = (Function) args[1]; | ||
return CompatibleGuava11.asMap(set, function); | ||
} | ||
} | ||
return null; | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
// End Compatible.java |
Oops, something went wrong.