protected Optional<FormYourCollectionResource> findListableYourCollection(PropertyDesc pd, FormMappingOption option) { final Class<?> propertyType = pd.getPropertyType(); final List<FormYourCollectionResource> yourCollections = option.getYourCollections(); return yourCollections.stream() // checking defined type and instance type .filter(res -> propertyType.equals(res.getYourType())) // just type in form mapping (to avoid complexity) .filter(res -> res.getYourCollectionCreator().apply(Collections.emptyList()) instanceof List) .findFirst(); // basically only-one here (if no duplicate type specified) }
protected Optional<FormYourCollectionResource> findListableYourCollection(PropertyDesc pd, FormMappingOption option) { final Class<?> propertyType = pd.getPropertyType(); final List<FormYourCollectionResource> yourCollections = option.getYourCollections(); return yourCollections.stream() // checking defined type and instance type .filter(res -> propertyType.equals(res.getYourType())) // just type in form mapping (to avoid complexity) .filter(res -> res.getYourCollectionCreator().apply(Collections.emptyList()) instanceof List) .findFirst(); // basically only-one here (if no duplicate type specified) }
protected Object prepareYourCollection(VirtualForm virtualForm, Object bean, String name, Object value, StringBuilder pathSb, FormMappingOption option, PropertyDesc pd) { final List<FormYourCollectionResource> yourCollections = option.getYourCollections(); if (yourCollections.isEmpty()) { return null; // no settings of your collections } final Class<?> propertyType = pd.getPropertyType(); for (FormYourCollectionResource yourCollection : yourCollections) { if (!propertyType.equals(yourCollection.getYourType())) { // just type in form mapping (to avoid complexity) continue; } final List<?> objectList = prepareObjectList(virtualForm, bean, name, value, pathSb, option, pd); final Iterable<? extends Object> applied = yourCollection.getYourCollectionCreator().apply(objectList); final Object mappedValue; if (applied instanceof List<?>) { mappedValue = applied; } else { final List<Object> newList = new ArrayList<>(); for (Object element : applied) { newList.add(element); } mappedValue = newList; } return mappedValue; } return null; // is not your collections }
protected Object prepareYourCollection(VirtualForm virtualForm, Object bean, String name, Object value, StringBuilder pathSb, FormMappingOption option, PropertyDesc pd) { final List<FormYourCollectionResource> yourCollections = option.getYourCollections(); if (yourCollections.isEmpty()) { return null; // no settings of your collections } final Class<?> propertyType = pd.getPropertyType(); for (FormYourCollectionResource yourCollection : yourCollections) { if (!propertyType.equals(yourCollection.getYourType())) { // just type in form mapping (to avoid complexity) continue; } final List<?> objectList = prepareObjectList(virtualForm, bean, name, value, pathSb, option, pd); final Iterable<? extends Object> applied = yourCollection.getYourCollectionCreator().apply(objectList); final Object mappedValue; if (applied instanceof List<?>) { mappedValue = applied; } else { final List<Object> newList = new ArrayList<>(); for (Object element : applied) { newList.add(element); } mappedValue = newList; } return mappedValue; } return null; // is not your collections }