List of usage examples for com.google.common.reflect TypeToken wrap
public final TypeToken<T> wrap()
From source file:ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection.java
@SuppressWarnings("unchecked") public <T> TypeSerializer<T> get(TypeToken<T> type) { Preconditions.checkNotNull(type, "type"); type = type.wrap(); TypeSerializer<?> serial = typeMatches.get(type); if (serial == null) { for (Map.Entry<TypeToken<?>, TypeSerializer<?>> ent : typeMatches.entrySet()) { if (ent.getKey().isAssignableFrom(type)) { serial = ent.getValue(); typeMatches.put(type, serial); break; }//from w w w .ja v a 2 s. c o m } } if (serial == null) { for (Map.Entry<Predicate<TypeToken<?>>, TypeSerializer<?>> ent : functionMatches.entrySet()) { if (ent.getKey().test(type)) { serial = ent.getValue(); typeMatches.put(type, serial); break; } } } if (serial == null && parent != null) { serial = parent.get(type); } return (TypeSerializer) serial; }
From source file:com.datastax.driver.core.TypeCodec.java
/** * Return {@code true} if this codec is capable of serializing * the given {@code javaType}.//from www . jav a 2 s. c om * <p/> * The implementation is <em>invariant</em> with respect to the passed * argument (through the usage of {@link TypeToken#equals(Object)} * and <em>it's strongly recommended not to modify this behavior</em>. * This means that a codec will only ever return {@code true} for the * <em>exact</em> Java type that it has been created for. * <p/> * If the argument represents a Java primitive type, its wrapper type * is considered instead. * * @param javaType The Java type this codec should serialize from and deserialize to; cannot be {@code null}. * @return {@code true} if the codec is capable of serializing * the given {@code javaType}, and {@code false} otherwise. * @throws NullPointerException if {@code javaType} is {@code null}. */ public boolean accepts(TypeToken javaType) { checkNotNull(javaType, "Parameter javaType cannot be null"); return this.javaType.equals(javaType.wrap()); }