private Object handleBasic()

in bval-jsr/src/main/java/org/apache/bval/jsr/job/ValidateProperty.java [400:434]


        private Object handleBasic(Object o, String indexOrKey) {
            if (Map.class.isInstance(o)) {
                for (Map.Entry<?, ?> e : ((Map<?, ?>) o).entrySet()) {
                    if (String.valueOf(e.getKey()).equals(indexOrKey)) {
                        return e.getValue();
                    }
                }
            } else {
                try {
                    final int index = Integer.parseInt(indexOrKey);
                    if (index < 0) {
                        Exceptions.raise(IllegalArgumentException::new, "Invalid index %d", index);
                    }
                    if (o != null && TypeUtils.isArrayType(o.getClass())) {
                        if (Array.getLength(o) > index) {
                            return Array.get(o, index);
                        }
                    } else if (List.class.isInstance(o)) {
                        final List<?> l = (List<?>) o;
                        if (l.size() > index) {
                            return l.get(index);
                        }
                    } else if (Iterable.class.isInstance(o)) {
                        int i = -1;
                        for (Object e : (Iterable<?>) o) {
                            if (++i == index) {
                                return e;
                            }
                        }
                    }
                } catch (NumberFormatException e) {
                }
            }
            return null;
        }