Polish TypeCode
This commit is contained in:
parent
ec270c7135
commit
ddd6b123bb
|
|
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -17,10 +17,11 @@
|
|||
package org.springframework.expression.spel.ast;
|
||||
|
||||
/**
|
||||
* Captures primitive types and their corresponding class objects, plus one special entry
|
||||
* that represents all reference (non-primitive) types.
|
||||
* Captures primitive types and their corresponding class objects, plus one special
|
||||
* {@link #OBJECT} entry that represents all reference (non-primitive) types.
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public enum TypeCode {
|
||||
|
||||
|
|
@ -34,25 +35,20 @@ public enum TypeCode {
|
|||
*/
|
||||
BOOLEAN(Boolean.TYPE),
|
||||
|
||||
/**
|
||||
* A {@code byte}.
|
||||
*/
|
||||
BYTE(Byte.TYPE),
|
||||
|
||||
/**
|
||||
* A {@code char}.
|
||||
*/
|
||||
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}.
|
||||
|
|
@ -65,12 +61,17 @@ public enum TypeCode {
|
|||
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) {
|
||||
|
|
@ -84,19 +85,17 @@ public enum TypeCode {
|
|||
|
||||
|
||||
public static TypeCode forName(String name) {
|
||||
TypeCode[] tcs = values();
|
||||
for (int i = 1; i < tcs.length; i++) {
|
||||
if (tcs[i].name().equalsIgnoreCase(name)) {
|
||||
return tcs[i];
|
||||
for (TypeCode typeCode : values()) {
|
||||
if (typeCode.name().equalsIgnoreCase(name)) {
|
||||
return typeCode;
|
||||
}
|
||||
}
|
||||
return OBJECT;
|
||||
}
|
||||
|
||||
public static TypeCode forClass(Class<?> clazz) {
|
||||
TypeCode[] allValues = TypeCode.values();
|
||||
for (TypeCode typeCode : allValues) {
|
||||
if (clazz == typeCode.getType()) {
|
||||
for (TypeCode typeCode : values()) {
|
||||
if (typeCode.getType() == clazz) {
|
||||
return typeCode;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue