本文整理汇总了Java中com.holonplatform.core.internal.utils.TypeUtils.isEnum方法的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils.isEnum方法的具体用法?Java TypeUtils.isEnum怎么用?Java TypeUtils.isEnum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.holonplatform.core.internal.utils.TypeUtils
的用法示例。
在下文中一共展示了TypeUtils.isEnum方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkParameterValue
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
* Check the given view parameter value, performing type conversions when applicable.
* @param view View instance
* @param definition Parameter definition
* @param value Parameter value
* @return Processed parameter value
* @throws ViewConfigurationException Error processing value
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Object checkParameterValue(View view, ViewParameterDefinition definition, Object value)
throws ViewConfigurationException {
if (value != null) {
// String
if (TypeUtils.isString(definition.getType()) && !TypeUtils.isString(value.getClass())) {
return value.toString();
}
if (!TypeUtils.isString(definition.getType()) && TypeUtils.isString(value.getClass())) {
return ConversionUtils.convertStringValue((String) value, definition.getType());
}
// Numbers
if (TypeUtils.isNumber(definition.getType()) && TypeUtils.isNumber(value.getClass())) {
return ConversionUtils.convertNumberToTargetClass((Number) value, (Class<Number>) definition.getType());
}
// Enums
if (TypeUtils.isEnum(definition.getType()) && !TypeUtils.isEnum(value.getClass())) {
return ConversionUtils.convertEnumValue((Class<Enum>) definition.getType(), value);
}
// check type consistency
if (!TypeUtils.isAssignable(value.getClass(), definition.getType())) {
throw new ViewConfigurationException("Value type " + value.getClass().getName()
+ " doesn't match view parameter type " + definition.getType().getName());
}
}
return value;
}
示例2: render
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@Override
public Field render(Property<T> property) {
ObjectUtils.argumentNotNull(property, "Property must be not null");
Class<?> propertyType = property.getType();
// Try to render property according to a supported property type
if (TypeUtils.isString(propertyType)) {
// String
return renderString(property);
}
if (TypeUtils.isBoolean(propertyType)) {
// Boolean
return renderBoolean(property);
}
if (TypeUtils.isEnum(propertyType)) {
// Enum
return renderEnum(property);
}
if (TypeUtils.isTemporal(propertyType)) {
// Temporal
return renderTemporal(property);
}
if (TypeUtils.isDate(propertyType)) {
// Date
return renderDate(property);
}
if (TypeUtils.isNumber(propertyType)) {
// Number
return renderNumber(property);
}
return null;
}
示例3: serializeParameterValue
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
* Serialize given parameter value as String
* @param value Value to serialize
* @param dateFormat Date format to use with {@link Date} value types
* @return Serialized value
*/
private static String serializeParameterValue(Object value, DateFormat dateFormat) {
if (!isNullOrEmpty(value)) {
if (TypeUtils.isString(value.getClass())) {
return (String) value;
}
if (TypeUtils.isBoolean(value.getClass())) {
return ((Boolean) value) ? "true" : "false";
}
if (TypeUtils.isEnum(value.getClass())) {
int ordinal = ((Enum<?>) value).ordinal();
return String.valueOf(ordinal);
}
if (TypeUtils.isNumber(value.getClass())) {
if (TypeUtils.isDecimalNumber(value.getClass())) {
return PARAMETER_VALUE_DECIMAL_FORMAT.format(value);
} else {
return PARAMETER_VALUE_INTEGER_FORMAT.format(value);
}
}
if (TypeUtils.isDate(value.getClass())) {
return dateFormat.format((Date) value);
}
if (TypeUtils.isTemporal(value.getClass())) {
TemporalType type = TemporalType.getTemporalType((Temporal) value);
if (type == null) {
type = TemporalType.DATE;
}
switch (type) {
case DATE_TIME:
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format((Temporal) value);
case TIME:
return DateTimeFormatter.ISO_LOCAL_TIME.format((Temporal) value);
case DATE:
default:
return DateTimeFormatter.ISO_LOCAL_DATE.format((Temporal) value);
}
}
throw new UnsupportedOperationException(
"Parameter value serialization " + "not supported for type: " + value.getClass().getName());
}
return null;
}
示例4: serializeValue
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
* Serialize given {@link LiteralValue} as SQL string.
* @param value Value to serialize
* @param temporalType Optional temporal type
* @return Serialized SQL value
*/
public static String serializeValue(Object value, TemporalType temporalType) {
if (value != null) {
// CharSequence
if (TypeUtils.isCharSequence(value.getClass())) {
return "'" + value.toString() + "'";
}
// Number
if (TypeUtils.isNumber(value.getClass())) {
if (TypeUtils.isDecimalNumber(value.getClass())) {
return DECIMAL_FORMAT.format(value);
}
return INTEGER_FORMAT.format(value);
}
// Enum (by default, ordinal value is used)
if (TypeUtils.isEnum(value.getClass())) {
return String.valueOf(((Enum<?>) value).ordinal());
}
// Reader
if (Reader.class.isAssignableFrom(value.getClass())) {
try (Reader reader = ((Reader) value)) {
StringBuilder sb = new StringBuilder();
sb.append("'");
int buffer;
while ((buffer = reader.read()) != -1) {
sb.append((char) buffer);
}
sb.append("'");
return sb.toString();
} catch (IOException e) {
throw new QueryBuildException("Failed to read value from the Reader [" + value + "]", e);
}
}
// Date and times
Optional<String> serializedDate = serializeDate(value, temporalType);
if (serializedDate.isPresent()) {
return "'" + serializedDate.get() + "'";
}
// defaults to toString()
return value.toString();
}
return null;
}
示例5: isAdmittedParameterFieldType
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
* Check parameter field type
* @param type Field type
* @return <code>true</code> if type is admitted as view parameter value
*/
private static boolean isAdmittedParameterFieldType(Class<?> type) {
return TypeUtils.isString(type) || TypeUtils.isNumber(type) || TypeUtils.isBoolean(type)
|| TypeUtils.isDate(type) || TypeUtils.isLocalTemporal(type) || TypeUtils.isEnum(type);
}