/** * Returns true if the type is a collection type. */ default boolean isCollectionType() { return getTypeInfo().isCollectionType(); }
protected boolean validateMap(String name, Map map, Validation validation, int maxErrors) { TypeInfo typeInfo = null; for(Object item : map.entrySet()) { Map.Entry entry = (Map.Entry)item; Object value = entry.getValue(); if(null == value) { continue; } if(null == typeInfo) { typeInfo = Types.getTypeInfo(value.getClass()); } if(typeInfo.isComplexType() || typeInfo.isCollectionType()) { String fullName = Strings.nullToEmpty(name) + "['" + entry.getKey().toString() + "']"; if(!validate(fullName, value, validation, maxErrors) ){ return false; } } else { return true; } } return true; }
protected boolean validateArray(String name, Object[] array, Validation validation, int maxErrors) { TypeInfo typeInfo = null; for(int i=0;i<array.length;i++) { Object value = array[i]; if(value == null) { continue; } if(typeInfo == null) { typeInfo = Types.getTypeInfo(value.getClass()); } if(typeInfo.isComplexType() || typeInfo.isCollectionType()) { String fullName = Strings.nullToEmpty(name) + "[" + String.valueOf(i) + "]"; if(!validate(fullName, value, validation, maxErrors) ){ return false; } } else { return true; } } return true; }
protected boolean validateCollection(String name, Iterable iterable, Validation validation, int maxErrors) { int i=0; TypeInfo typeInfo = null; for(Object value : iterable) { if(value == null) { continue; } if(typeInfo == null) { typeInfo = Types.getTypeInfo(value.getClass()); } if(typeInfo.isComplexType() || typeInfo.isCollectionType()) { String fullName = Strings.nullToEmpty(name) + "[" + String.valueOf(i) + "]"; if(!validate(fullName, value, validation, maxErrors) ){ return false; } } else { return true; } i++; } return true; }
public static OpenType of(TypeInfo ti) { if(ti.getType() == Void.class || ti.getType() == Void.TYPE) { return SimpleType.VOID; } if(ti.isSimpleType()) { return forSimpleType(ti.getType()); } if(ti.isCollectionType()) { try { return new ArrayType(1, of(ti.getElementTypeInfo())); } catch (OpenDataException e) { throw new MException("Invalid array type", e); } } return forCompositeType(ti.getType()); }