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:ratpack.render.Renderer.java

/**
 * Creates a type token for a <i>compatible</i> renderer of the given type of object.
 *
 * @param toRender the type that the renderer renders
 * @param <T> the type that the renderer renders
 * @return a type token for a <i>compatible</i> renderer of the given type of object
 *//*from  w w w .  j  a  v a2s.  co m*/
static <T> TypeToken<Renderer<? super T>> typeCompatibleOf(T toRender) {
    Class<T> clazz = Types.cast(toRender.getClass());
    return new TypeToken<Renderer<? super T>>(clazz) {
    }.where(new TypeParameter<T>() {
    }, clazz);
}

From source file:ratpack.exec.util.Types.java

/**
 * Creates a type token for a promise of the given type.
 *
 * <pre class="java">{@code/*w  ww .  j  a  v  a  2  s  . c  om*/
 * import ratpack.exec.util.Types;
 * import ratpack.exec.Promise;
 * import com.google.common.reflect.TypeToken;
 *
 * import java.util.List;
 *
 * import static org.junit.Assert.*;
 *
 * public class Example {
 *   public static void main(String... args) {
 *     assertEquals(
 *       Types.promiseOf(new TypeToken<List<String>>() {}),
 *       new TypeToken<Promise<List<String>>>() {}
 *     );
 *   }
 * }
 * }</pre>
 *
 * @param type the promise element type
 * @param <T> the promise element type
 * @return a type token for a promise of of the given type.
 */
public static <T> TypeToken<Promise<T>> promiseOf(TypeToken<T> type) {
    return new TypeToken<Promise<T>>() {
    }.where(new TypeParameter<T>() {
    }, type);
}

From source file:com.datastax.driver.core.TypeTokens.java

/**
 * Create a {@link TypeToken} that represents a {@link Set} whose elements
 * are of the given type./*ww w .  j  a va2s. co  m*/
 *
 * @param eltType The set element type.
 * @param <T>     The set element type.
 * @return A {@link TypeToken} that represents a {@link Set} whose elements
 * are of the given type.
 */
public static <T> TypeToken<Set<T>> setOf(Class<T> eltType) {
    // @formatter:off
    return new TypeToken<Set<T>>() {
    }.where(new TypeParameter<T>() {
    }, eltType);
    // @formatter:on
}

From source file:co.cask.tigon.internal.app.AbstractSpecificationCodec.java

protected final <V> JsonElement serializeMap(Map<String, V> map, JsonSerializationContext context,
        Class<V> valueType) {
    Type type = new TypeToken<Map<String, V>>() {
    }.where(new TypeParameter<V>() {
    }, valueType).getType();/*w w w .  j a v a2 s.  c  o m*/
    return context.serialize(map, type);
}

From source file:org.apache.brooklyn.core.config.SetConfigKey.java

@SuppressWarnings("serial")
private static <V> TypeToken<Set<V>> typeTokenFor(TypeToken<V> subType) {
    return new TypeToken<Set<V>>() {
    }.where(new TypeParameter<V>() {
    }, subType);//from w  w  w  .j a v a2 s  . c om
}

From source file:edu.washington.cs.cupid.wizards.internal.AbstractMapping.java

@Override
public final TypeToken<Map<K, Set<V>>> getOutputType() {
    return new TypeToken<Map<K, Set<V>>>(getClass()) {
    }.where(new TypeParameter<K>() {
    }, keyType).where(new TypeParameter<V>() {
    }, valueType);//from   w  w w.ja v  a  2s.  c  o  m
}

From source file:com.facebook.presto.server.smile.SmileCodec.java

public static <K, V> SmileCodec<Map<K, V>> mapSmileCodec(Class<K> keyType, Class<V> valueType) {
    requireNonNull(keyType, "keyType is null");
    requireNonNull(valueType, "valueType is null");

    Type mapType = new TypeToken<Map<K, V>>() {
    }.where(new TypeParameter<K>() {
    }, keyType).where(new TypeParameter<V>() {
    }, valueType).getType();//from  w  w w  .  j  a  va  2 s.c  o m

    return new SmileCodec<>(OBJECT_MAPPER_SUPPLIER.get(), mapType);
}

From source file:com.datastax.driver.extras.codecs.guava.OptionalCodec.java

public OptionalCodec(TypeCodec<T> codec, Predicate<T> isAbsent) {
    // @formatter:off
    super(codec, new TypeToken<Optional<T>>() {
    }.where(new TypeParameter<T>() {
    }, codec.getJavaType()));//from  ww w  .j  ava  2s. c om
    // @formatter:on
    this.isAbsent = isAbsent;
}

From source file:com.facebook.swift.codec.metadata.ThriftType.java

public static <K, V> ThriftType map(ThriftType keyType, ThriftType valueType) {
    checkNotNull(keyType, "keyType is null");
    checkNotNull(valueType, "valueType is null");

    @SuppressWarnings("serial")
    Type javaType = new TypeToken<Map<K, V>>() {
    }.where(new TypeParameter<K>() {
    }, (TypeToken<K>) TypeToken.of(keyType.getJavaType())).where(new TypeParameter<V>() {
    }, (TypeToken<V>) TypeToken.of(valueType.getJavaType())).getType();
    return new ThriftType(ThriftProtocolType.MAP, javaType, keyType, valueType);
}

From source file:com.datastax.driver.extras.codecs.jdk8.OptionalCodec.java

public OptionalCodec(TypeCodec<T> codec, java.util.function.Predicate<T> isAbsent) {
    // @formatter:off
    super(codec, new TypeToken<java.util.Optional<T>>() {
    }.where(new TypeParameter<T>() {
    }, codec.getJavaType()));//from ww  w  .j a  v  a2  s  . c  om
    // @formatter:on
    this.isAbsent = isAbsent;
}