/*
* Copyright 2002-2019 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.
Author: Andy Clement
/**
* Captures primitive types and their corresponding class objects, plus one special entry
* that represents all reference (non-primitive) types.
*
* @author Andy Clement
*/
public enum TypeCode {
An Object
. /**
* An {@link Object}.
*/
OBJECT(Object.class),
A boolean
. /**
* A {@code boolean}.
*/
BOOLEAN(Boolean.TYPE),
A byte
. /**
* A {@code byte}.
*/
BYTE(Byte.TYPE),
A char
. /**
* A {@code char}.
*/
CHAR(Character.TYPE),
A double
. /**
* A {@code double}.
*/
DOUBLE(Double.TYPE),
A float
. /**
* A {@code float}.
*/
FLOAT(Float.TYPE),
An int
. /**
* An {@code int}.
*/
INT(Integer.TYPE),
A long
. /**
* A {@code long}.
*/
LONG(Long.TYPE),
An Object
. /**
* An {@link Object}.
*/
SHORT(Short.TYPE);
private Class<?> type;
TypeCode(Class<?> type) {
this.type = type;
}
public Class<?> getType() {
return this.type;
}
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];
}
}
return OBJECT;
}
public static TypeCode forClass(Class<?> clazz) {
TypeCode[] allValues = TypeCode.values();
for (TypeCode typeCode : allValues) {
if (clazz == typeCode.getType()) {
return typeCode;
}
}
return OBJECT;
}
}