public static Object getIndex()

in src/main/java/org/apache/sling/scripting/sightly/render/ObjectModel.java [362:387]


    public static Object getIndex(Object object, int index) {
        if (object == null) {
            return null;
        }

        // special handing for enum object
        if (object instanceof Class && ((Class<?>)object).isEnum()) {
            Class<?> cls = (Class<?>)object;
            if (index >= 0 && index < cls.getEnumConstants().length) {
                //find the enum constant whose ordinal matches the requested index
                return cls.getEnumConstants()[index];
            } else {
                return null;
            }
        }

        Class<?> cls = object.getClass();
        if (cls.isArray() && index >= 0 && index < Array.getLength(object)) {
            return Array.get(object, index);
        }
        Collection collection = toCollection(object);
        if (collection instanceof List && index >= 0 && index < collection.size()) {
            return ((List) collection).get(index);
        }
        return null;
    }