/** * Returns the {@link TypeInformation} for the given raw super type. * * @param superType must not be {@literal null}. * @return the {@link TypeInformation} for the given raw super type. * @throws IllegalArgumentException in case the current {@link TypeInformation} does not implement the given type. * @since 2.0 */ default TypeInformation<?> getRequiredSuperTypeInformation(Class<?> superType) { TypeInformation<?> result = getSuperTypeInformation(superType); if (result == null) { throw new IllegalArgumentException(String.format( "Can't retrieve super type information for %s! Does current type really implement the given one?", superType)); } return result; }
public boolean isAssignableFrom(TypeInformation<?> target) { TypeInformation<?> superTypeInformation = target.getSuperTypeInformation(getType()); return superTypeInformation == null ? false : superTypeInformation.equals(this); }
public boolean isAssignableFrom(TypeInformation<?> target) { return target.getSuperTypeInformation(getType()).equals(this); }
@Nullable public TypeInformation<?> getSuperTypeInformation(Class<?> superType) { Class<?> rawType = getType(); if (!superType.isAssignableFrom(rawType)) { return null; } if (getType().equals(superType)) { return this; } List<Type> candidates = new ArrayList<>(); Type genericSuperclass = rawType.getGenericSuperclass(); if (genericSuperclass != null) { candidates.add(genericSuperclass); } candidates.addAll(Arrays.asList(rawType.getGenericInterfaces())); for (Type candidate : candidates) { TypeInformation<?> candidateInfo = createInfo(candidate); if (superType.equals(candidateInfo.getType())) { return candidateInfo; } else { TypeInformation<?> nestedSuperType = candidateInfo.getSuperTypeInformation(superType); if (nestedSuperType != null) { return nestedSuperType; } } } return null; }
public TypeInformation<?> getSuperTypeInformation(Class<?> superType) { Class<?> type = getType(); if (!superType.isAssignableFrom(type)) { return null; } if (getType().equals(superType)) { return this; } List<Type> candidates = new ArrayList<Type>(); Type genericSuperclass = type.getGenericSuperclass(); if (genericSuperclass != null) { candidates.add(genericSuperclass); } candidates.addAll(Arrays.asList(type.getGenericInterfaces())); for (Type candidate : candidates) { TypeInformation<?> candidateInfo = createInfo(candidate); if (superType.equals(candidateInfo.getType())) { return candidateInfo; } else { TypeInformation<?> nestedSuperType = candidateInfo.getSuperTypeInformation(superType); if (nestedSuperType != null) { return nestedSuperType; } } } return null; }
@Override public boolean isAssignableFrom(TypeInformation<?> target) { if (this.equals(target)) { return true; } Class<T> rawType = getType(); Class<?> rawTargetType = target.getType(); if (!rawType.isAssignableFrom(rawTargetType)) { return false; } TypeInformation<?> otherTypeInformation = rawType.equals(rawTargetType) ? target : target.getSuperTypeInformation(rawType); List<TypeInformation<?>> myParameters = getTypeArguments(); List<TypeInformation<?>> typeParameters = otherTypeInformation == null ? Collections.emptyList() : otherTypeInformation.getTypeArguments(); if (myParameters.size() != typeParameters.size()) { return false; } for (int i = 0; i < myParameters.size(); i++) { if (!myParameters.get(i).isAssignableFrom(typeParameters.get(i))) { return false; } } return true; }
@Override public boolean isAssignableFrom(TypeInformation<?> target) { if (this.equals(target)) { return true; } Class<T> rawType = getType(); Class<?> rawTargetType = target.getType(); if (!rawType.isAssignableFrom(rawTargetType)) { return false; } TypeInformation<?> otherTypeInformation = rawType.equals(rawTargetType) ? target : target .getSuperTypeInformation(rawType); List<TypeInformation<?>> myParameters = getTypeArguments(); List<TypeInformation<?>> typeParameters = otherTypeInformation.getTypeArguments(); if (myParameters.size() != typeParameters.size()) { return false; } for (int i = 0; i < myParameters.size(); i++) { if (!myParameters.get(i).isAssignableFrom(typeParameters.get(i))) { return false; } } return true; }
@Override @Nullable public Object readValue(@Nullable Object value, TypeInformation<?> type) { if (null == value) { return null; } if (getConversions().hasCustomReadTarget(value.getClass(), type.getType())) { return getConversionService().convert(value, type.getType()); } if (AggregateReference.class.isAssignableFrom(type.getType())) { TypeInformation<?> idType = type.getSuperTypeInformation(AggregateReference.class).getTypeArguments().get(1); return AggregateReference.to(readValue(value, idType)); } return super.readValue(value, type); }