-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #809 from serso/my-android
Pull request for #769
- Loading branch information
Showing
59 changed files
with
319 additions
and
97 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
description 'Android compatibility module' | ||
|
||
dependencies { | ||
} | ||
|
||
useReducedJdk(project) |
Binary file not shown.
Binary file not shown.
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,13 @@ | ||
package java.lang; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* This class won't be loaded at runtime as it "overrides" a bootstrap class from JDK. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD}) | ||
public @interface SafeVarargs {} |
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,9 @@ | ||
package org.web3j.compat; | ||
|
||
/** | ||
* Ports {@link java.util.function.BiFunction}. | ||
*/ | ||
public interface BiFunction<T, U, R> { | ||
|
||
R apply(T t, U u); | ||
} |
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,91 @@ | ||
package org.web3j.compat; | ||
|
||
import java.lang.reflect.Type; | ||
import java.math.BigInteger; | ||
import java.nio.charset.Charset; | ||
|
||
/** | ||
* Provides compatibility methods to substitute those methods from Java SDK that | ||
* are not supported on Android. | ||
*/ | ||
public final class Compat { | ||
|
||
/** | ||
* Ports {@link java.nio.charset.StandardCharsets#UTF_8}. | ||
*/ | ||
public static final Charset UTF_8 = Charset.forName("UTF-8"); | ||
|
||
private static final BigInteger LONG_MAX = BigInteger.valueOf(Long.MAX_VALUE); | ||
private static final BigInteger LONG_MIN = BigInteger.valueOf(Long.MIN_VALUE); | ||
|
||
private Compat() { | ||
} | ||
|
||
/** | ||
* Ports {@link String#join(CharSequence, CharSequence...)}. | ||
*/ | ||
public static String join(CharSequence delimiter, CharSequence... elements) { | ||
if (elements.length == 0) { | ||
return ""; | ||
} | ||
final StringBuilder sb = new StringBuilder(7 * elements.length); | ||
sb.append(elements[0]); | ||
for (int i = 1; i < elements.length; i++) { | ||
sb.append(delimiter); | ||
sb.append(elements[i]); | ||
|
||
} | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* Ports {@link BigInteger#longValueExact()}. | ||
*/ | ||
public static long longValueExact(BigInteger value) { | ||
if (value.compareTo(LONG_MIN) >= 0 && value.compareTo(LONG_MAX) <= 0) { | ||
return value.longValue(); | ||
} | ||
throw new ArithmeticException("BigInteger out of long range"); | ||
} | ||
|
||
/** | ||
* Ports {@link Type#getTypeName()}. | ||
*/ | ||
public static String getTypeName(Type type) { | ||
if (type instanceof Class) { | ||
return getClassName((Class)type); | ||
} | ||
return type.toString(); | ||
|
||
} | ||
|
||
/** | ||
* Copied from {@link Class#getTypeName()}. | ||
*/ | ||
private static String getClassName(Class type) { | ||
if (type.isArray()) { | ||
try { | ||
Class<?> cl = type; | ||
int dimensions = 0; | ||
while (cl.isArray()) { | ||
dimensions++; | ||
cl = cl.getComponentType(); | ||
} | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(cl.getName()); | ||
for (int i = 0; i < dimensions; i++) { | ||
sb.append("[]"); | ||
} | ||
return sb.toString(); | ||
} catch (Throwable e) { /*FALLTHRU*/ } | ||
} | ||
return type.getName(); | ||
} | ||
|
||
/** | ||
* Ports {@link Boolean#hashCode(boolean)}. | ||
*/ | ||
public static int hashCode(boolean value) { | ||
return value ? 1231 : 1237; | ||
} | ||
} |
Oops, something went wrong.