本文整理汇总了Java中com.holonplatform.core.internal.utils.TypeUtils.isNumber方法的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils.isNumber方法的具体用法?Java TypeUtils.isNumber怎么用?Java TypeUtils.isNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.holonplatform.core.internal.utils.TypeUtils
的用法示例。
在下文中一共展示了TypeUtils.isNumber方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lessThan
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
* Build a validator that checks that a value is less than given <code>compareTo</code> value.
* <p>
* Supported data types: {@link Comparable}
* </p>
* @param <T> Value and validator type
* @param compareTo Value to compare
* @param message Validation error message
* @param messageCode Optional validation error message localization code
* @return Validator
*/
@SuppressWarnings("serial")
static <T extends Comparable<T>> Validator<T> lessThan(T compareTo, String message, String messageCode) {
ObjectUtils.argumentNotNull(compareTo, "Value to compare must be not null");
return new BuiltinValidator<T>() {
@Override
public void validate(T v) throws ValidationException {
if (v != null && v.compareTo(compareTo) >= 0) {
throw new ValidationException(message, messageCode, compareTo);
}
}
@Override
public Optional<ValidatorDescriptor> getDescriptor() {
if (TypeUtils.isNumber(compareTo.getClass())) {
return Optional.of(ValidatorDescriptor.builder().max(((Number) compareTo)).exclusiveMax().build());
}
return Optional.empty();
}
};
}
示例2: lessOrEqual
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
* Build a validator that checks that a value is less than or equal to given <code>compareTo</code> value.
* <p>
* Supported data types: {@link Comparable}
* </p>
* @param <T> Value and validator type
* @param compareTo Value to compare
* @param message Validation error message
* @param messageCode Optional validation error message localization code
* @return Validator
*/
@SuppressWarnings("serial")
static <T extends Comparable<T>> Validator<T> lessOrEqual(T compareTo, String message, String messageCode) {
ObjectUtils.argumentNotNull(compareTo, "Value to compare must be not null");
return new BuiltinValidator<T>() {
@Override
public void validate(T v) throws ValidationException {
if (v != null && v.compareTo(compareTo) > 0) {
throw new ValidationException(message, messageCode, compareTo);
}
}
@Override
public Optional<ValidatorDescriptor> getDescriptor() {
if (TypeUtils.isNumber(compareTo.getClass())) {
return Optional.of(ValidatorDescriptor.builder().max(((Number) compareTo)).build());
}
return Optional.empty();
}
};
}
示例3: greaterThan
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
* Build a validator that checks that a value is greater than given <code>compareTo</code> value.
* <p>
* Supported data types: {@link Comparable}
* </p>
* @param <T> Value and validator type
* @param compareTo Value to compare
* @param message Validation error message
* @param messageCode Optional validation error message localization code
* @return Validator
*/
@SuppressWarnings("serial")
static <T extends Comparable<T>> Validator<T> greaterThan(T compareTo, String message, String messageCode) {
ObjectUtils.argumentNotNull(compareTo, "Value to compare must be not null");
return new BuiltinValidator<T>() {
@Override
public void validate(T v) throws ValidationException {
if (v != null && v.compareTo(compareTo) <= 0) {
throw new ValidationException(message, messageCode, compareTo);
}
}
@Override
public Optional<ValidatorDescriptor> getDescriptor() {
if (TypeUtils.isNumber(compareTo.getClass())) {
return Optional.of(ValidatorDescriptor.builder().min(((Number) compareTo)).exclusiveMin().build());
}
return Optional.empty();
}
};
}
示例4: greaterOrEqual
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
* Build a validator that checks that a value is greater than or equal to given <code>compareTo</code> value.
* <p>
* Supported data types: {@link Comparable}
* </p>
* @param <T> Value and validator type
* @param compareTo Value to compare
* @param message Validation error message
* @param messageCode Optional validation error message localization code
* @return Validator
*/
@SuppressWarnings("serial")
static <T extends Comparable<T>> Validator<T> greaterOrEqual(T compareTo, String message, String messageCode) {
ObjectUtils.argumentNotNull(compareTo, "Value to compare must be not null");
return new BuiltinValidator<T>() {
@Override
public void validate(T v) throws ValidationException {
if (v != null && v.compareTo(compareTo) < 0) {
throw new ValidationException(message, messageCode, compareTo);
}
}
@Override
public Optional<ValidatorDescriptor> getDescriptor() {
if (TypeUtils.isNumber(compareTo.getClass())) {
return Optional.of(ValidatorDescriptor.builder().min(((Number) compareTo)).build());
}
return Optional.empty();
}
};
}
示例5: 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;
}
示例6: 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;
}
示例7: processQueryResult
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
* Process a query result and apply conversions if required.
* @param type Expected result type
* @param result Result value
* @return Processed result
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object processQueryResult(Class type, Object result) {
if (type != null && result != null) {
if (TypeUtils.isNumber(type) && TypeUtils.isNumber(result.getClass())) {
return ConversionUtils.convertNumberToTargetClass((Number) result, type);
}
}
return result;
}
示例8: deserializeValue
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T deserializeValue(QueryExpression<T> expression, Object value) {
if (value != null) {
// date and times
Optional<TemporalType> temporalType = JdbcDatastoreUtils.getTemporalType(expression, true);
if (temporalType.isPresent()) {
LocalDateTime dt = null;
if (TypeUtils.isString(value.getClass())) {
dt = asDateTime((String) value, temporalType.orElse(TemporalType.DATE));
} else if (TypeUtils.isNumber(value.getClass())) {
dt = asDateTime((Number) value);
}
if (dt != null) {
if (LocalDateTime.class.isAssignableFrom(expression.getType())) {
return (T) dt;
}
if (LocalDate.class.isAssignableFrom(expression.getType())) {
return (T) dt.toLocalDate();
}
if (LocalTime.class.isAssignableFrom(expression.getType())) {
return (T) dt.toLocalTime();
}
if (Date.class.isAssignableFrom(expression.getType())) {
return (T) ConversionUtils.fromLocalDateTime(dt);
}
}
}
}
// fallback to default
return SQLValueDeserializer.getDefault().deserializeValue(expression, value);
}
示例9: 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;
}
示例10: isIntrospectable
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
private static boolean isIntrospectable(Class<?> propertyClass) {
return propertyClass != Object.class && !propertyClass.isArray() && !propertyClass.isPrimitive()
&& !propertyClass.isEnum() && !TypeUtils.isString(propertyClass) && !TypeUtils.isNumber(propertyClass)
&& !TypeUtils.isTemporalOrCalendar(propertyClass) && !TypeUtils.isBoolean(propertyClass)
&& !Collection.class.isAssignableFrom(propertyClass);
}
示例11: 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;
}
示例12: classToJdbcType
import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
* Get the SQL type which corresponds to given Java type.
* @param type Java type
* @return SQL type
*/
public static int classToJdbcType(Class<?> type) {
if (type == null) {
return Types.NULL;
}
if (String.class.isAssignableFrom(type)) {
return Types.VARCHAR;
}
if (TypeUtils.isBoolean(type)) {
return Types.BOOLEAN;
}
if (TypeUtils.isInteger(type)) {
return Types.INTEGER;
}
if (TypeUtils.isLong(type)) {
return Types.BIGINT;
}
if (TypeUtils.isDouble(type) || TypeUtils.isFloat(type) || TypeUtils.isBigDecimal(type)) {
return Types.DECIMAL;
}
if (TypeUtils.isShort(type)) {
return Types.SMALLINT;
}
if (TypeUtils.isByte(type)) {
return Types.TINYINT;
}
if (TypeUtils.isNumber(type)) {
return Types.NUMERIC;
}
if (type == byte[].class) {
return Types.BINARY;
}
if (TypeUtils.isDate(type) || TypeUtils.isCalendar(type) || java.sql.Date.class.isAssignableFrom(type)
|| LocalDate.class.isAssignableFrom(type)) {
return Types.DATE;
}
if (LocalTime.class.isAssignableFrom(type) || java.sql.Time.class.isAssignableFrom(type)) {
return Types.TIME;
}
if (LocalDateTime.class.isAssignableFrom(type) || java.sql.Timestamp.class.isAssignableFrom(type)) {
return Types.TIMESTAMP;
}
if (ZonedDateTime.class.isAssignableFrom(type)) {
return Types.TIMESTAMP_WITH_TIMEZONE;
}
return Types.OTHER;
}
示例13: 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);
}