jodd-bean/src/main/java/jodd/typeconverter/impl/ArrayConverter.java
protected T[] convertValueToArray(final Object value) {
		if (value instanceof Collection) {
			Collection collection = (Collection) value;
			T[] target = createArray(collection.size());

			int i = 0;
			for (Object element : collection) {
				target[i] = convertType(element);
				i++;
			}

			return target;
		}

		if (value instanceof Iterable) {
			Iterable iterable = (Iterable) value;
			List<T> list = new ArrayList<>();

			for (Object element : iterable) {
				list.add(convertType(element));
			}

			T[] target = createArray(list.size());
			return list.toArray(target);
		}

		if (value instanceof CharSequence) {
			String[] strings = convertStringToArray(value.toString());
			return convertArrayToArray(strings);
		}

		// everything else:
		return convertToSingleElementArray(value);
	}
protected T[] convertValueToArray(final Object value) {
		if (value instanceof Collection) {
			Collection collection = (Collection) value;
			T[] target = createArray(collection.size());

			int i = 0;
			for (Object element : collection) {
				target[i] = convertType(element);
				i++;
			}

			return target;
		}

		if (value instanceof Iterable) {
			Iterable iterable = (Iterable) value;
			List<T> list = new ArrayList<>();

			for (Object element : iterable) {
				list.add(convertType(element));
			}

			T[] target = createArray(list.size());
			return list.toArray(target);
		}

		if (value instanceof CharSequence) {
			String[] strings = convertStringToArray(value.toString());
			return convertArrayToArray(strings);
		}

		// everything else:
		return convertToSingleElementArray(value);
	}
protected T [ ] convertValueToArray ( final Object value ) { if ( value instanceof Collection ) { Collection collection = ( Collection ) value ; T [ ] target = createArray ( collection . size ( ) ) ; int i = 0 ; for ( Object element : collection ) { target [ i ] = convertType ( element ) ; i ++ ; } return target ; } if ( value instanceof Iterable ) { Iterable iterable = ( Iterable ) value ; List < T > list = new ArrayList <> ( ) ; for ( Object element : iterable ) { list . add ( convertType ( element ) ) ; } T [ ] target = createArray ( list . size ( ) ) ; return list . toArray ( target ) ; } if ( value instanceof CharSequence ) { String [ ] strings = convertStringToArray ( value . toString ( ) ) ; return convertArrayToArray ( strings ) ; } // everything else: return convertToSingleElementArray ( value ) ; }
Converts non-array value to array. Detects various
collection types and iterates them to make conversion
and to create target array.
Converts non - array value to array . Detects various collection types and iterates them to make conversion and to create target array .