/** Sets the value of the indexed component in the supplied array to the supplied value. */ static public void set (Object array, int index, Object value) { java.lang.reflect.Array.set(array, index, value); }
/** Sets the value of the indexed component in the supplied array to the supplied value. */ static public void set (Object array, int index, Object value) { java.lang.reflect.Array.set(array, index, value); }
@Override public T set(T record, F fieldValue) { Array.set(record, pos, fieldValue); return record; } }
@Override public void write( Object value ) { Array.set( array, index++, value ); }
@Override public void write( Object value ) { Array.set( array, index, value ); index++; }
private Object convertDataArrayToTargetArray(Object[] array, Class<?> targetClass) throws NoSuchMethodException { Class<?> targetType = targetClass.getComponentType(); Method fromMethod = targetType.getMethod("from", array.getClass().getComponentType()); Object resultArray = Array.newInstance(targetType, array.length); for (int i = 0; i < array.length; i++) { Array.set(resultArray, i, ReflectionUtils.invokeMethod(fromMethod, null, array[i])); } return resultArray; }
private static <T> T copy( Object[] value, T target ) { for ( int i = 0; i < value.length; i++ ) { if ( value[i] == null ) { throw new IllegalArgumentException( "Property array value elements may not be null." ); } Array.set( target, i, value[i] ); } return target; }
@SuppressWarnings( "unchecked" ) public RECORD[] newBatchObject( int batchSize ) { Object array = Array.newInstance( klass, batchSize ); for ( int i = 0; i < batchSize; i++ ) { Array.set( array, i, factory.get() ); } return (RECORD[]) array; }
/** * For each element in the managed array, resolve reference if necessary. */ private Object resolveManagedArray(Object argName, List<?> ml, Class<?> elementType) { Object resolved = Array.newInstance(elementType, ml.size()); for (int i = 0; i < ml.size(); i++) { Array.set(resolved, i, resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i))); } return resolved; }
private Object convertDataArrayToTargetArray(Object[] array, Class<?> targetClass) throws NoSuchMethodException { Class<?> targetType = targetClass.getComponentType(); Method fromMethod = targetType.getMethod("from", array.getClass().getComponentType()); Object resultArray = Array.newInstance(targetType, array.length); for (int i = 0; i < array.length; i++) { Array.set(resultArray, i, ReflectionUtils.invokeMethod(fromMethod, null, array[i])); } return resultArray; }
/** * {@inheritDoc} */ public W[] resolve() { @SuppressWarnings("unchecked") W[] array = (W[]) Array.newInstance(componentType, values.size()); int index = 0; for (AnnotationValue.Loaded<?> annotationValue : values) { Array.set(array, index++, annotationValue.resolve()); } return array; }
/** * {@inheritDoc} */ public Object[] resolve() { Object[] array = (Object[]) Array.newInstance(componentType, values.size()); int index = 0; for (AnnotationValue.Loaded<?> annotationValue : values) { Array.set(array, index++, annotationValue.resolve()); } return array; }
/** * {@inheritDoc} */ public U[] resolve() { @SuppressWarnings("unchecked") U[] resolved = (U[]) Array.newInstance(unloadedComponentType, values.size()); int index = 0; for (AnnotationValue<?, ?> value : values) { Array.set(resolved, index++, value.resolve()); } return resolved; }
@Override @Nullable public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } TypeDescriptor targetElementType = targetType.getElementTypeDescriptor(); Assert.state(targetElementType != null, "No target element type"); Object target = Array.newInstance(targetElementType.getType(), 1); Object targetElement = this.conversionService.convert(source, sourceType, targetElementType); Array.set(target, 0, targetElement); return target; }
@Override @Nullable public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } String string = (String) source; String[] fields = StringUtils.commaDelimitedListToStringArray(string); TypeDescriptor targetElementType = targetType.getElementTypeDescriptor(); Assert.state(targetElementType != null, "No target element type"); Object target = Array.newInstance(targetElementType.getType(), fields.length); for (int i = 0; i < fields.length; i++) { String sourceElement = fields[i]; Object targetElement = this.conversionService.convert(sourceElement.trim(), sourceType, targetElementType); Array.set(target, i, targetElement); } return target; }
/** * Sets the array element forced. If index is greater then arrays length, array will be expanded to the index. * If speed is critical, it is better to allocate an array with proper size before using this method. */ protected void arrayForcedSet(BeanProperty bp, Object array, int index, Object value) { Class componentType = array.getClass().getComponentType(); array = ensureArraySize(bp, array, componentType, index); value = convertType(value, componentType); Array.set(array, index, value); }
private Object growArrayIfNecessary(Object array, int index, String name) { if (!isAutoGrowNestedPaths()) { return array; } int length = Array.getLength(array); if (index >= length && index < this.autoGrowCollectionLimit) { Class<?> componentType = array.getClass().getComponentType(); Object newArray = Array.newInstance(componentType, index + 1); System.arraycopy(array, 0, newArray, 0, length); for (int i = length; i < Array.getLength(newArray); i++) { Array.set(newArray, i, newValue(componentType, null, name)); } setPropertyValue(name, newArray); Object defaultValue = getPropertyValue(name); Assert.state(defaultValue != null, "Default value must not be null"); return defaultValue; } else { return array; } }
@Override @Nullable public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } Collection<?> sourceCollection = (Collection<?>) source; TypeDescriptor targetElementType = targetType.getElementTypeDescriptor(); Assert.state(targetElementType != null, "No target element type"); Object array = Array.newInstance(targetElementType.getType(), sourceCollection.size()); int i = 0; for (Object sourceElement : sourceCollection) { Object targetElement = this.conversionService.convert(sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetElementType); Array.set(array, i++, targetElement); } return array; }
private Object array( int length, Class<?> componentType ) { Object array = Array.newInstance( componentType, length ); for ( int i = 0; i < length; i++ ) { Array.set( array, i, createNew( componentType ) ); } return array; }
@Override public Object read( ReadableClosableChannel from ) throws IOException { ValueType componentType = typeOf( from.get() ); int length = from.getInt(); Object value = Array.newInstance( componentType.componentClass(), length ); for ( int i = 0; i < length; i++ ) { Array.set( value, i, componentType.read( from ) ); } return value; }