Exceptions.raise(IllegalArgumentException::new, "Invalid index %d", index); if (o != null && TypeUtils.isArrayType(o.getClass())) { if (Array.getLength(o) > index) { return Array.get(o, index);
Exceptions.raise(IllegalArgumentException::new, "Invalid index %d", index); if (o != null && TypeUtils.isArrayType(o.getClass())) { if (Array.getLength(o) > index) { return Array.get(o, index);
private Step handleElementByType(Type type) { Type elementType; if (TypeUtils.isArrayType(type)) { elementType = TypeUtils.getArrayComponentType(type); } else if (TypeUtils.isAssignable(type, Map.class)) { elementType = Optional.ofNullable(TypeUtils.getTypeArguments(type, Map.class).get(MAP_VALUE)).orElse(MAP_VALUE); } else if (TypeUtils.isAssignable(type, Iterable.class)) { elementType = Optional.ofNullable(TypeUtils.getTypeArguments(type, Iterable.class).get(ITERABLE_ELEMENT)) .orElse(ITERABLE_ELEMENT); } else { throw Exceptions.create(IllegalArgumentException::new, "Unable to resolve element type of %s", type); } return new TypeWrapper(validatorContext, elementType); }
private Step handleElementByType(Type type) { Type elementType; if (TypeUtils.isArrayType(type)) { elementType = TypeUtils.getArrayComponentType(type); } else if (TypeUtils.isAssignable(type, Map.class)) { elementType = Optional.ofNullable(TypeUtils.getTypeArguments(type, Map.class).get(MAP_VALUE)).orElse(MAP_VALUE); } else if (TypeUtils.isAssignable(type, Iterable.class)) { elementType = Optional.ofNullable(TypeUtils.getTypeArguments(type, Iterable.class).get(ITERABLE_ELEMENT)) .orElse(ITERABLE_ELEMENT); } else { throw Exceptions.create(IllegalArgumentException::new, "Unable to resolve element type of %s", type); } return new TypeWrapper(validatorContext, elementType); }
/** * Get the Java element type of a particular container type. * * @param containerType * @return Type or <code>null</code> if <code>containerType</code> is not * some type of {@link Iterable} or array */ public static Type getJavaElementType(Type containerType) { if (TypeUtils.isArrayType(containerType)) { return TypeUtils.getArrayComponentType(containerType); } if (TypeUtils.isAssignable(containerType, Iterable.class)) { Map<TypeVariable<?>, Type> typeArguments = TypeUtils.getTypeArguments(containerType, Iterable.class); Type type = TypeUtils.unrollVariables(typeArguments, ITERABLE_TYPE); return type != null ? type : Object.class; } return null; }