Example usage for com.google.common.reflect TypeToken isSubtypeOf

List of usage examples for com.google.common.reflect TypeToken isSubtypeOf

Introduction

In this page you can find the example usage for com.google.common.reflect TypeToken isSubtypeOf.

Prototype

public final boolean isSubtypeOf(Type supertype) 

Source Link

Document

Returns true if this type is a subtype of the given type .

Usage

From source file:com.google.api.server.spi.config.model.Types.java

public static boolean isCollectionResponseType(TypeToken<?> type) {
    return type.isSubtypeOf(CollectionResponse.class);
}

From source file:com.google.api.server.spi.config.model.Types.java

/**
 * Returns whether or not this type is an {@link Enum}.
 *//*from   www.  ja  v a  2  s .c om*/
public static boolean isEnumType(TypeToken<?> type) {
    return type.isSubtypeOf(Enum.class);
}

From source file:com.google.api.server.spi.config.model.Types.java

/**
 * Returns whether or not this type is a {@link Map}. This excludes {@link GenericData}, which is
 * used by the Google Java client library as a supertype of resource types with concrete fields.
 *///from ww  w  .j  av  a  2s  .  co  m
public static boolean isMapType(TypeToken<?> type) {
    return type.isSubtypeOf(Map.class) && !isJavaClientEntity(type);
}

From source file:com.google.api.server.spi.config.model.Types.java

/**
 * Returns whether or not this type is a Google Java client library entity.
 *///w ww . j a va  2 s.c o  m
public static boolean isJavaClientEntity(TypeToken<?> type) {
    return type.isSubtypeOf(GenericData.class);
}

From source file:com.google.api.server.spi.config.model.Types.java

/**
 * Gets the element type of a type we want to treat as an array. Actual arrays or subtypes of
 * {@link java.util.Collection} can be treated as arrays. Returns null if the type cannot be
 * treated as an array./*  w  ww . j  ava2s  . co  m*/
 */
public static TypeToken<?> getArrayItemType(TypeToken<?> type) {
    if (type.isSubtypeOf(Collection.class)) {
        return type.resolveType(Collection.class.getTypeParameters()[0]);
    } else if (type.isArray()) {
        return type.getComponentType();
    }
    return null;
}

From source file:com.google.api.server.spi.config.model.Types.java

/**
 * Returns whether or not this type should be treated as a JSON array type. This includes all
 * array and {@link Collection} types, except for byte arrays, which are treated as base64
 * encoded strings.// ww w.ja  v a2  s .  co m
 */
public static boolean isArrayType(TypeToken<?> type) {
    return getArrayItemType(type) != null && !type.isSubtypeOf(byte[].class);
}

From source file:net.navatwo.jfxproperties.MoreReflection.java

public static boolean isReadOnlyProperty(TypeToken<?> type) {
    return type.isSubtypeOf(ReadOnlyProperty.class);
}

From source file:net.navatwo.jfxproperties.MoreReflection.java

public static boolean isProperty(TypeToken<?> type) {
    return type.isSubtypeOf(Property.class);
}

From source file:net.navatwo.jfxproperties.MoreReflection.java

public static boolean isOptional(TypeToken<?> type) {
    return type.isSubtypeOf(Optional.class);
}

From source file:net.navatwo.jfxproperties.MoreReflection.java

/**
 * Checks if the passed type is an observable collection of the correct type.
 *
 * @param propType//from  w  w  w . jav  a  2 s . co m
 * @return
 */
public static boolean isCollection(TypeToken<?> propType) {
    return propType.isSubtypeOf(Map.class) || propType.isSubtypeOf(Collection.class);
}