public Object convertSingleTypeArray()

in src/main/java/org/apache/sling/jcr/contentparser/impl/ParserHelper.java [117:142]


    public Object convertSingleTypeArray(Object[] values) {
        if (values.length == 0) {
            return values;
        }
        Class<?> itemType = null;
        for (Object value : values) {
            if (value == null) {
                throw new ParseException("Multivalue array must not contain null values.");
            }
            if (value instanceof Map || value instanceof JsonObject) {
                throw new ParseException("Multivalue array must not contain maps/objects.");
            }
            if (itemType == null) {
                itemType = value.getClass();
            }
            else if (itemType != value.getClass()) {
                throw new ParseException("Multivalue array must not contain values with different types "
                        + "(" + itemType.getName() + ", " + value.getClass().getName() + ").");
            }
        }
        Object convertedArray = Array.newInstance(itemType, values.length);
        for (int i=0; i<values.length; i++) {
            Array.set(convertedArray, i, values[i]);
        }
        return convertedArray;
    }