Example usage for com.google.common.reflect TypeParameter TypeParameter

List of usage examples for com.google.common.reflect TypeParameter TypeParameter

Introduction

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

Prototype

protected TypeParameter() 

Source Link

Usage

From source file:org.apache.beam.sdk.values.TypeDescriptors.java

/**
 * The {@link TypeDescriptor} for {@link KV}.
 * This is the equivalent of:/*from   w  w w .j  ava 2  s.co m*/
 * <pre>
 * new TypeDescriptor&lt;KV&lt;K,V&gt;&gt;() {};
 * </pre>
 *
 * <p>Example of use:
 * <pre>
 * {@code
 * PCollection<String> words = ...;
 * PCollection<KV<String, String>> words = words.apply(
 *            FlatMapElements.via(...)
 *            .withOutputType(
 *              TypeDescriptors.kv(TypeDescriptors.strings(), TypeDescriptors.strings())));
 * }
 * </pre>
 * @param key The {@link TypeDescriptor} for the key
 * @param value The {@link TypeDescriptor} for the value
 * @return A {@link TypeDescriptor} for {@link KV}
 */
public static <K, V> TypeDescriptor<KV<K, V>> kvs(TypeDescriptor<K> key, TypeDescriptor<V> value) {
    TypeDescriptor<KV<K, V>> typeDescriptor = new TypeDescriptor<KV<K, V>>() {
    }.<K>where(new TypeParameter<K>() {
    }, key).<V>where(new TypeParameter<V>() {
    }, value);

    return typeDescriptor;
}

From source file:ninja.leaping.configurate.SimpleConfigurationNode.java

@Override
public <T> List<T> getList(TypeToken<T> type, Supplier<List<T>> defSupplier) throws ObjectMappingException {
    List<T> ret = getValue(new TypeToken<List<T>>() {
    }.where(new TypeParameter<T>() {
    }, type), defSupplier);/*from  w w  w .j  a va  2 s  .  co m*/
    return ret.isEmpty() ? calculateDef(defSupplier.get()) : ret;
}

From source file:io.airlift.drift.codec.metadata.ThriftType.java

public static <T> ThriftType optional(ThriftTypeReference valueTypeReference) {
    requireNonNull(valueTypeReference, "valueTypeReference is null");

    @SuppressWarnings("serial")
    Type javaType = new TypeToken<Optional<T>>() {
    }.where(new TypeParameter<T>() {
    }, (TypeToken<T>) TypeToken.of(valueTypeReference.getJavaType())).getType();
    return new ThriftType(valueTypeReference.getProtocolType(), javaType, null, valueTypeReference,
            Optional.empty());//w  w  w.  ja va 2 s  . c o m
}

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  .  j  a  va  2  s . co  m*/
 * @return
 */
public static <K, V> boolean isMap(TypeToken<?> propType, TypeToken<K> keyType, TypeToken<V> valueType) {
    TypeToken<Map<K, V>> mapType = new TypeToken<Map<K, V>>() {
    }.where(new TypeParameter<K>() {
    }, keyType).where(new TypeParameter<V>() {
    }, valueType);

    boolean result = propType.isSubtypeOf(mapType);
    if (result) {
        TypeToken<?> pKeyType = resolveTypeParameter(propType, 0);
        TypeToken<?> pValueType = resolveTypeParameter(propType, 1);

        result &= keyType.isSubtypeOf(pKeyType) && valueType.isSubtypeOf(pValueType);
    }

    return result;
}

From source file:io.airlift.drift.client.guice.DriftClientBinder.java

@SuppressWarnings("unchecked")
private static <T> TypeLiteral<DriftClient<T>> driftClientTypeLiteral(Class<T> clientInterface) {
    Type javaType = new TypeToken<DriftClient<T>>() {
    }.where(new TypeParameter<T>() {
    }, TypeToken.of(clientInterface)).getType();
    return (TypeLiteral<DriftClient<T>>) TypeLiteral.get(javaType);
}

From source file:org.apache.beam.sdk.values.TypeDescriptors.java

/**
 * The {@link TypeDescriptor} for {@link Set}.
 * This is the equivalent of://from  www .  j  a va2 s. c  om
 * <pre>
 * new TypeDescriptor&lt;Set&lt;E&gt;&gt;() {};
 * </pre>
 *
 * <p>Example of use:
 * <pre>
 * {@code
 * PCollection<String> words = ...;
 * PCollection<Set<String>> words = words.apply(
 *            FlatMapElements.via(...)
 *            .withOutputType(TypeDescriptors.sets(TypeDescriptors.strings())));
 * }
 * </pre>
 * @param element The {@link TypeDescriptor} for the set
 * @return A {@link TypeDescriptor} for {@link Set}
 */
public static <T> TypeDescriptor<Set<T>> sets(TypeDescriptor<T> element) {
    TypeDescriptor<Set<T>> typeDescriptor = new TypeDescriptor<Set<T>>() {
    }.<T>where(new TypeParameter<T>() {
    }, element);

    return typeDescriptor;
}

From source file:org.elassandra.cqlinject.CqlClient.java

static <K, V> TypeToken<Map<K, V>> mapToken(TypeToken<K> keyToken, TypeToken<V> valueToken) {
    return new TypeToken<Map<K, V>>() {
    }.where(new TypeParameter<K>() {
    }, keyToken).where(new TypeParameter<V>() {
    }, valueToken);/*from   w w w  .j  a  va  2 s  .  c om*/
}

From source file:org.lanternpowered.server.data.key.LanternKeyFactory.java

public static <E> Key<ListValue<E>> makeListKey(TypeToken<E> elementToken, DataQuery query, String id,
        String name) {//from   w  w w  .  j  av a2 s  .co m
    final TypeToken<? extends List<E>> elementToken0 = new TypeToken<List<E>>() {
    }.where(new TypeParameter<E>() {
    }, elementToken);
    final TypeToken<ListValue<E>> valueToken = new TypeToken<ListValue<E>>() {
    }.where(new TypeParameter<E>() {
    }, elementToken);
    return makeListKey(elementToken0, valueToken, query, id, name);
}

From source file:org.elassandra.cqlinject.CqlClient.java

static <V> TypeToken<Set<V>> setToken(TypeToken<V> valueToken) {
    return new TypeToken<Set<V>>() {
    }.where(new TypeParameter<V>() {
    }, valueToken);/*  ww  w  .j a  v a 2 s.  c  o m*/
}

From source file:org.elassandra.cqlinject.CqlClient.java

static <V> TypeToken<List<V>> listToken(TypeToken<V> valueToken) {
    return new TypeToken<List<V>>() {
    }.where(new TypeParameter<V>() {
    }, valueToken);//from   w ww.j  a  v a  2 s .c o  m
}