public TypeManifest(@Nullable TypeLiteral<T> nullableType) { this.typeToken = nullableType != null ? Types.toToken(nullableType) : new TypeToken<T>(getClass()){}; this.type = nullableType != null ? nullableType : Types.toLiteral(typeToken); Types.assertFullySpecified(this.type); this.typeParameter = new TypeParameter<T>(){}; this.typeArg = new TypeArgument<T>(this.type){}; TypeResolver resolver = new TypeResolver(); for(Class<?> cls = getClass(); cls != null; cls = cls.getSuperclass()) { if(cls.getTypeParameters().length > 0) { resolver = resolver.where(cls.getTypeParameters()[0], type.getType()); } } this.resolver = resolver; }
@Inject ModelMeta(TypeLiteral<M> completeType, TypeLiteral<P> partialType, Provider<Optional<ModelStore<M>>> store) { this.partialType = Types.toToken(partialType); this.completeType = Types.toToken(completeType); partialUpdateType = assertFullySpecified(new TypeToken<PartialModelUpdate<P>>(){}.where(new TypeParameter<P>(){}, this.partialType)); completeUpdateType = assertFullySpecified(new TypeToken<ModelUpdate<M>>(){}.where(new TypeParameter<M>(){}, this.completeType)); multiResponseType = assertFullySpecified(new TypeToken<FindMultiResponse<M>>(){}.where(new TypeParameter<M>(){}, this.completeType)); this.store = store; final ModelName annot = completeType.getRawType().getAnnotation(ModelName.class); if(annot != null) { name = annot.value(); singularName = annot.singular().length() > 0 ? annot.singular() : name.toLowerCase(); pluralName = annot.plural().length() > 0 ? annot.plural() : StringUtils.pluralize(singularName); } else { name = completeType.getRawType().getSimpleName(); singularName = name.toLowerCase(); pluralName = StringUtils.pluralize(singularName); } }
private <T> void checkParameterizedSchema(Schema schema, Class<T> type) { assertThat(schema).isEqualTo(Schema.builder() .setName("Parameterized_" + type.getSimpleName()) .setType("object") .addField("foo", Field.builder() .setName("foo") .setType(FieldType.fromType(TypeToken.of(type))) .build()) .addField("next", Field.builder() .setName("next") .setType(FieldType.OBJECT) .setSchemaReference( SchemaReference.create(repo, config, new TypeToken<Parameterized<T>>() {} .where(new TypeParameter<T>() {}, TypeToken.of(type)))) .build()) .addField("testEnum", Field.builder() .setName("testEnum") .setType(FieldType.ENUM) .setSchemaReference(SchemaReference.create(repo, config, TypeToken.of(TestEnum.class))) .build()) .build()); }
/** * @param nodeType The type of values associated with nodes * @param edgeType The type of value associated with edges * @param nodeList Creates the list of nodes * @param edgeList Creates the list of edges */ public DefaultObservableGraph(TypeToken<N> nodeType, TypeToken<E> edgeType, CollectionCreator<Node<N, E>, ObservableList<Node<N, E>>> nodeList, CollectionCreator<Edge<N, E>, ObservableList<Edge<N, E>>> edgeList) { theLock = new ReentrantReadWriteLock(); theSessionController = new DefaultTransactable(theLock); theNodeController = nodeList.create( new TypeToken<Node<N, E>>() {}.where(new TypeParameter<N>() {}, nodeType).where(new TypeParameter<E>() {}, edgeType), theLock, theSessionController.getSession(), theSessionController); theNodes = theNodeController.immutable(); theEdgeController = edgeList.create( new TypeToken<Edge<N, E>>() {}.where(new TypeParameter<N>() {}, nodeType).where(new TypeParameter<E>() {}, edgeType), theLock, theSessionController.getSession(), theSessionController); theEdges = theEdgeController.immutable(); }
public static <K, V> ThriftType map(ThriftTypeReference keyTypeReference, ThriftTypeReference valueTypeReference) { requireNonNull(keyTypeReference, "keyTypeReference is null"); requireNonNull(valueTypeReference, "valueTypeReference is null"); @SuppressWarnings("serial") Type javaType = new TypeToken<Map<K, V>>() {} .where(new TypeParameter<K>() {}, (TypeToken<K>) TypeToken.of(keyTypeReference.getJavaType())) .where(new TypeParameter<V>() {}, (TypeToken<V>) TypeToken.of(valueTypeReference.getJavaType())) .getType(); return new ThriftType(ThriftProtocolType.MAP, javaType, keyTypeReference, valueTypeReference); }
public static <E> ThriftType set(ThriftTypeReference valueTypeReference) { requireNonNull(valueTypeReference, "valueTypeReference is null"); @SuppressWarnings("serial") Type javaType = new TypeToken<Set<E>>() {} .where(new TypeParameter<E>() {}, (TypeToken<E>) TypeToken.of(valueTypeReference.getJavaType())) .getType(); return new ThriftType(ThriftProtocolType.SET, javaType, null, valueTypeReference); }
public static <E> ThriftType list(ThriftTypeReference valueTypeReference) { requireNonNull(valueTypeReference, "valueTypeReference is null"); @SuppressWarnings("serial") Type javaType = new TypeToken<List<E>>() {} .where(new TypeParameter<E>() {}, (TypeToken<E>) TypeToken.of(valueTypeReference.getJavaType())) .getType(); return new ThriftType(ThriftProtocolType.LIST, javaType, null, valueTypeReference); }
@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); }
@SuppressWarnings("unchecked") private <E> TypeToken<List<E>> getListTokenFromSet(TypeToken<?> type) { // Get the inner type out of the type token TypeToken<?> innerType = getInnerToken(type); // Put it into the new list token return new TypeToken<List<E>>() {}.where(new TypeParameter<E>() {}, (TypeToken<E>)innerType); }
private static <T> TypeToken<List<T>> listOfElements(Class<T> elementType) { @SuppressWarnings("serial") TypeToken<List<T>> genericList = new TypeToken<List<T>>() { // Reifies T }; return genericList.where( new TypeParameter<T>() { // Reifires T }, elementType); }
@Override public <T> MembersInjector<T> getMembersInjector(TypeToken<T> typeLiteral) { TypeToken<MembersInjector<T>> injectorType = new TypeToken<MembersInjector<T>>() { private static final long serialVersionUID = 1L; }.where(new TypeParameter<T>() { }, typeLiteral); return getInstance(DependencyKey.of(injectorType)); }
@Override public <T> MembersInjector<T> getMembersInjector( TypeLiteral<T> typeLiteral) { TypeToken<MembersInjector<T>> injectorType = new TypeToken<MembersInjector<T>>() { private static final long serialVersionUID = 1L; }.where(new TypeParameter<T>() { }, typeLiteral.getTypeToken()); return delegate.getInstance(DependencyKey.of(injectorType)); }
@SuppressWarnings("serial") public static <T> TypeToken<List<T>> listOf(final TypeToken<T> entityType) { final TypeToken<List<T>> listType = new TypeToken<List<T>>() { // nothing to implement! }; final TypeParameter<T> elementType = new TypeParameter<T>() { // nothing to implement! }; return listType.where(elementType, entityType); }
public static <T> TypeToken<ResponseEntity<T>> responseEntityOf(final TypeToken<T> entityType) { final TypeToken<ResponseEntity<T>> responseEntityType = new TypeToken<ResponseEntity<T>>() { // nothing to implement! }; final TypeParameter<T> elementType = new TypeParameter<T>() { // nothing to implement! }; return responseEntityType.where(elementType, entityType); }
/** * Creates specialized stream {@link TypeToken type token} for the given element {@link TypeToken type token}. Used * to declare the expected stream response {@link TypeToken type token} in Riptide {@link org.zalando.riptide.Route route} as follows: * * <pre> * on(...).call(streamOf(resultTypeToken),...) * </pre> * * @param type element token type. * @return stream token type. */ @SuppressWarnings("serial") public static <T> TypeToken<Stream<T>> streamOf(final TypeToken<T> type) { final TypeToken<Stream<T>> streamType = new TypeToken<Stream<T>>() { // no overriding needed. }; final TypeParameter<T> elementType = new TypeParameter<T>() { // no overriding needed. }; return streamType.where(elementType, type); }
public static <K, V> Key<MapValue<K, V>> makeMapKeyWithKeyAndValue(TypeToken<K> keyToken, TypeToken<V> valueToken, DataQuery query, String id, String name) { final TypeToken<MapValue<K, V>> valueToken0 = new TypeToken<MapValue<K, V>>() {} .where(new TypeParameter<K>() {}, keyToken) .where(new TypeParameter<V>() {}, valueToken); return new LanternKeyBuilder<>().type(valueToken0).query(query).id(id).name(name).build(); }
private <T> void bindService(Class<T> clazz) { final TypeToken<Service<T>> token = new TypeToken<Service<T>>() {} .where(new TypeParameter<T>() {}, clazz); final TypeLiteral literal = TypeLiteral.get(token.getType()); //noinspection unchecked bindAndExpose(literal).toProvider(ServiceObjectProvider.class); }
private static <K, V> Type mapOf(Class<K> keyClass, Class<V> valueClass) { return new TypeToken<Map<K, V>>() {} .where(new TypeParameter<K>() {}, TypeToken.of(keyClass)) .where(new TypeParameter<V>() {}, TypeToken.of(valueClass)) .getType(); }
static <K, V> TypeToken<Map<K, V>> mapOf( Class<K> keyType, Class<V> valueType) { return new TypeToken<Map<K, V>>() { /** * */ private static final long serialVersionUID = 5781653436802867344L;} .where(new TypeParameter<K>() {}, keyType) .where(new TypeParameter<V>() {}, valueType); }
static <K, V> TypeToken<Map<K, V>> mapOf(TypeToken<K> keyType, TypeToken<V> valueType) { return new TypeToken<Map<K, V>>() { /** * */ private static final long serialVersionUID = 5781653436802867344L; } .where(new TypeParameter<K>() { }, keyType) .where(new TypeParameter<V>() { }, valueType); }
/** * Executes the request, returning the full response body * * @return Body containing the "data" object and other metadata * @throws IOException */ public ResultBody<T> executeRaw() throws IOException { HttpResponse response = this.client.request(this); return Json.getInstance().fromJson( new InputStreamReader(response.getContent()), new TypeToken<ResultBody<T>>() { }.where( new TypeParameter<T>() { }, this.elementClass ).getType() ); }
/** * Executes the request, returning the full response body * * @return Body containing the "data" object and other metadata * @throws IOException */ public ResultBodyCollection<T> executeRaw() throws IOException { HttpResponse response = this.client.request(this); return Json.getInstance().fromJson( new InputStreamReader(response.getContent()), new com.google.common.reflect.TypeToken<ResultBodyCollection<T>>() { }.where( new TypeParameter<T>() { }, this.elementClass ).getType() ); }
public <T> ResourceCollection<T> jsonToResourceCollection(String jsonInput, Class<T> resourceType) { try { Type type = new TypeToken<ResourceCollection<T>>() {} .where(new TypeParameter<T>() {}, TypeToken.of(resourceType)).getType(); LOGGER.info("JSON successfully converted to a resource collection of {}", resourceType.getSimpleName()); return this.gson().fromJson(jsonInput, type); } catch (final JsonParseException e) { throw new SDKInternalException(SDKErrorEnum.internalError, "An error occurred while converting JSON input to resource collection", e); } }
/** * @param <N> The type of node values in the graph * @param <E> The type of edge values in the graph * @param nodeType The node type for the graph * @param edgeType The edge type for the graph * @return An empty graph */ static <N, E> ObservableGraph<N, E> empty(TypeToken<N> nodeType, TypeToken<E> edgeType) { return new ObservableGraph<N, E>() { @Override public ObservableCollection<Node<N, E>> getNodes() { return org.observe.collect.ObservableSet.constant( new TypeToken<Node<N, E>>() {}.where(new TypeParameter<N>() {}, nodeType).where(new TypeParameter<E>() {}, edgeType)); } @Override public ObservableCollection<Edge<N, E>> getEdges() { return org.observe.collect.ObservableSet.constant( new TypeToken<Edge<N, E>>() {}.where(new TypeParameter<N>() {}, nodeType).where(new TypeParameter<E>() {}, edgeType)); } @Override public ObservableValue<CollectionSession> getSession() { return ObservableValue.constant(TypeToken.of(CollectionSession.class), null); } @Override public Transaction lock(boolean write, Object cause) { return () -> { }; } @Override public boolean isSafe() { return true; } }; }
/** * @param keyType The key type of the set * @param valueType The value type of the set * @param compare The comparator to sort the keys * @return The default collection creator for entry sets in this sorted multi map class */ public static <K, V> CollectionCreator<ObservableSortedMultiEntry<K, V>, ObservableSortedSet<ObservableSortedMultiEntry<K, V>>> defaultCreator( TypeToken<K> keyType, TypeToken<V> valueType, Comparator<? super K> compare) { return new CollectionCreator<ObservableSortedMultiEntry<K, V>, ObservableSortedSet<ObservableSortedMultiEntry<K, V>>>() { @Override public ObservableSortedSet<ObservableSortedMultiEntry<K, V>> create(TypeToken<ObservableSortedMultiEntry<K, V>> type, ReentrantReadWriteLock lock, ObservableValue<CollectionSession> session, Transactable sessionController) { TypeToken<ObservableSortedMultiEntry<K, V>> setType = new TypeToken<ObservableSortedMultiEntry<K, V>>() {} .where(new TypeParameter<K>() {}, keyType).where(new TypeParameter<V>() {}, valueType); return new ObservableTreeSet<>(setType, lock, session, sessionController, (entry1, entry2) -> compare.compare(entry1.getKey(), entry2.getKey())); } }; }
/** * @param keyType The type of key used by this map * @param valueType The type of value stored in this map * @param entrySet Creates the set to store this collection's entries */ public <E extends ObservableMultiEntry<K, V>> ObservableMultiMapImpl(TypeToken<K> keyType, TypeToken<V> valueType, CollectionCreator<E, ? extends ObservableSet<E>> entrySet) { this(keyType, valueType, new TypeToken<E>() {}.where(new TypeParameter<K>() {}, keyType).where(new TypeParameter<V>() {}, valueType), entrySet, (key, keyTyp, valueTyp, lock, session, controller) -> new DefaultMultiMapEntry<>(key, keyType, valueType, lock, session, controller)); }
/** * @param keyType The key type of the set * @param valueType The value type of the set * @param compare The comparator to sort the keys * @return The default collection creator for entry sets in this sorted map class */ public static <K, V> CollectionCreator<ObservableEntry<K, V>, ObservableSet<ObservableEntry<K, V>>> defaultCreator(TypeToken<K> keyType, TypeToken<V> valueType, Comparator<? super K> compare) { return new CollectionCreator<ObservableEntry<K, V>, ObservableSet<ObservableEntry<K, V>>>() { @Override public ObservableSet<ObservableEntry<K, V>> create(TypeToken<ObservableEntry<K, V>> type, ReentrantReadWriteLock lock, ObservableValue<CollectionSession> session, Transactable sessionController) { TypeToken<ObservableEntry<K, V>> setType = new TypeToken<ObservableEntry<K, V>>() {} .where(new TypeParameter<K>() {}, keyType).where(new TypeParameter<V>() {}, valueType); return new ObservableTreeSet<>(setType, lock, session, sessionController, (entry1, entry2) -> compare.compare(entry1.getKey(), entry2.getKey())); } }; }
/** * @param keyType The type of key used by this map * @param valueType The type of value stored in this map * @param entrySet Creates the set to hold this map's entries */ public ObservableMapImpl(TypeToken<K> keyType, TypeToken<V> valueType, CollectionCreator<ObservableEntry<K, V>, ObservableSet<ObservableEntry<K, V>>> entrySet) { theKeyType = keyType.wrap(); theValueType = valueType.wrap(); theLock=new ReentrantReadWriteLock(); theSessionController = new DefaultTransactable(theLock); theSession = ((DefaultTransactable) theSessionController).getSession(); theEntries = entrySet.create( new TypeToken<ObservableEntry<K, V>>() {}.where(new TypeParameter<K>() {}, theKeyType).where(new TypeParameter<V>() {}, theValueType), theLock, theSession, theSessionController); }
/** * @param keyType The type of key used by this map * @param valueType The type of value stored in this map * @param entrySet Creates the set to hold this map's entries * @param lock The lock for this map to use * @param session The session observable for this map * @param sessionController The session controller for this map */ public ObservableMapImpl(TypeToken<K> keyType, TypeToken<V> valueType, CollectionCreator<ObservableEntry<K, V>, ObservableSet<ObservableEntry<K, V>>> entrySet, ReentrantReadWriteLock lock, ObservableValue<CollectionSession> session, Transactable sessionController) { theKeyType = keyType.wrap(); theValueType = valueType.wrap(); theLock = lock; theSession = session; theSessionController = sessionController; theEntries = entrySet.create(new TypeToken<ObservableEntry<K, V>>() {}.where(new TypeParameter<K>() {}, theKeyType) .where(new TypeParameter<V>() {}, theValueType), theLock, theSession, theSessionController); }
/** @return This collection, as an observable value containing an immutable collection */ default ObservableValue<Collection<E>> asValue() { ObservableCollection<E> outer = this; return new ObservableValue<Collection<E>>() { final TypeToken<Collection<E>> theType = new TypeToken<Collection<E>>() {}.where(new TypeParameter<E>() {}, outer.getType()); @Override public TypeToken<Collection<E>> getType() { return theType; } @Override public Collection<E> get() { return Collections.unmodifiableCollection(new ArrayList<>(outer)); } @Override public Subscription subscribe(Observer<? super ObservableValueEvent<Collection<E>>> observer) { Collection<E> [] value = new Collection[] {get()}; observer.onNext(createInitialEvent(value[0])); return outer.simpleChanges().act(v -> { Collection<E> old = value[0]; value[0] = get(); observer.onNext(createChangeEvent(old, value[0], null)); }); } @Override public boolean isSafe() { return outer.isSafe(); } }; }
UniqueElement(CollectionWrappingSet<E> set, boolean alwaysUseFirst) { theSet = set; isAlwaysUsingFirst = alwaysUseFirst; theElements = createElements(); theCurrentElement = new SimpleSettableValue<>( new TypeToken<ObservableElement<E>>() {}.where(new TypeParameter<E>() {}, theSet.getType()), true); }
/** * @param <T> The supertype of elements in the lists * @param type The super type of all possible lists in the outer list * @param lists The lists to flatten * @return An observable list that contains all the values of the given lists */ public static <T> ObservableList<T> flattenLists(TypeToken<T> type, ObservableList<? extends T>... lists) { type = type.wrap(); if(lists.length == 0) return constant(type); ObservableList<ObservableList<T>> wrapper = constant(new TypeToken<ObservableList<T>>() {}.where(new TypeParameter<T>() {}, type), (ObservableList<T>[]) lists); return flatten(wrapper); }
static <T> Key<ProvisionWrapper<T>> keyOf(TypeLiteral<T> type) { return Key.get(new ResolvableType<ProvisionWrapper<T>>(){}.where(new TypeParameter<T>(){}, type)); }
protected OptionalAggregator(TypeToken<T> innerType) { super(innerType, new TypeToken<Optional<T>>(){}.where(new TypeParameter<T>(){}, innerType)); }
protected ListAggregator(TypeToken<T> innerType) { super(innerType, new TypeToken<List<T>>(){}.where(new TypeParameter<T>(){}, innerType)); }
protected SetAggregator(TypeToken<T> innerType) { super(innerType, new TypeToken<Set<T>>(){}.where(new TypeParameter<T>(){}, innerType)); }
static <T> TypeToken<ElementParser<T>> typeOf(TypeToken<T> type) { return new TypeToken<ElementParser<T>>(){}.where(new TypeParameter<T>(){}, type); }
static <T> TypeToken<PrimitiveParser<T>> typeOf(TypeToken<T> type) { return new TypeToken<PrimitiveParser<T>>(){}.where(new TypeParameter<T>(){}, type); }
/** * Return a {@link TypeLiteral} describing the required renderer type for the given component type */ public static <T extends BaseComponent> TypeLiteral<ComponentRenderer<? super T>> rendererType(Class<T> componentType) { return Types.resolve(new TypeLiteral<ComponentRenderer<? super T>>(){}, new TypeParameter<T>(){}, componentType); }
public <X> TypeLiteral<T> where(TypeParameter<X> parameter, TypeLiteral<X> type) { return where(parameter, Types.toToken(type)); }