@SuppressWarnings("unchecked") public static final <E> Enumerable<E> of(Object object) throws IllegalArgumentException { Enumerable<E> e = tryOf(object); if(null == e) { throw new IllegalArgumentException("not a supported enumerable type '" + object.getClass().getName() + "'"); } return e; }
@SuppressWarnings("unchecked") public static final <E> Enumerable<E> tryOf(Object object) throws IllegalArgumentException { if(null == object){ return empty(); } if(object instanceof Enumerable){ return (Enumerable<E>)object; } if(object instanceof List){ return new ListEnumerable<E>((List<E>)object); } if(object instanceof Collection){ return new CollectionEnumerable<>((Collection<E>)object); } Class<?> clazz = object.getClass(); if(clazz.isArray()){ if(clazz.getComponentType().isPrimitive()){ return new ArrayObjectIterable<E>(object); }else{ return ofArray((E[])object); } } if(object instanceof Iterable){ return new IterableEnumerable<E>((Iterable<E>)object); } return null; }
protected static Object getArrayProperty(Object object,int index){ return Enumerables.of(object).get(index); }
public void calcIdsByEmbeddedField(Set<Object> ids, Record record, String embeddedFieldName) { Object embeddedIds = record.get(embeddedFieldName); if (null != embeddedIds) { Enumerable<Object> enumerable = Enumerables.tryOf(embeddedIds); if (null == enumerable) { throw new BadRequestException("The embedded ids must be array at field '" + embeddedFieldName + "'"); } for (Object item : enumerable) { if (!ids.contains(item)) { ids.add(item); } } } }
protected boolean validateArray(Validation validation, String name, Object value) { if(validated.hasArrayValidation()) { return doValidateArray(validation, name, Enumerables.of(value)); } return true; }
Enumerable e = Enumerables.tryOf(v); if (null == e) { relationProperties.put(rp, new Object[]{v});
static Object convert(Object value, OpenType targetType) { if(null == value) { return null; } if(targetType instanceof SimpleType) { return value; } if(targetType instanceof CompositeType) { CompositeType ct = (CompositeType)targetType; try { return convertToCompositeData(value, ct); } catch (OpenDataException e) { throw new MException(e); } } if(targetType instanceof ArrayType) { ArrayType at = (ArrayType)targetType; OpenType elementType = at.getElementOpenType(); if(elementType instanceof SimpleType) { return Enumerables.of(value).toList(); } List<Object> list = new ArrayList<>(); for(Object item : Enumerables.of(value)) { list.add(convert(item, elementType)); } return list; } //todo : support throw new IllegalStateException("Not supported open type '" + targetType + "'"); }
Enumerable e = Enumerables.tryOf(v); if(null == e) { relationProperties.put(rp, new Object[]{v});
List expandedList = new ArrayList(); if (null != embeddedIds) { for (Object embeddedId : Enumerables.of(embeddedIds)) { Map expandedRecord = totalExpandedMap.get(embeddedId); if (null != expandedRecord) {
stm.addParameter(null); }else{ Enumerable<Object> c = Enumerables.tryOf(value); if(c == null) { stm.append(JDBC.PARAMETER_PLACEHOLDER_CHAR);
@Override protected boolean doValidate(Validation validation, String name, Object value, Out<Object> out) { Enumerable e; try { e = Enumerables.of(value); }catch (IllegalArgumentException ex) { validation.addError(name, "The value must be an array or collection"); return false; } if(null != arrayValidator && !arrayValidator.doValidateArray(validation, name, e)) { return false; } if(null != elementValidator) { int i=0; for(Object element : e) { if(!elementValidator.validate(validation, name + "[" + i + "]", element, Out.empty())) { return false; } i++; } } return true; }
List expandedList = new ArrayList(); if (null != embeddedIds) { for (Object embeddedId : Enumerables.of(embeddedIds)) { Record expandedRecord = totalExpandedMap.get(embeddedId); if (null != expandedRecord) {