/** * Get child node at specified index. Child node type depends on {@link #componentType}. * * @param childIndex child index. * @return child node at requested index. * @throws IllegalArgumentException if child index argument is not a numeric value. */ @Override public Node getChild(String childIndex) throws IllegalArgumentException { Params.isNumeric(childIndex, "Child index"); int index = Integer.parseInt(childIndex); ensureCapacity(index, componentType); return FormObject.this.factory.createNode(list.get(index), componentType); }
/** * Set value to child node identified by given child index. Given string value is converted to list component type, see * {@link #componentType} using {@link Converter}. * * @param childIndex child index, * @param value string value, null and empty accepted, loaded from field. * @throws IllegalArgumentException if child index argument is not a numeric value. * @throws ConverterException if field value conversion fails. */ @Override public void setValue(String childIndex, Object value) throws IllegalArgumentException, ConverterException { Params.isNumeric(childIndex, "Child index"); int index = Integer.parseInt(childIndex); ensureCapacity(index); if (!String.class.equals(componentType)) { value = converter.asObject((String) value, componentType); } list.set(index, value); }
/** * Get child node at specified index, creating it on the fly if missing. Child node type depends on * {@link #componentType}. * * @param childIndex child index. * @return child node at requested index, freshly created or reused from array. * @throws IllegalArgumentException if child index argument is not a numeric value. */ @Override public Node getChild(String childIndex) throws IllegalArgumentException { Params.isNumeric(childIndex, "Child index"); int index = Integer.parseInt(childIndex); Object item = Array.get(array, index); if (item == null) { Array.set(array, index, item = FormObject.this.factory.newInstance(componentType)); } return FormObject.this.factory.createNode(item, componentType); }
/** * Set value to child specified by given index. If child index exceeds array length this setter does nothing and value * is ignored. * <p> * Given string value is converted to array type, see {@link #componentType} using {@link Converter}. * * @param childIndex node child index, * @param value string value, null and empty accepted, loaded from field. * @throws IllegalArgumentException if child index argument is not a numeric value. * @throws ConverterException if field value conversion fails. */ @Override public void setValue(String childIndex, Object value) throws IllegalArgumentException, ConverterException { Params.isNumeric(childIndex, "Child index"); int index = Integer.parseInt(childIndex); if (index >= Array.getLength(array)) { log.debug("Array capacity exceeded. Ingore value |%s| for array index |%d|.", value, index); return; } if (!String.class.equals(componentType)) { value = converter.asObject((String) value, componentType); } Array.set(array, index, value); } }