Polish TypeCode

This commit is contained in:
Sam Brannen 2023-03-27 19:07:07 +02:00
parent ec270c7135
commit ddd6b123bb
1 changed files with 21 additions and 22 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,10 +17,11 @@
package org.springframework.expression.spel.ast; package org.springframework.expression.spel.ast;
/** /**
* Captures primitive types and their corresponding class objects, plus one special entry * Captures primitive types and their corresponding class objects, plus one special
* that represents all reference (non-primitive) types. * {@link #OBJECT} entry that represents all reference (non-primitive) types.
* *
* @author Andy Clement * @author Andy Clement
* @author Sam Brannen
*/ */
public enum TypeCode { public enum TypeCode {
@ -34,25 +35,20 @@ public enum TypeCode {
*/ */
BOOLEAN(Boolean.TYPE), BOOLEAN(Boolean.TYPE),
/**
* A {@code byte}.
*/
BYTE(Byte.TYPE),
/** /**
* A {@code char}. * A {@code char}.
*/ */
CHAR(Character.TYPE), CHAR(Character.TYPE),
/** /**
* A {@code double}. * A {@code byte}.
*/ */
DOUBLE(Double.TYPE), BYTE(Byte.TYPE),
/** /**
* A {@code float}. * A {@code short}.
*/ */
FLOAT(Float.TYPE), SHORT(Short.TYPE),
/** /**
* An {@code int}. * An {@code int}.
@ -65,12 +61,17 @@ public enum TypeCode {
LONG(Long.TYPE), LONG(Long.TYPE),
/** /**
* An {@link Object}. * A {@code float}.
*/ */
SHORT(Short.TYPE); FLOAT(Float.TYPE),
/**
* A {@code double}.
*/
DOUBLE(Double.TYPE);
private Class<?> type; private final Class<?> type;
TypeCode(Class<?> type) { TypeCode(Class<?> type) {
@ -84,19 +85,17 @@ public enum TypeCode {
public static TypeCode forName(String name) { public static TypeCode forName(String name) {
TypeCode[] tcs = values(); for (TypeCode typeCode : values()) {
for (int i = 1; i < tcs.length; i++) { if (typeCode.name().equalsIgnoreCase(name)) {
if (tcs[i].name().equalsIgnoreCase(name)) { return typeCode;
return tcs[i];
} }
} }
return OBJECT; return OBJECT;
} }
public static TypeCode forClass(Class<?> clazz) { public static TypeCode forClass(Class<?> clazz) {
TypeCode[] allValues = TypeCode.values(); for (TypeCode typeCode : values()) {
for (TypeCode typeCode : allValues) { if (typeCode.getType() == clazz) {
if (clazz == typeCode.getType()) {
return typeCode; return typeCode;
} }
} }