Skip to content

Commit

Permalink
Polish contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Mar 27, 2023
1 parent 47aca90 commit 0c0cda9
Showing 1 changed file with 54 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* @author Andy Clement
* @author Juergen Hoeller
* @author Sam Brannen
* @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
* @author Harry Yang
* @since 3.0
*/
public class ConstructorReference extends SpelNodeImpl {
Expand Down Expand Up @@ -332,17 +332,17 @@ private TypedValue createArray(ExpressionState state) throws EvaluationException
throw new SpelEvaluationException(getStartPosition(), SpelMessage.INITIALIZER_LENGTH_INCORRECT);
}
}

newArray = switch (arrayTypeCode) {
case OBJECT -> createReferenceTypeArray(state, typeConverter, initializer.children, componentType);
case BOOLEAN -> createBooleanArray(state, typeConverter, initializer.children);
case BYTE -> createByteArray(state, typeConverter, initializer.children);
case CHAR -> createCharArray(state, typeConverter, initializer.children);
case DOUBLE -> createDoubleArray(state, typeConverter, initializer.children);
case FLOAT -> createFloatArray(state, typeConverter, initializer.children);
case BYTE -> createByteArray(state, typeConverter, initializer.children);
case SHORT -> createShortArray(state, typeConverter, initializer.children);
case INT -> createIntArray(state, typeConverter, initializer.children);
case LONG -> createLongArray(state, typeConverter, initializer.children);
case SHORT -> createShortArray(state, typeConverter, initializer.children);
case FLOAT -> createFloatArray(state, typeConverter, initializer.children);
case DOUBLE -> createDoubleArray(state, typeConverter, initializer.children);
default -> throw new IllegalStateException("Unsupported TypeCode: " + arrayTypeCode);
};
}
return new TypedValue(newArray);
Expand All @@ -355,88 +355,88 @@ private void checkNumElements(long numElements) {
}
}

private Object createReferenceTypeArray(ExpressionState state,
TypeConverter typeConverter, SpelNodeImpl[] children, Class<?> componentType) {
Object[] newArray = (Object[]) Array.newInstance(componentType, children.length);
TypeDescriptor toTypeDescriptor = TypeDescriptor.valueOf(componentType);
for (int i = 0; i < newArray.length; i++) {
Object arrayEntry = children[i].getValue(state);
newArray[i] = typeConverter.convertValue(arrayEntry,
TypeDescriptor.forObject(arrayEntry), toTypeDescriptor);
private Object createReferenceTypeArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children,
Class<?> componentType) {

Object[] array = (Object[]) Array.newInstance(componentType, children.length);
TypeDescriptor targetType = TypeDescriptor.valueOf(componentType);
for (int i = 0; i < array.length; i++) {
Object value = children[i].getValue(state);
array[i] = typeConverter.convertValue(value, TypeDescriptor.forObject(value), targetType);
}
return newArray;
return array;
}

private byte[] createByteArray(ExpressionState state, TypeConverter converter, SpelNodeImpl[] children) {
byte[] byteArray = new byte[children.length];
for (int i = 0; i < byteArray.length; i++) {
private boolean[] createBooleanArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
boolean[] array = new boolean[children.length];
for (int i = 0; i < array.length; i++) {
TypedValue typedValue = children[i].getTypedValue(state);
byteArray[i] = ExpressionUtils.toByte(converter, typedValue);
array[i] = ExpressionUtils.toBoolean(typeConverter, typedValue);
}
return byteArray;
return array;
}

private float[] createFloatArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
float[] floatArray = new float[children.length];
for (int i = 0; i < floatArray.length; i++) {
private char[] createCharArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
char[] array = new char[children.length];
for (int i = 0; i < array.length; i++) {
TypedValue typedValue = children[i].getTypedValue(state);
floatArray[i] = ExpressionUtils.toFloat(typeConverter, typedValue);
array[i] = ExpressionUtils.toChar(typeConverter, typedValue);
}
return floatArray;
return array;
}

private double[] createDoubleArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
double[] doubleArray = new double[children.length];
for (int i = 0; i < doubleArray.length; i++) {
private byte[] createByteArray(ExpressionState state, TypeConverter converter, SpelNodeImpl[] children) {
byte[] array = new byte[children.length];
for (int i = 0; i < array.length; i++) {
TypedValue typedValue = children[i].getTypedValue(state);
doubleArray[i] = ExpressionUtils.toDouble(typeConverter, typedValue);
array[i] = ExpressionUtils.toByte(converter, typedValue);
}
return doubleArray;
return array;
}

private short[] createShortArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
short[] shortArray = new short[children.length];
for (int i = 0; i < shortArray.length; i++) {
short[] array = new short[children.length];
for (int i = 0; i < array.length; i++) {
TypedValue typedValue = children[i].getTypedValue(state);
shortArray[i] = ExpressionUtils.toShort(typeConverter, typedValue);
array[i] = ExpressionUtils.toShort(typeConverter, typedValue);
}
return shortArray;
return array;
}

private long[] createLongArray(ExpressionState state, TypeConverter converter, SpelNodeImpl[] children) {
long[] longArray = new long[children.length];
for (int i = 0; i < longArray.length; i++) {
private int[] createIntArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
int[] array = new int[children.length];
for (int i = 0; i < array.length; i++) {
TypedValue typedValue = children[i].getTypedValue(state);
longArray[i] = ExpressionUtils.toLong(converter, typedValue);
array[i] = ExpressionUtils.toInt(typeConverter, typedValue);
}
return longArray;
return array;
}

private char[] createCharArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
char[] newCharArray = new char[children.length];
for (int i = 0; i < newCharArray.length; i++) {
private long[] createLongArray(ExpressionState state, TypeConverter converter, SpelNodeImpl[] children) {
long[] array = new long[children.length];
for (int i = 0; i < array.length; i++) {
TypedValue typedValue = children[i].getTypedValue(state);
newCharArray[i] = ExpressionUtils.toChar(typeConverter, typedValue);
array[i] = ExpressionUtils.toLong(converter, typedValue);
}
return newCharArray;
return array;
}

private boolean[] createBooleanArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
boolean[] newBooleanArray = new boolean[children.length];
for (int i = 0; i < newBooleanArray.length; i++) {
private float[] createFloatArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
float[] array = new float[children.length];
for (int i = 0; i < array.length; i++) {
TypedValue typedValue = children[i].getTypedValue(state);
newBooleanArray[i] = ExpressionUtils.toBoolean(typeConverter, typedValue);
array[i] = ExpressionUtils.toFloat(typeConverter, typedValue);
}
return newBooleanArray;
return array;
}

private int[] createIntArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
int[] intArray = new int[children.length];
for (int i = 0; i < intArray.length; i++) {
private double[] createDoubleArray(ExpressionState state, TypeConverter typeConverter, SpelNodeImpl[] children) {
double[] array = new double[children.length];
for (int i = 0; i < array.length; i++) {
TypedValue typedValue = children[i].getTypedValue(state);
intArray[i] = ExpressionUtils.toInt(typeConverter, typedValue);
array[i] = ExpressionUtils.toDouble(typeConverter, typedValue);
}
return intArray;
return array;
}

private boolean hasInitializer() {
Expand Down

0 comments on commit 0c0cda9

Please sign in to comment.