From 28e5984789165ec42b6b0b473ca231e4fed776ab Mon Sep 17 00:00:00 2001 From: Nandakumar Vadivelu Date: Fri, 29 Dec 2023 01:29:13 +0530 Subject: [PATCH] [Java] Reduce guava TypeToken dependency --- .../fury/builder/BaseObjectCodecBuilder.java | 2 +- .../org/apache/fury/builder/CodecBuilder.java | 2 +- .../org/apache/fury/builder/CodecUtils.java | 2 +- .../fury/builder/CompatibleCodecBuilder.java | 2 +- .../fury/builder/MetaSharedCodecBuilder.java | 2 +- .../fury/builder/ObjectCodecBuilder.java | 2 +- .../apache/fury/codegen/CodegenContext.java | 2 +- .../org/apache/fury/codegen/Expression.java | 2 +- .../apache/fury/codegen/ExpressionUtils.java | 2 +- .../fury/codegen/ExpressionVisitor.java | 2 +- .../org/apache/fury/reflect/Primitives.java | 135 +++++++ .../org/apache/fury/reflect/TypeToken.java | 335 ++++++++++++++++++ .../apache/fury/resolver/ClassResolver.java | 2 +- .../apache/fury/resolver/FieldResolver.java | 2 +- .../fury/serializer/ObjectSerializer.java | 2 +- .../fury/serializer/StructSerializer.java | 2 +- .../collection/AbstractMapSerializer.java | 2 +- .../java/org/apache/fury/type/ClassDef.java | 2 +- .../java/org/apache/fury/type/Descriptor.java | 2 +- .../org/apache/fury/type/GenericType.java | 2 +- .../java/org/apache/fury/type/ScalaTypes.java | 2 +- .../java/org/apache/fury/type/TypeUtils.java | 2 +- .../org/apache/fury/util/ReflectionUtils.java | 2 +- .../java/org/apache/fury/FuryInitPerf.java | 2 +- .../fury/codegen/CodegenContextTest.java | 2 +- .../fury/codegen/ExpressionVisitorTest.java | 2 +- .../collection/CollectionSerializersTest.java | 2 +- .../collection/MapSerializersTest.java | 2 +- .../fury/type/DescriptorGrouperTest.java | 2 +- .../org/apache/fury/type/DescriptorTest.java | 6 +- .../org/apache/fury/type/TypeUtilsTest.java | 2 +- .../fury/format/encoder/ArrayDataForEach.java | 2 +- .../format/encoder/ArrayEncoderBuilder.java | 2 +- .../encoder/BaseBinaryEncoderBuilder.java | 2 +- .../apache/fury/format/encoder/Encoders.java | 2 +- .../format/encoder/MapEncoderBuilder.java | 2 +- .../format/encoder/RowEncoderBuilder.java | 2 +- .../fury/format/row/binary/BinaryUtils.java | 2 +- .../fury/format/type/TypeInference.java | 2 +- .../fury/format/encoder/ArrayEncoderTest.java | 2 +- .../fury/format/encoder/MapEncoderTest.java | 2 +- 41 files changed, 511 insertions(+), 41 deletions(-) create mode 100644 java/fury-core/src/main/java/org/apache/fury/reflect/Primitives.java create mode 100644 java/fury-core/src/main/java/org/apache/fury/reflect/TypeToken.java diff --git a/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java b/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java index dc4765250d..bdacf70e9b 100644 --- a/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java +++ b/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java @@ -50,7 +50,6 @@ import static org.apache.fury.util.Preconditions.checkArgument; import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; import java.lang.reflect.Modifier; import java.util.Collections; import java.util.HashMap; @@ -82,6 +81,7 @@ import org.apache.fury.codegen.ExpressionVisitor.ExprHolder; import org.apache.fury.collection.Tuple2; import org.apache.fury.memory.MemoryBuffer; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.resolver.ClassInfo; import org.apache.fury.resolver.ClassInfoHolder; import org.apache.fury.resolver.ClassResolver; diff --git a/java/fury-core/src/main/java/org/apache/fury/builder/CodecBuilder.java b/java/fury-core/src/main/java/org/apache/fury/builder/CodecBuilder.java index 94e65f742e..cfcd281987 100644 --- a/java/fury-core/src/main/java/org/apache/fury/builder/CodecBuilder.java +++ b/java/fury-core/src/main/java/org/apache/fury/builder/CodecBuilder.java @@ -34,7 +34,6 @@ import static org.apache.fury.type.TypeUtils.PRIMITIVE_VOID_TYPE; import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import java.lang.invoke.MethodHandle; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -55,6 +54,7 @@ import org.apache.fury.codegen.Expression.StaticInvoke; import org.apache.fury.collection.Tuple2; import org.apache.fury.memory.MemoryBuffer; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.resolver.ClassInfo; import org.apache.fury.resolver.ClassInfoHolder; import org.apache.fury.type.Descriptor; diff --git a/java/fury-core/src/main/java/org/apache/fury/builder/CodecUtils.java b/java/fury-core/src/main/java/org/apache/fury/builder/CodecUtils.java index 6d74a0122b..8808cc5edb 100644 --- a/java/fury-core/src/main/java/org/apache/fury/builder/CodecUtils.java +++ b/java/fury-core/src/main/java/org/apache/fury/builder/CodecUtils.java @@ -19,11 +19,11 @@ package org.apache.fury.builder; -import com.google.common.reflect.TypeToken; import java.util.Collections; import org.apache.fury.Fury; import org.apache.fury.codegen.CodeGenerator; import org.apache.fury.codegen.CompileUnit; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.resolver.FieldResolver; import org.apache.fury.serializer.Serializer; import org.apache.fury.type.ClassDef; diff --git a/java/fury-core/src/main/java/org/apache/fury/builder/CompatibleCodecBuilder.java b/java/fury-core/src/main/java/org/apache/fury/builder/CompatibleCodecBuilder.java index 3c0dfd102e..f234e4682c 100644 --- a/java/fury-core/src/main/java/org/apache/fury/builder/CompatibleCodecBuilder.java +++ b/java/fury-core/src/main/java/org/apache/fury/builder/CompatibleCodecBuilder.java @@ -33,7 +33,6 @@ import static org.apache.fury.type.TypeUtils.PRIMITIVE_VOID_TYPE; import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -66,6 +65,7 @@ import org.apache.fury.codegen.ExpressionOptimizer; import org.apache.fury.codegen.ExpressionUtils; import org.apache.fury.collection.Tuple2; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.resolver.ClassInfo; import org.apache.fury.resolver.ClassResolver; import org.apache.fury.resolver.FieldResolver; diff --git a/java/fury-core/src/main/java/org/apache/fury/builder/MetaSharedCodecBuilder.java b/java/fury-core/src/main/java/org/apache/fury/builder/MetaSharedCodecBuilder.java index 8c68f78e03..6d31d2a1b7 100644 --- a/java/fury-core/src/main/java/org/apache/fury/builder/MetaSharedCodecBuilder.java +++ b/java/fury-core/src/main/java/org/apache/fury/builder/MetaSharedCodecBuilder.java @@ -21,7 +21,6 @@ import static org.apache.fury.builder.Generated.GeneratedMetaSharedSerializer.SERIALIZER_FIELD_NAME; -import com.google.common.reflect.TypeToken; import java.util.Collection; import java.util.SortedMap; import org.apache.fury.Fury; @@ -32,6 +31,7 @@ import org.apache.fury.config.CompatibleMode; import org.apache.fury.config.FuryBuilder; import org.apache.fury.memory.MemoryBuffer; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.serializer.CodegenSerializer; import org.apache.fury.serializer.MetaSharedSerializer; import org.apache.fury.serializer.ObjectSerializer; diff --git a/java/fury-core/src/main/java/org/apache/fury/builder/ObjectCodecBuilder.java b/java/fury-core/src/main/java/org/apache/fury/builder/ObjectCodecBuilder.java index 76e28c9d8d..ec381f7b12 100644 --- a/java/fury-core/src/main/java/org/apache/fury/builder/ObjectCodecBuilder.java +++ b/java/fury-core/src/main/java/org/apache/fury/builder/ObjectCodecBuilder.java @@ -34,7 +34,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.reflect.TypeToken; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -56,6 +55,7 @@ import org.apache.fury.codegen.Expression.ReplaceStub; import org.apache.fury.codegen.Expression.StaticInvoke; import org.apache.fury.codegen.ExpressionVisitor; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.serializer.ObjectSerializer; import org.apache.fury.serializer.PrimitiveSerializers.LongSerializer; import org.apache.fury.type.Descriptor; diff --git a/java/fury-core/src/main/java/org/apache/fury/codegen/CodegenContext.java b/java/fury-core/src/main/java/org/apache/fury/codegen/CodegenContext.java index 2af5fbed6d..70502c78e3 100644 --- a/java/fury-core/src/main/java/org/apache/fury/codegen/CodegenContext.java +++ b/java/fury-core/src/main/java/org/apache/fury/codegen/CodegenContext.java @@ -26,7 +26,6 @@ import static org.apache.fury.type.TypeUtils.getRawType; import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -41,6 +40,7 @@ import org.apache.fury.codegen.Expression.Reference; import org.apache.fury.collection.Collections; import org.apache.fury.collection.Tuple2; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.util.Preconditions; import org.apache.fury.util.ReflectionUtils; import org.apache.fury.util.StringUtils; diff --git a/java/fury-core/src/main/java/org/apache/fury/codegen/Expression.java b/java/fury-core/src/main/java/org/apache/fury/codegen/Expression.java index b04b8c3bb8..88331251ad 100644 --- a/java/fury-core/src/main/java/org/apache/fury/codegen/Expression.java +++ b/java/fury-core/src/main/java/org/apache/fury/codegen/Expression.java @@ -47,7 +47,6 @@ import static org.apache.fury.type.TypeUtils.maxType; import static org.apache.fury.util.Preconditions.checkArgument; -import com.google.common.reflect.TypeToken; import java.lang.reflect.Array; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -56,6 +55,7 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.TypeUtils; import org.apache.fury.util.Platform; import org.apache.fury.util.Preconditions; diff --git a/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionUtils.java b/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionUtils.java index 9fe9e34fee..6420a5b647 100644 --- a/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionUtils.java +++ b/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionUtils.java @@ -28,7 +28,6 @@ import static org.apache.fury.codegen.Expression.StaticInvoke; import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -36,6 +35,7 @@ import java.util.List; import org.apache.fury.codegen.Expression.Cast; import org.apache.fury.codegen.Expression.Null; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.util.Preconditions; import org.apache.fury.util.StringUtils; import org.apache.fury.util.function.Functions; diff --git a/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionVisitor.java b/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionVisitor.java index 7371013b3f..58e3e4ac0a 100644 --- a/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionVisitor.java +++ b/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionVisitor.java @@ -19,7 +19,6 @@ package org.apache.fury.codegen; -import com.google.common.reflect.TypeToken; import java.io.Serializable; import java.lang.invoke.SerializedLambda; import java.lang.reflect.Field; @@ -34,6 +33,7 @@ import java.util.function.Function; import org.apache.fury.codegen.Expression.ListExpression; import org.apache.fury.codegen.Expression.Reference; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.TypeUtils; import org.apache.fury.util.Platform; import org.apache.fury.util.Preconditions; diff --git a/java/fury-core/src/main/java/org/apache/fury/reflect/Primitives.java b/java/fury-core/src/main/java/org/apache/fury/reflect/Primitives.java new file mode 100644 index 0000000000..2340e5ba7e --- /dev/null +++ b/java/fury-core/src/main/java/org/apache/fury/reflect/Primitives.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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 org.apache.fury.reflect; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; + +/** + * Contains static utility methods pertaining to primitive types and their corresponding wrapper + * types. + */ +public final class Primitives { + private Primitives() {} + + /** A map from primitive types to their corresponding wrapper types. */ + private static final Map, Class> PRIMITIVE_TO_WRAPPER_TYPE; + + /** A map from wrapper types to their corresponding primitive types. */ + private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPE; + + // Sad that we can't use a BiMap. :( + + static { + final Map, Class> primToWrap = new LinkedHashMap<>(16); + final Map, Class> wrapToPrim = new LinkedHashMap<>(16); + + add(primToWrap, wrapToPrim, boolean.class, Boolean.class); + add(primToWrap, wrapToPrim, byte.class, Byte.class); + add(primToWrap, wrapToPrim, char.class, Character.class); + add(primToWrap, wrapToPrim, double.class, Double.class); + add(primToWrap, wrapToPrim, float.class, Float.class); + add(primToWrap, wrapToPrim, int.class, Integer.class); + add(primToWrap, wrapToPrim, long.class, Long.class); + add(primToWrap, wrapToPrim, short.class, Short.class); + add(primToWrap, wrapToPrim, void.class, Void.class); + + PRIMITIVE_TO_WRAPPER_TYPE = Collections.unmodifiableMap(primToWrap); + WRAPPER_TO_PRIMITIVE_TYPE = Collections.unmodifiableMap(wrapToPrim); + } + + private static void add( + Map, Class> forward, + Map, Class> backward, + Class key, + Class value) { + forward.put(key, value); + backward.put(value, key); + } + + /** + * Returns an immutable set of all nine primitive types (including {@code void}). Note that a + * simpler way to test whether a {@code Class} instance is a member of this set is to call {@link + * Class#isPrimitive}. + */ + public static Set> allPrimitiveTypes() { + return PRIMITIVE_TO_WRAPPER_TYPE.keySet(); + } + + /** Returns an immutable set of all nine primitive-wrapper types (including {@link Void}). */ + public static Set> allWrapperTypes() { + return WRAPPER_TO_PRIMITIVE_TYPE.keySet(); + } + + /** + * Returns {@code true} if {@code type} is one of the nine primitive-wrapper types, such as {@link + * Integer}. + * + * @see Class#isPrimitive + */ + public static boolean isWrapperType(Class type) { + if (type == null) { + throw new NullPointerException(); + } + return WRAPPER_TO_PRIMITIVE_TYPE.containsKey(type); + } + + /** + * Returns the corresponding wrapper type of {@code type} if it is a primitive type; otherwise + * returns {@code type} itself. Idempotent. + * + *
+   *     wrap(int.class) == Integer.class
+   *     wrap(Integer.class) == Integer.class
+   *     wrap(String.class) == String.class
+   * 
+ */ + public static Class wrap(Class type) { + if (type == null) { + throw new NullPointerException(); + } + // cast is safe: long.class and Long.class are both of type Class + @SuppressWarnings("unchecked") + final Class wrapped = (Class) PRIMITIVE_TO_WRAPPER_TYPE.get(type); + return (wrapped == null) ? type : wrapped; + } + + /** + * Returns the corresponding primitive type of {@code type} if it is a wrapper type; otherwise + * returns {@code type} itself. Idempotent. + * + *
+   *     unwrap(Integer.class) == int.class
+   *     unwrap(int.class) == int.class
+   *     unwrap(String.class) == String.class
+   * 
+ */ + public static Class unwrap(Class type) { + if (type == null) { + throw new NullPointerException(); + } + // cast is safe: long.class and Long.class are both of type Class + @SuppressWarnings("unchecked") + final Class unwrapped = (Class) WRAPPER_TO_PRIMITIVE_TYPE.get(type); + return (unwrapped == null) ? type : unwrapped; + } +} diff --git a/java/fury-core/src/main/java/org/apache/fury/reflect/TypeToken.java b/java/fury-core/src/main/java/org/apache/fury/reflect/TypeToken.java new file mode 100644 index 0000000000..08d43aeb1c --- /dev/null +++ b/java/fury-core/src/main/java/org/apache/fury/reflect/TypeToken.java @@ -0,0 +1,335 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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 org.apache.fury.reflect; + +import com.google.common.reflect.TypeParameter; +import java.lang.reflect.Array; +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.lang.reflect.WildcardType; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +public class TypeToken { + + private final Type type; + + /** + * Constructs a new type token of {@code T}. + * + *

Clients create an empty anonymous subclass. This embeds the type parameter in the anonymous + * class's type hierarchy, so we can reconstitute it at runtime despite erasure. + * + *

For example: + * + *

{@code
+   * TypeToken> t = new TypeToken>() {};
+   * }
+ */ + protected TypeToken() { + this.type = capture(); + } + + private TypeToken(Class declaringClass) { + this.type = declaringClass; + } + + private TypeToken(Type type) { + this.type = type; + } + + /** Returns an instance of type token that wraps {@code type}. */ + public static TypeToken of(Class clazz) { + return new TypeToken(clazz); + } + + /** Returns an instance of type token that wraps {@code type}. */ + public static TypeToken of(Type type) { + return new TypeToken(type); + } + + /** Returns the captured type. */ + private Type capture() { + final Type superclass = getClass().getGenericSuperclass(); + if (!(superclass instanceof ParameterizedType)) { + throw new IllegalArgumentException(superclass + " isn't parameterized"); + } + return ((ParameterizedType) superclass).getActualTypeArguments()[0]; + } + + /** Returns the represented type. */ + public Type getType() { + return type; + } + + /** + * Returns the raw type of {@code T}. Formally speaking, if {@code T} is returned by {@link + * java.lang.reflect.Method#getGenericReturnType}, the raw type is what's returned by {@link + * java.lang.reflect.Method#getReturnType} of the same method object. Specifically: + * + *
    + *
  • If {@code T} is a {@code Class} itself, {@code T} itself is returned. + *
  • If {@code T} is a {@link ParameterizedType}, the raw type of the parameterized type is + * returned. + *
  • If {@code T} is a {@link GenericArrayType}, the returned type is the corresponding array + * class. For example: {@code List[] => List[]}. + *
  • If {@code T} is a type variable or a wildcard type, the raw type of the first upper bound + * is returned. For example: {@code => Foo}. + *
+ */ + public Class getRawType() { + // For wildcard or type variable, the first bound determines the runtime type. + Class rawType = getRawTypes(type).iterator().next(); + @SuppressWarnings("unchecked") // raw type is |T| + Class result = (Class) rawType; + return result; + } + + private static Set> getRawTypes(Type... types) { + Set> set = new HashSet<>(); + for (Type type : types) { + if (type instanceof TypeVariable) { + return getRawTypes(((TypeVariable) type).getBounds()); + } else if (type instanceof WildcardType) { + return getRawTypes(((WildcardType) type).getUpperBounds()); + } else if (type instanceof ParameterizedType) { + set.add((Class) ((ParameterizedType) type).getRawType()); + } else if (type instanceof Class) { + set.add((Class) type); + } else if (type instanceof GenericArrayType) { + set.add( + getArrayClass(of(((GenericArrayType) type).getGenericComponentType()).getRawType())); + } else { + throw new AssertionError("Unknown type: " + type); + } + } + return Collections.unmodifiableSet(set); + } + + + /** Returns true if this type is one of the primitive types (including {@code void}). */ + public boolean isPrimitive() { + return type instanceof Class && ((Class) type).isPrimitive(); + } + + /** + * Returns true if this type is known to be an array type, such as {@code int[]}, {@code T[]}, + * {@code []>} etc. + */ + public boolean isArray() { + return getComponentType(type) != null; + } + + /** + * Returns the array component type if this type represents an array ({@code int[]}, {@code T[]}, + * {@code []>} etc.), or else {@code null} is returned. + */ + public TypeToken getComponentType() { + return of(getComponentType(type)); + } + + /** + * Returns the array component type if this type represents an array ({@code int[]}, {@code T[]}, + * {@code []>} etc.), or else {@code null} is returned. + */ + private static Type getComponentType(Type type) { + if (type == null) { + return null; + } + if (type instanceof TypeVariable) { + return subtypeOfComponentType(((TypeVariable) type).getBounds()); + } else if (type instanceof WildcardType) { + return subtypeOfComponentType(((WildcardType) type).getUpperBounds()); + } else if (type instanceof Class) { + return ((Class) type).getComponentType(); + } else if (type instanceof GenericArrayType) { + return ((GenericArrayType) type).getGenericComponentType(); + } + return null; + } + + /** + * Returns {@code ? extends X} if any of {@code bounds} is a subtype of {@code X[]}; or null + * otherwise. + */ + private static Type subtypeOfComponentType(Type[] bounds) { + for (Type bound : bounds) { + final Type componentType = getComponentType(bound); + if (componentType != null) { + // Only the first bound can be a class or array. + // Bounds after the first can only be interfaces. + if (componentType instanceof Class) { + final Class componentClass = (Class) componentType; + if (componentClass.isPrimitive()) { + return componentClass; + } + } + return componentType; + } + } + return null; + } + + /** + * Do not use this method. This is used only for code refactoring during Guava dependency removal. + */ + public com.google.common.reflect.TypeToken getGuavaTypeToken() { + return com.google.common.reflect.TypeToken.of(type); + } + + /** + * Resolves the given {@code type} against the type context represented by this type. For example: + * + *
{@code
+   * new TypeToken>() {}.resolveType(
+   *     List.class.getMethod("get", int.class).getGenericReturnType())
+   * => String.class
+   * }
+ */ + public TypeToken resolveType(Type iteratorReturnType) { + // TODO: Remove guava dependency. + return TypeToken.of(getGuavaTypeToken().resolveType(iteratorReturnType).getType()); + } + + /** + * Returns the generic form of {@code superclass}. For example, if this is {@code + * ArrayList}, {@code Iterable} is returned given the input {@code + * Iterable.class}. + */ + public TypeToken getSupertype(Class superclass) { + // TODO: Remove guava dependency. + return TypeToken.of( + ((com.google.common.reflect.TypeToken) getGuavaTypeToken()) + .getSupertype(superclass) + .getType()); + } + + /** + * Returns subtype of {@code this} with {@code subclass} as the raw class. For example, if this is + * {@code Iterable} and {@code subclass} is {@code List}, {@code List} is + * returned. + */ + public final TypeToken getSubtype(Class subclass) { + // TODO: Remove guava dependency. + return of(getGuavaTypeToken().getSubtype(subclass).getType()); + } + + /** Returns true if this type is a subtype of the given {@code type}. */ + public boolean isSubtypeOf(TypeToken type) { + return isSubtypeOf(type.getType()); + } + + /** Returns true if this type is a subtype of the given {@code type}. */ + public final boolean isSubtypeOf(Type supertype) { + // TODO: Remove guava dependency. + return getGuavaTypeToken().isSubtypeOf(supertype); + } + + /** Returns true if this type is a supertype of the given {@code type}. */ + public final boolean isSupertypeOf(Type type) { + // TODO: Remove guava dependency. + return of(type).getGuavaTypeToken().isSubtypeOf(getType()); + } + + /** Returns true if this type is a supertype of the given {@code type}. */ + public final boolean isSupertypeOf(TypeToken type) { + // TODO: Remove guava dependency. + return type.getGuavaTypeToken().isSubtypeOf(getType()); + } + + /** + * Returns the corresponding wrapper type if this is a primitive type; otherwise returns {@code + * this} itself. + */ + public final TypeToken wrap() { + if (isPrimitive()) { + @SuppressWarnings("unchecked") + final Class clazz = (Class) type; + return of(Primitives.wrap(clazz)); + } + return this; + } + + /** + * Returns the corresponding primitive type if this is a wrapper type; otherwise returns {@code + * this} itself. + */ + public final TypeToken unwrap() { + if (isWrapper()) { + @SuppressWarnings("unchecked") // this is a wrapper class + final Class clazz = (Class) type; + return of(Primitives.unwrap(clazz)); + } + return this; + } + + public TypeToken where(TypeParameter typeParam, Class typeArg) { + return where(typeParam, of(typeArg)); + } + + public final TypeToken where(TypeParameter typeParam, TypeToken typeArg) { + // TODO: Remove guava dependency. + return of( + getGuavaTypeToken() + .where( + typeParam, + (com.google.common.reflect.TypeToken) + com.google.common.reflect.TypeToken.of(typeArg.getType())) + .getType()); + } + + private boolean isWrapper() { + if (type instanceof Class) { + return Primitives.allPrimitiveTypes().contains((Class) type); + } + return false; + } + + /** + * Returns true if {@code o} is another {@code TypeToken} that represents the same {@link Type}. + */ + @Override + public boolean equals(Object o) { + if (o instanceof TypeToken) { + final TypeToken that = (TypeToken) o; + return type.equals(that.type); + } + return false; + } + + @Override + public int hashCode() { + return type.hashCode(); + } + + @Override + public String toString() { + return (type instanceof Class) ? ((Class) type).getName() : type.toString(); + } + + /** Returns the {@code Class} object of arrays with {@code componentType}. */ + private static Class getArrayClass(Class componentType) { + return Array.newInstance(componentType, 0).getClass(); + } + +} diff --git a/java/fury-core/src/main/java/org/apache/fury/resolver/ClassResolver.java b/java/fury-core/src/main/java/org/apache/fury/resolver/ClassResolver.java index b61242e636..6630491f06 100644 --- a/java/fury-core/src/main/java/org/apache/fury/resolver/ClassResolver.java +++ b/java/fury-core/src/main/java/org/apache/fury/resolver/ClassResolver.java @@ -29,7 +29,6 @@ import static org.apache.fury.type.TypeUtils.getRawType; import com.google.common.collect.ImmutableMap; -import com.google.common.reflect.TypeToken; import java.io.Externalizable; import java.io.IOException; import java.io.Serializable; @@ -96,6 +95,7 @@ import org.apache.fury.config.Language; import org.apache.fury.exception.InsecureException; import org.apache.fury.memory.MemoryBuffer; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.serializer.ArraySerializers; import org.apache.fury.serializer.BufferSerializers; import org.apache.fury.serializer.CodegenSerializer.LazyInitBeanSerializer; diff --git a/java/fury-core/src/main/java/org/apache/fury/resolver/FieldResolver.java b/java/fury-core/src/main/java/org/apache/fury/resolver/FieldResolver.java index 88dcb162f6..c987614b1c 100644 --- a/java/fury-core/src/main/java/org/apache/fury/resolver/FieldResolver.java +++ b/java/fury-core/src/main/java/org/apache/fury/resolver/FieldResolver.java @@ -27,7 +27,6 @@ import static org.apache.fury.resolver.FieldResolver.FieldInfoEncodingType.SEPARATE_TYPES_HASH; import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.nio.charset.StandardCharsets; @@ -48,6 +47,7 @@ import org.apache.fury.collection.Tuple2; import org.apache.fury.exception.ClassNotCompatibleException; import org.apache.fury.memory.MemoryBuffer; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.serializer.PrimitiveSerializers; import org.apache.fury.serializer.collection.CollectionSerializer; import org.apache.fury.serializer.collection.MapSerializer; diff --git a/java/fury-core/src/main/java/org/apache/fury/serializer/ObjectSerializer.java b/java/fury-core/src/main/java/org/apache/fury/serializer/ObjectSerializer.java index 7d99b59c1a..bba8ec8d15 100644 --- a/java/fury-core/src/main/java/org/apache/fury/serializer/ObjectSerializer.java +++ b/java/fury-core/src/main/java/org/apache/fury/serializer/ObjectSerializer.java @@ -21,7 +21,6 @@ import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import java.lang.invoke.MethodHandle; import java.util.ArrayList; import java.util.Arrays; @@ -34,6 +33,7 @@ import org.apache.fury.collection.Tuple3; import org.apache.fury.exception.FuryException; import org.apache.fury.memory.MemoryBuffer; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.resolver.ClassInfo; import org.apache.fury.resolver.ClassInfoHolder; import org.apache.fury.resolver.ClassResolver; diff --git a/java/fury-core/src/main/java/org/apache/fury/serializer/StructSerializer.java b/java/fury-core/src/main/java/org/apache/fury/serializer/StructSerializer.java index 97a8a0b81d..15a4ba9dce 100644 --- a/java/fury-core/src/main/java/org/apache/fury/serializer/StructSerializer.java +++ b/java/fury-core/src/main/java/org/apache/fury/serializer/StructSerializer.java @@ -19,7 +19,6 @@ package org.apache.fury.serializer; -import com.google.common.reflect.TypeToken; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -32,6 +31,7 @@ import org.apache.fury.config.Language; import org.apache.fury.exception.ClassNotCompatibleException; import org.apache.fury.memory.MemoryBuffer; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.Descriptor; import org.apache.fury.type.GenericType; import org.apache.fury.type.Generics; diff --git a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java index c62d2912cf..33c031300c 100644 --- a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java +++ b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java @@ -21,13 +21,13 @@ import static org.apache.fury.type.TypeUtils.MAP_TYPE; -import com.google.common.reflect.TypeToken; import java.lang.invoke.MethodHandle; import java.util.Map; import org.apache.fury.Fury; import org.apache.fury.collection.IdentityMap; import org.apache.fury.collection.Tuple2; import org.apache.fury.memory.MemoryBuffer; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.resolver.ClassInfoHolder; import org.apache.fury.resolver.ClassResolver; import org.apache.fury.resolver.RefResolver; diff --git a/java/fury-core/src/main/java/org/apache/fury/type/ClassDef.java b/java/fury-core/src/main/java/org/apache/fury/type/ClassDef.java index cf60b72199..74578387a9 100644 --- a/java/fury-core/src/main/java/org/apache/fury/type/ClassDef.java +++ b/java/fury-core/src/main/java/org/apache/fury/type/ClassDef.java @@ -24,7 +24,6 @@ import static org.apache.fury.type.TypeUtils.collectionOf; import static org.apache.fury.type.TypeUtils.mapOf; -import com.google.common.reflect.TypeToken; import java.io.ObjectStreamClass; import java.io.Serializable; import java.lang.reflect.Field; @@ -44,6 +43,7 @@ import org.apache.fury.config.FuryBuilder; import org.apache.fury.memory.MemoryBuffer; import org.apache.fury.memory.MemoryUtils; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.resolver.ClassResolver; import org.apache.fury.serializer.CompatibleSerializer; import org.apache.fury.util.LoggerFactory; diff --git a/java/fury-core/src/main/java/org/apache/fury/type/Descriptor.java b/java/fury-core/src/main/java/org/apache/fury/type/Descriptor.java index f5e78f5ef6..3f7085d960 100644 --- a/java/fury-core/src/main/java/org/apache/fury/type/Descriptor.java +++ b/java/fury-core/src/main/java/org/apache/fury/type/Descriptor.java @@ -23,7 +23,6 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.reflect.TypeToken; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -46,6 +45,7 @@ import org.apache.fury.annotation.Ignore; import org.apache.fury.annotation.Internal; import org.apache.fury.collection.Tuple2; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.util.Platform; import org.apache.fury.util.Preconditions; import org.apache.fury.util.StringUtils; diff --git a/java/fury-core/src/main/java/org/apache/fury/type/GenericType.java b/java/fury-core/src/main/java/org/apache/fury/type/GenericType.java index cfdd551fd4..d2f236e42a 100644 --- a/java/fury-core/src/main/java/org/apache/fury/type/GenericType.java +++ b/java/fury-core/src/main/java/org/apache/fury/type/GenericType.java @@ -21,7 +21,6 @@ import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import java.lang.reflect.GenericArrayType; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; @@ -31,6 +30,7 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.resolver.ClassResolver; import org.apache.fury.serializer.Serializer; diff --git a/java/fury-core/src/main/java/org/apache/fury/type/ScalaTypes.java b/java/fury-core/src/main/java/org/apache/fury/type/ScalaTypes.java index 096a5720aa..5772112de0 100644 --- a/java/fury-core/src/main/java/org/apache/fury/type/ScalaTypes.java +++ b/java/fury-core/src/main/java/org/apache/fury/type/ScalaTypes.java @@ -19,10 +19,10 @@ package org.apache.fury.type; -import com.google.common.reflect.TypeToken; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import org.apache.fury.collection.Tuple2; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.util.ReflectionUtils; /** diff --git a/java/fury-core/src/main/java/org/apache/fury/type/TypeUtils.java b/java/fury-core/src/main/java/org/apache/fury/type/TypeUtils.java index 687cef9c91..92b77ffb70 100644 --- a/java/fury-core/src/main/java/org/apache/fury/type/TypeUtils.java +++ b/java/fury-core/src/main/java/org/apache/fury/type/TypeUtils.java @@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.reflect.TypeParameter; -import com.google.common.reflect.TypeToken; import java.lang.reflect.Array; import java.lang.reflect.GenericArrayType; import java.lang.reflect.Modifier; @@ -50,6 +49,7 @@ import java.util.stream.Collectors; import org.apache.fury.collection.IdentityMap; import org.apache.fury.collection.Tuple2; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.util.Preconditions; import org.apache.fury.util.ReflectionUtils; diff --git a/java/fury-core/src/main/java/org/apache/fury/util/ReflectionUtils.java b/java/fury-core/src/main/java/org/apache/fury/util/ReflectionUtils.java index 607833cc21..47483195b9 100644 --- a/java/fury-core/src/main/java/org/apache/fury/util/ReflectionUtils.java +++ b/java/fury-core/src/main/java/org/apache/fury/util/ReflectionUtils.java @@ -22,7 +22,6 @@ import static org.apache.fury.type.TypeUtils.OBJECT_TYPE; import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; @@ -48,6 +47,7 @@ import org.apache.fury.annotation.CodegenInvoke; import org.apache.fury.annotation.Internal; import org.apache.fury.collection.Tuple3; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.util.function.Functions; import org.apache.fury.util.unsafe._JDKAccess; diff --git a/java/fury-core/src/test/java/org/apache/fury/FuryInitPerf.java b/java/fury-core/src/test/java/org/apache/fury/FuryInitPerf.java index 2e3ecfb97b..5f8b531830 100644 --- a/java/fury-core/src/test/java/org/apache/fury/FuryInitPerf.java +++ b/java/fury-core/src/test/java/org/apache/fury/FuryInitPerf.java @@ -19,7 +19,7 @@ package org.apache.fury; -import com.google.common.reflect.TypeToken; +import org.apache.fury.reflect.TypeToken; import java.util.ArrayList; import java.util.Collection; import java.util.List; diff --git a/java/fury-core/src/test/java/org/apache/fury/codegen/CodegenContextTest.java b/java/fury-core/src/test/java/org/apache/fury/codegen/CodegenContextTest.java index 3b3a72a163..0e33f9a0d8 100644 --- a/java/fury-core/src/test/java/org/apache/fury/codegen/CodegenContextTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/codegen/CodegenContextTest.java @@ -19,7 +19,7 @@ package org.apache.fury.codegen; -import com.google.common.reflect.TypeToken; +import org.apache.fury.reflect.TypeToken; import java.util.List; import org.apache.fury.codegen.Expression.Invoke; import org.apache.fury.codegen.Expression.Literal; diff --git a/java/fury-core/src/test/java/org/apache/fury/codegen/ExpressionVisitorTest.java b/java/fury-core/src/test/java/org/apache/fury/codegen/ExpressionVisitorTest.java index e265c93ccf..0d4fd4ce34 100644 --- a/java/fury-core/src/test/java/org/apache/fury/codegen/ExpressionVisitorTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/codegen/ExpressionVisitorTest.java @@ -21,7 +21,7 @@ import static org.testng.Assert.assertEquals; -import com.google.common.reflect.TypeToken; +import org.apache.fury.reflect.TypeToken; import java.lang.invoke.SerializedLambda; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; diff --git a/java/fury-core/src/test/java/org/apache/fury/serializer/collection/CollectionSerializersTest.java b/java/fury-core/src/test/java/org/apache/fury/serializer/collection/CollectionSerializersTest.java index 226003e543..34d36894b6 100644 --- a/java/fury-core/src/test/java/org/apache/fury/serializer/collection/CollectionSerializersTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/serializer/collection/CollectionSerializersTest.java @@ -27,7 +27,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; -import com.google.common.reflect.TypeToken; +import org.apache.fury.reflect.TypeToken; import java.io.Serializable; import java.util.AbstractCollection; import java.util.ArrayDeque; diff --git a/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java b/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java index 78826efafb..157da7f02d 100644 --- a/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java @@ -25,7 +25,7 @@ import static org.testng.Assert.assertEquals; import com.google.common.collect.ImmutableMap; -import com.google.common.reflect.TypeToken; +import org.apache.fury.reflect.TypeToken; import java.io.Serializable; import java.util.AbstractMap; import java.util.ArrayList; diff --git a/java/fury-core/src/test/java/org/apache/fury/type/DescriptorGrouperTest.java b/java/fury-core/src/test/java/org/apache/fury/type/DescriptorGrouperTest.java index 69861f0f40..5eb5c569d2 100644 --- a/java/fury-core/src/test/java/org/apache/fury/type/DescriptorGrouperTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/type/DescriptorGrouperTest.java @@ -22,7 +22,7 @@ import static org.testng.Assert.*; import com.google.common.primitives.Primitives; -import com.google.common.reflect.TypeToken; +import org.apache.fury.reflect.TypeToken; import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; diff --git a/java/fury-core/src/test/java/org/apache/fury/type/DescriptorTest.java b/java/fury-core/src/test/java/org/apache/fury/type/DescriptorTest.java index 13c22f7383..59c343b529 100644 --- a/java/fury-core/src/test/java/org/apache/fury/type/DescriptorTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/type/DescriptorTest.java @@ -19,7 +19,7 @@ package org.apache.fury.type; -import com.google.common.reflect.TypeToken; +import org.apache.fury.reflect.TypeToken; import java.beans.IntrospectionException; import java.beans.Introspector; import java.lang.reflect.Field; @@ -72,8 +72,8 @@ public void getDescriptorsTest() throws IntrospectionException { .filter(d -> d.getReadMethod() != null && d.getWriteMethod() != null) .map( p -> { - TypeToken returnType = typeToken.method(p.getReadMethod()).getReturnType(); - return Arrays.asList( + TypeToken returnType = TypeToken.of(p.getReadMethod().getReturnType()); + return Arrays.asList( p.getName(), returnType, p.getReadMethod().getName(), diff --git a/java/fury-core/src/test/java/org/apache/fury/type/TypeUtilsTest.java b/java/fury-core/src/test/java/org/apache/fury/type/TypeUtilsTest.java index 342dc01c97..795661a2db 100644 --- a/java/fury-core/src/test/java/org/apache/fury/type/TypeUtilsTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/type/TypeUtilsTest.java @@ -22,7 +22,7 @@ import static org.testng.Assert.assertEquals; import com.google.common.collect.ImmutableList; -import com.google.common.reflect.TypeToken; +import org.apache.fury.reflect.TypeToken; import java.lang.reflect.Type; import java.util.AbstractList; import java.util.ArrayList; diff --git a/java/fury-format/src/main/java/org/apache/fury/format/encoder/ArrayDataForEach.java b/java/fury-format/src/main/java/org/apache/fury/format/encoder/ArrayDataForEach.java index fcb92d9154..db3ae1f511 100644 --- a/java/fury-format/src/main/java/org/apache/fury/format/encoder/ArrayDataForEach.java +++ b/java/fury-format/src/main/java/org/apache/fury/format/encoder/ArrayDataForEach.java @@ -21,7 +21,6 @@ import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import org.apache.fury.annotation.Internal; import org.apache.fury.codegen.ClosureVisitable; import org.apache.fury.codegen.Code; @@ -30,6 +29,7 @@ import org.apache.fury.codegen.Expression; import org.apache.fury.format.row.binary.BinaryArray; import org.apache.fury.format.row.binary.BinaryUtils; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.TypeUtils; import org.apache.fury.util.Preconditions; import org.apache.fury.util.StringUtils; diff --git a/java/fury-format/src/main/java/org/apache/fury/format/encoder/ArrayEncoderBuilder.java b/java/fury-format/src/main/java/org/apache/fury/format/encoder/ArrayEncoderBuilder.java index e1e2e078e2..a1fb9aebb1 100644 --- a/java/fury-format/src/main/java/org/apache/fury/format/encoder/ArrayEncoderBuilder.java +++ b/java/fury-format/src/main/java/org/apache/fury/format/encoder/ArrayEncoderBuilder.java @@ -22,7 +22,6 @@ import static org.apache.fury.type.TypeUtils.CLASS_TYPE; import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import org.apache.arrow.vector.types.pojo.Field; import org.apache.fury.Fury; import org.apache.fury.codegen.CodeGenerator; @@ -32,6 +31,7 @@ import org.apache.fury.format.row.binary.BinaryArray; import org.apache.fury.format.row.binary.writer.BinaryArrayWriter; import org.apache.fury.format.type.TypeInference; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.TypeUtils; import org.apache.fury.util.LoggerFactory; import org.apache.fury.util.StringUtils; diff --git a/java/fury-format/src/main/java/org/apache/fury/format/encoder/BaseBinaryEncoderBuilder.java b/java/fury-format/src/main/java/org/apache/fury/format/encoder/BaseBinaryEncoderBuilder.java index bd14230389..054d5a3331 100644 --- a/java/fury-format/src/main/java/org/apache/fury/format/encoder/BaseBinaryEncoderBuilder.java +++ b/java/fury-format/src/main/java/org/apache/fury/format/encoder/BaseBinaryEncoderBuilder.java @@ -21,7 +21,6 @@ import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; @@ -63,6 +62,7 @@ import org.apache.fury.format.row.binary.writer.BinaryWriter; import org.apache.fury.format.type.DataTypes; import org.apache.fury.memory.MemoryBuffer; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.TypeUtils; import org.apache.fury.util.DateTimeUtils; import org.apache.fury.util.Preconditions; diff --git a/java/fury-format/src/main/java/org/apache/fury/format/encoder/Encoders.java b/java/fury-format/src/main/java/org/apache/fury/format/encoder/Encoders.java index 5b6b888a2a..8f4b702b52 100644 --- a/java/fury-format/src/main/java/org/apache/fury/format/encoder/Encoders.java +++ b/java/fury-format/src/main/java/org/apache/fury/format/encoder/Encoders.java @@ -21,7 +21,6 @@ import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import java.util.Collection; import java.util.HashSet; import java.util.Map; @@ -43,6 +42,7 @@ import org.apache.fury.format.type.TypeInference; import org.apache.fury.memory.MemoryBuffer; import org.apache.fury.memory.MemoryUtils; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.TypeUtils; import org.apache.fury.util.LoggerFactory; import org.slf4j.Logger; diff --git a/java/fury-format/src/main/java/org/apache/fury/format/encoder/MapEncoderBuilder.java b/java/fury-format/src/main/java/org/apache/fury/format/encoder/MapEncoderBuilder.java index b4ba11e549..00e79cd817 100644 --- a/java/fury-format/src/main/java/org/apache/fury/format/encoder/MapEncoderBuilder.java +++ b/java/fury-format/src/main/java/org/apache/fury/format/encoder/MapEncoderBuilder.java @@ -22,7 +22,6 @@ import static org.apache.fury.type.TypeUtils.CLASS_TYPE; import static org.apache.fury.type.TypeUtils.getRawType; -import com.google.common.reflect.TypeToken; import java.util.Map; import org.apache.arrow.vector.types.pojo.Field; import org.apache.fury.Fury; @@ -34,6 +33,7 @@ import org.apache.fury.format.row.binary.BinaryMap; import org.apache.fury.format.row.binary.writer.BinaryArrayWriter; import org.apache.fury.format.type.TypeInference; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.TypeUtils; import org.apache.fury.util.LoggerFactory; import org.apache.fury.util.StringUtils; diff --git a/java/fury-format/src/main/java/org/apache/fury/format/encoder/RowEncoderBuilder.java b/java/fury-format/src/main/java/org/apache/fury/format/encoder/RowEncoderBuilder.java index edf037aa4f..cb1e863144 100644 --- a/java/fury-format/src/main/java/org/apache/fury/format/encoder/RowEncoderBuilder.java +++ b/java/fury-format/src/main/java/org/apache/fury/format/encoder/RowEncoderBuilder.java @@ -23,7 +23,6 @@ import static org.apache.fury.type.TypeUtils.getRawType; import com.google.common.base.CaseFormat; -import com.google.common.reflect.TypeToken; import java.lang.reflect.Modifier; import java.util.SortedMap; import org.apache.arrow.vector.types.pojo.Field; @@ -46,6 +45,7 @@ import org.apache.fury.format.row.binary.writer.BinaryRowWriter; import org.apache.fury.format.type.DataTypes; import org.apache.fury.format.type.TypeInference; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.Descriptor; import org.apache.fury.type.TypeUtils; import org.apache.fury.util.GraalvmSupport; diff --git a/java/fury-format/src/main/java/org/apache/fury/format/row/binary/BinaryUtils.java b/java/fury-format/src/main/java/org/apache/fury/format/row/binary/BinaryUtils.java index 9b5b65ab72..d6e81685c1 100644 --- a/java/fury-format/src/main/java/org/apache/fury/format/row/binary/BinaryUtils.java +++ b/java/fury-format/src/main/java/org/apache/fury/format/row/binary/BinaryUtils.java @@ -19,8 +19,8 @@ package org.apache.fury.format.row.binary; -import com.google.common.reflect.TypeToken; import org.apache.fury.memory.MemoryBuffer; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.TypeUtils; /** diff --git a/java/fury-format/src/main/java/org/apache/fury/format/type/TypeInference.java b/java/fury-format/src/main/java/org/apache/fury/format/type/TypeInference.java index 556db3a459..22aa19951a 100644 --- a/java/fury-format/src/main/java/org/apache/fury/format/type/TypeInference.java +++ b/java/fury-format/src/main/java/org/apache/fury/format/type/TypeInference.java @@ -23,7 +23,6 @@ import static org.apache.fury.type.TypeUtils.getRawType; import com.google.common.base.CaseFormat; -import com.google.common.reflect.TypeToken; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; @@ -39,6 +38,7 @@ import org.apache.arrow.vector.types.pojo.FieldType; import org.apache.arrow.vector.types.pojo.Schema; import org.apache.fury.collection.Tuple2; +import org.apache.fury.reflect.TypeToken; import org.apache.fury.type.Descriptor; import org.apache.fury.type.TypeUtils; import org.apache.fury.util.DecimalUtils; diff --git a/java/fury-format/src/test/java/org/apache/fury/format/encoder/ArrayEncoderTest.java b/java/fury-format/src/test/java/org/apache/fury/format/encoder/ArrayEncoderTest.java index 4d375e8480..531cf36f4e 100644 --- a/java/fury-format/src/test/java/org/apache/fury/format/encoder/ArrayEncoderTest.java +++ b/java/fury-format/src/test/java/org/apache/fury/format/encoder/ArrayEncoderTest.java @@ -19,7 +19,7 @@ package org.apache.fury.format.encoder; -import com.google.common.reflect.TypeToken; +import org.apache.fury.reflect.TypeToken; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; diff --git a/java/fury-format/src/test/java/org/apache/fury/format/encoder/MapEncoderTest.java b/java/fury-format/src/test/java/org/apache/fury/format/encoder/MapEncoderTest.java index b9bf07f590..b7a618d845 100644 --- a/java/fury-format/src/test/java/org/apache/fury/format/encoder/MapEncoderTest.java +++ b/java/fury-format/src/test/java/org/apache/fury/format/encoder/MapEncoderTest.java @@ -19,7 +19,7 @@ package org.apache.fury.format.encoder; -import com.google.common.reflect.TypeToken; +import org.apache.fury.reflect.TypeToken; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap;