class ReflectionHelper {

	public static Object getIndexedValue(Object value, String index) {
		if ( value == null ) {
			return null;
		}

		// try to create the index
		int numIndex = -1;
		try {
			numIndex = Integer.valueOf( index );
		}
		catch ( NumberFormatException nfe ) {
			// ignore
		}

		if ( numIndex == -1 ) {  // must be a map indexed by string
			Map<?, ?> map = ( Map<?, ?> ) value;
			//noinspection SuspiciousMethodCalls
			return map.get( index );
		}

		Iterator<?> iter = null;
		Type type = value.getClass();
		if ( isIterable( type ) ) {
			iter = ( ( Iterable<?> ) value ).iterator();
		}
		else if ( isMap( type ) ) {
			Map<?, ?> map = ( Map<?, ?> ) value;
			iter = map.values().iterator();
		}
		else if ( TypeUtils.isArray( type ) ) {
			List<?> arrayList = Arrays.asList( value );
			iter = arrayList.iterator();
		}

		int i = 0;
		Object o;
		while ( iter.hasNext() ) {
			o = iter.next();
			if ( i == numIndex ) {
				return o;
			}
			i++;
		}
		return null;
	}

	private  ReflectionHelper();

}