@Override public boolean accept(Type type, Class<?> clazz) { if (clazz == null) { return false; } return clazz.isArray(); }
@Override public boolean accept(Type type, Class<?> clazz) { if (clazz == null) { return false; } return clazz.isArray(); }
/** * Returns '{@code true}' for arrays, {@link Collection Collections} * and {@link Map Maps}. */ private static boolean typeRequiresMultiple(Class<?> type) { return (type.isArray() || Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)); }
/** * Determine whether the given object is an array: * either an Object array or a primitive array. * @param obj the object to check */ public static boolean isArray(@Nullable Object obj) { return (obj != null && obj.getClass().isArray()); }
/** * Determine if the object needs wrap * * @param clazz object type * @return need wrap */ public static boolean needWrapper(Class<?> clazz) { return WrapperUtils.WRAPPER_SET.contains(clazz) || clazz.isArray() || clazz.isEnum(); }
/** * Determine if the object needs wrap * * @param clazz object type * @return need wrap */ public static boolean needWrapper(Class<?> clazz) { return WrapperUtils.WRAPPER_SET.contains(clazz) || clazz.isArray() || clazz.isEnum(); }
/** * Check if the given class represents an array of primitives, * i.e. boolean, byte, char, short, int, long, float, or double. * @param clazz the class to check * @return whether the given class is a primitive array class */ public static boolean isPrimitiveArray(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); return (clazz.isArray() && clazz.getComponentType().isPrimitive()); }
@Override Type usedInGenericType(Type type) { checkNotNull(type); if (type instanceof Class) { Class<?> cls = (Class<?>) type; if (cls.isArray()) { return new GenericArrayTypeImpl(cls.getComponentType()); } } return type; } },
/** * Is this type an array type? */ public boolean isArray() { return getType().isArray(); }
@Override public void printValue(String label, @Nullable Object value) { if (value != null && value.getClass().isArray()) { value = CollectionUtils.arrayToList(value); } writer.println(String.format("%17s = %s", label, value)); } });
private void appendType(StringBuilder sb, Class<?> type, boolean useLongTypeName) { if (type.isArray()) { appendType(sb, type.getComponentType(), useLongTypeName); sb.append("[]"); } else { sb.append(useLongTypeName ? type.getName() : type.getSimpleName()); } } }
private boolean isBindingCandidate(String name, @Nullable Object value) { return (!name.startsWith(BindingResult.MODEL_KEY_PREFIX) && value != null && !value.getClass().isArray() && !(value instanceof Collection) && !(value instanceof Map) && !BeanUtils.isSimpleValueType(value.getClass())); }
/** * Check if the given class represents an array of primitive wrappers, * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double. * @param clazz the class to check * @return whether the given class is a primitive wrapper array class */ public static boolean isPrimitiveWrapperArray(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); return (clazz.isArray() && isPrimitiveWrapper(clazz.getComponentType())); }
private static boolean isPrimitives(Class<?> cls) { if (cls.isArray()) { return isPrimitive(cls.getComponentType()); } return isPrimitive(cls); }
public static boolean isPrimitives(Class<?> cls) { if (cls.isArray()) { return isPrimitive(cls.getComponentType()); } return isPrimitive(cls); }
/** * Return {@code true} if this type resolves to a Class that represents an array. * @see #getComponentType() */ public boolean isArray() { if (this == NONE) { return false; } return ((this.type instanceof Class && ((Class<?>) this.type).isArray()) || this.type instanceof GenericArrayType || resolveType().isArray()); }
@Override protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException { Class<?> clazz = desc.forClass(); if (clazz.isPrimitive() || clazz.isArray()) { write(0); super.writeClassDescriptor(desc); } else { write(1); writeUTF(desc.getName()); } } }
@Override protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException { Class<?> clazz = desc.forClass(); if (clazz.isPrimitive() || clazz.isArray()) { write(0); super.writeClassDescriptor(desc); } else { write(1); writeUTF(desc.getName()); } } }
@Test public void testBeanPropertyIsArray() { PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(ContainerBean.class); for (PropertyDescriptor descriptor : descriptors) { if ("containedBeans".equals(descriptor.getName())) { assertTrue("Property should be an array", descriptor.getPropertyType().isArray()); assertEquals(descriptor.getPropertyType().getComponentType(), ContainedBean.class); } } }
@Test public void arrayClassType() throws Exception { ResolvableType type = ResolvableType.forField(Fields.class.getField("arrayClassType")); assertThat(type.getType(), instanceOf(Class.class)); assertThat(((Class) type.getType()).isArray(), equalTo(true)); }