/** Returns the value of the indexed component in the supplied array. */ static public Object get (Object array, int index) { return java.lang.reflect.Array.get(array, index); }
public static Object[] createObjectArray(Object array) { if (array instanceof Object[]) { return (Object[]) array; } Object[] result = new Object[Array.getLength(array)]; for (int i = 0; i < Array.getLength(array); i++) { result[i] = Array.get(array, i); } return result; } }
@Override void apply(RequestBuilder builder, @Nullable Object values) throws IOException { if (values == null) return; // Skip null values. for (int i = 0, size = Array.getLength(values); i < size; i++) { //noinspection unchecked ParameterHandler.this.apply(builder, (T) Array.get(values, i)); } } };
/** Returns the value of the indexed component in the supplied array. */ static public Object get (Object array, int index) { return java.lang.reflect.Array.get(array, index); }
public Object next() { return Array.get(value, currentIndex++); }
/** * Check if the supplied value is the first entry in the array represented by the possibleArray value. * @param value the value to check for in the array * @param possibleArray an array object that may have the supplied value as the first element * @return true if the supplied value is the first entry in the array */ private static boolean isFirstEntryInArray(Object value, @Nullable Object possibleArray) { if (possibleArray == null) { return false; } Class<?> type = possibleArray.getClass(); if (!type.isArray() || Array.getLength(possibleArray) == 0 || !ClassUtils.isAssignableValue(type.getComponentType(), value)) { return false; } Object arrayValue = Array.get(possibleArray, 0); return (type.getComponentType().isPrimitive() ? arrayValue.equals(value) : arrayValue == value); }
@SuppressWarnings("unchecked") @Override public OUT extract(Object in) { return (OUT) Array.get(in, fieldId); }
@Override @Nullable public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } if (sourceType.isAssignableTo(targetType)) { return source; } if (Array.getLength(source) == 0) { return null; } Object firstElement = Array.get(source, 0); return this.conversionService.convert(firstElement, sourceType.elementTypeDescriptor(firstElement), targetType); }
@SuppressWarnings("unchecked") @Override public F get(T record) { return (F) Array.get(record, pos); }
private void addArrayValues(ParameterSignature sig, String name, List<PotentialAssignment> list, Object array) { for (int i = 0; i < Array.getLength(array); i++) { Object value = Array.get(array, i); if (sig.canAcceptValue(value)) { list.add(PotentialAssignment.forValue(name + "[" + i + "]", value)); } } }
@SuppressWarnings("unchecked") @Override public OUT[] extract(Object in) { OUT[] output = (OUT[]) Array.newInstance(clazz, order.length); for (int i = 0; i < order.length; i++) { output[i] = (OUT) Array.get(in, this.order[i]); } return output; }
private Object getToStringableArrayElement(Object array, int length, int index) { if (index < length) { Object element = Array.get(array, index); if (isArray(element)) { return objectWithToString(componentTypeName(element.getClass()) + "[" + Array.getLength(element) + "]"); } else { return element; } } else { return END_OF_ARRAY_SENTINEL; } }
@Override protected AnnotatedElement resolve(AnnotatedElement annotatedElement) { try { return (AnnotatedElement) Array.get(GET_ANNOTATED_BOUNDS.invoke(annotatedElement, NO_ARGUMENTS), index); } catch (ClassCastException ignored) { // To avoid bug on early releases of Java 8. return NoOp.INSTANCE; } catch (IllegalAccessException exception) { throw new IllegalStateException("Cannot access java.lang.reflect.AnnotatedTypeVariable#getAnnotatedBounds", exception); } catch (InvocationTargetException exception) { throw new IllegalStateException("Error invoking java.lang.reflect.AnnotatedTypeVariable#getAnnotatedBounds", exception.getCause()); } }
/** * {@inheritDoc} */ public AnnotatedElement resolve() { try { return (AnnotatedElement) Array.get(getAnnotatedInterfaces.invoke(type), index); } catch (IllegalAccessException exception) { throw new IllegalStateException("Cannot access java.lang.Class#getAnnotatedInterfaces", exception); } catch (InvocationTargetException exception) { throw new IllegalStateException("Error invoking java.lang.Class#getAnnotatedInterfaces", exception.getCause()); } } }
/** * {@inheritDoc} */ public AnnotatedElement resolve() { try { return (AnnotatedElement) Array.get(getAnnotatedParameterTypes.invoke(executable, NO_ARGUMENTS), index); } catch (IllegalAccessException exception) { throw new IllegalStateException("Cannot access java.lang.reflect.Executable#getAnnotatedParameterTypes", exception); } catch (InvocationTargetException exception) { throw new IllegalStateException("Error invoking java.lang.reflect.Executable#getAnnotatedParameterTypes", exception.getCause()); } } }
@Override protected AnnotatedElement resolve(AnnotatedElement annotatedElement) { try { return (AnnotatedElement) Array.get(GET_ANNOTATED_LOWER_BOUNDS.invoke(annotatedElement, NO_ARGUMENTS), index); } catch (ClassCastException ignored) { // To avoid bug on early releases of Java 8. return NoOp.INSTANCE; } catch (IllegalAccessException exception) { throw new IllegalStateException("Cannot access java.lang.reflect.AnnotatedWildcardType#getAnnotatedLowerBounds", exception); } catch (InvocationTargetException exception) { throw new IllegalStateException("Error invoking java.lang.reflect.AnnotatedWildcardType#getAnnotatedLowerBounds", exception.getCause()); } } }
@Override protected String toString(Object array, int index) { return ForNonArrayType.STRING.toString(Array.get(array, index)); } };
@Override public Tuple getKey(IN value) { Tuple key = Tuple.newInstance(fields.length); for (int i = 0; i < fields.length; i++) { key.setField(Array.get(value, fields[i]), i); } return key; }
@Test public void SPR10452() { SpelParserConfiguration configuration = new SpelParserConfiguration(false, false); ExpressionParser parser = new SpelExpressionParser(configuration); StandardEvaluationContext context = new StandardEvaluationContext(); Expression spel = parser.parseExpression("#enumType.values()"); context.setVariable("enumType", ABC.class); Object result = spel.getValue(context); assertNotNull(result); assertTrue(result.getClass().isArray()); assertEquals(ABC.A, Array.get(result, 0)); assertEquals(ABC.B, Array.get(result, 1)); assertEquals(ABC.C, Array.get(result, 2)); context.setVariable("enumType", XYZ.class); result = spel.getValue(context); assertNotNull(result); assertTrue(result.getClass().isArray()); assertEquals(XYZ.X, Array.get(result, 0)); assertEquals(XYZ.Y, Array.get(result, 1)); assertEquals(XYZ.Z, Array.get(result, 2)); }