本文整理汇总了Java中com.holonplatform.core.internal.utils.TypeUtils类的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils类的具体用法?Java TypeUtils怎么用?Java TypeUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeUtils类属于com.holonplatform.core.internal.utils包,在下文中一共展示了TypeUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: clearViewParameter
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
/**
* Clear view parameter on given view instance
* @param view View instance
* @param definition Parameter definition
*/
private static void clearViewParameter(View view, ViewParameterDefinition definition)
throws ViewConfigurationException {
Object value = null;
if (TypeUtils.isPrimitiveBoolean(definition.getType())) {
value = Boolean.FALSE;
} else if (TypeUtils.isPrimitiveInt(definition.getType()) || short.class == definition.getType()) {
value = 0;
} else if (TypeUtils.isPrimitiveInt(definition.getType())) {
value = 0;
} else if (TypeUtils.isPrimitiveFloat(definition.getType())) {
value = 0f;
} else if (TypeUtils.isPrimitiveDouble(definition.getType())) {
value = 0d;
}
setViewParameterValue(view, definition, value);
}
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:23,代码来源:ViewNavigationUtils.java
示例2: get
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> get(String resourceKey, Class<T> resourceType) throws TypeMismatchException {
ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null");
ObjectUtils.argumentNotNull(resourceType, "Resource type must be not null");
final VaadinSession session = VaadinSession.getCurrent();
if (session != null) {
Object value = session.getAttribute(resourceKey);
if (value != null) {
// check type
if (!TypeUtils.isAssignable(value.getClass(), resourceType)) {
throw new TypeMismatchException("<" + NAME + "> Actual resource type [" + value.getClass().getName()
+ "] and required resource type [" + resourceType.getName() + "] mismatch");
}
return Optional.of((T) value);
}
}
return Optional.empty();
}
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:27,代码来源:VaadinSessionScope.java
示例3: convert
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public R convert(Q result) throws QueryResultConversionException {
try {
final Object value = getResult(expression, result);
// check type
if (value != null && !TypeUtils.isAssignable(value.getClass(), expression.getType())) {
throw new QueryResultConversionException("Expected a value of projection type ["
+ expression.getType().getName() + "], got a value of type: " + value.getClass().getName());
}
return (R) value;
} catch (Exception e) {
throw new QueryResultConversionException(
"Failed to convert query result for expression [" + expression + "]", e);
}
}
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:21,代码来源:SingleSelectionResultConverter.java
示例4: getAuthorizer
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
/**
* Get {@link Authorizer} to use with given permission type
* <p>
* This first Authorizer registered in this Realm which is consistent with given <code>permissionType</code> is
* used.
* </p>
* @param permissionType Permission type
* @return Authorizer
* @throws UnsupportedPermissionException If no {@link Authorizer} is available for given permission type
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Authorizer<Permission> getAuthorizer(Class<? extends Permission> permissionType)
throws UnsupportedPermissionException {
Authorizer<Permission> permissionAuthorizer = null;
for (Authorizer authorizer : getAuthorizers()) {
if (TypeUtils.isAssignable(permissionType, authorizer.getPermissionType())) {
permissionAuthorizer = authorizer;
break;
}
}
if (permissionAuthorizer == null) {
throw new UnsupportedPermissionException("Unsupported permission type: " + permissionType.getName()
+ " - No suitable Authorizer available in Realm");
}
return permissionAuthorizer;
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:29,代码来源:DefaultRealm.java
示例5: 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();
}
};
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:33,代码来源:Validator.java
示例6: 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();
}
};
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:33,代码来源:Validator.java
示例7: 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();
}
};
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:33,代码来源:Validator.java
示例8: 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();
}
};
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:33,代码来源:Validator.java
示例9: getAndCheckPropertyValue
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
/**
* Get value for given property, checking type consistency and apply any {@link PropertyValueConverter} bound to
* property.
* <p>
* Actual property value must be provided by subclasses through {@link #getPropertyValue(Property)} method.
* </p>
* @param <T> Property type
* @param property Property for which obtain the value
* @return Property value
* @throws PropertyAccessException Error handling property value
*/
@SuppressWarnings("unchecked")
protected <T> T getAndCheckPropertyValue(Property<T> property) throws PropertyAccessException {
// check value provider
if (property instanceof VirtualProperty) {
return getValueProviderPropertyValue((VirtualProperty<T>) property);
}
// use delegate method to obtain value
Object value = getPropertyValue(property);
// check type
if (value != null) {
if (!TypeUtils.isAssignable(value.getClass(), property.getType())) {
throw new TypeMismatchException("Value type " + value.getClass().getName()
+ " doesn't match property type " + property.getType().getName());
}
}
return (T) value;
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:32,代码来源:AbstractPropertyBox.java
示例10: get
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
/**
* Get a value of given <code>type</code> identified by given <code>key</code>.
* @param key Resource key
* @param type Resource type
* @return Resource value, or <code>null</code> if not found
* @param <T> Resource type
* @throws TypeMismatchException Expected and actual resource type mismatch
*/
@SuppressWarnings("unchecked")
public <T> T get(String key, Class<T> type) throws TypeMismatchException {
ObjectUtils.argumentNotNull(key, "Resource key must be not null");
ObjectUtils.argumentNotNull(type, "Resource type must be not null");
LOGGER.debug(() -> "<" + scopeName + "> get resource with key [" + key + "]");
Object resource = resources.get(key);
if (resource != null) {
// check type
if (!TypeUtils.isAssignable(resource.getClass(), type)) {
throw new TypeMismatchException(
"<" + scopeName + "> Actual resource type [" + resource.getClass().getName()
+ "] and required resource type [" + type.getName() + "] mismatch");
}
LOGGER.debug(() -> "<" + scopeName + "> Retrieved resource value of type [" + resource.getClass().getName()
+ "] for key [" + key + "]");
return (T) resource;
}
return null;
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:32,代码来源:ContextResourceMap.java
示例11: read
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <V> V read(String propertyName, T instance) {
ObjectUtils.argumentNotNull(propertyName, "Property name must be not null");
ObjectUtils.argumentNotNull(instance, "Bean instance must be not null");
final BeanProperty<?> property = (BeanProperty<?>) requireProperty(propertyName);
final Object value = read(property, instance, null);
// check type
if (value != null && !TypeUtils.isAssignable(value.getClass(), property.getType())) {
throw new TypeMismatchException("Read value type " + value.getClass().getName()
+ " doesn't match property type " + property.getType().getName());
}
return (V) value;
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:18,代码来源:DefaultBeanPropertySet.java
示例12: write
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public T write(PropertyBox propertyBox, T instance, boolean ignoreMissing) {
ObjectUtils.argumentNotNull(propertyBox, "PropertyBox must be not null");
ObjectUtils.argumentNotNull(instance, "Bean instance must be not null");
propertyBox.stream().filter(p -> !p.isReadOnly()).filter(p -> Path.class.isAssignableFrom(p.getClass()))
.map(p -> (Path<?>) p).forEach(p -> {
getProperty(p, ignoreMissing).ifPresent(bp -> {
final Property<Object> property = ((Property) p);
final Object boxValue = propertyBox.getValue(property);
Object value = boxValue;
// check conversion
if (!TypeUtils.isAssignable(bp.getType(), property.getType())) {
value = property.getConverter()
.filter(c -> TypeUtils.isAssignable(bp.getType(), c.getModelType()))
.map(c -> ((PropertyValueConverter) c).toModel(boxValue, property))
.orElse(boxValue);
}
write(bp, p.getType(), value, instance);
});
});
return instance;
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:26,代码来源:DefaultBeanPropertySet.java
示例13: getProperty
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T getProperty(String key, Class<T> targetType) throws IllegalArgumentException {
ObjectUtils.argumentNotNull(key, "Property name must be not null");
ObjectUtils.argumentNotNull(targetType, "Property type must be not null");
Object value = properties.get(key);
if (value != null) {
if (TypeUtils.isAssignable(value.getClass(), targetType)) {
return (T) value;
} else if (TypeUtils.isString(value.getClass())) {
return ConversionUtils.convertStringValue(value.toString(), targetType);
} else {
throw new IllegalArgumentException(
"Property " + key + " type is not consistent " + "with required type: " + targetType.getName()
+ " (got type: " + value.getClass().getName() + ")");
}
}
return null;
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:22,代码来源:MapConfigPropertyProvider.java
示例14: getParameterIf
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> getParameterIf(String name, Class<T> type, Predicate<T> condition) {
ObjectUtils.argumentNotNull(name, "Parameter name must be not null");
ObjectUtils.argumentNotNull(type, "Parameter type must be not null");
ObjectUtils.argumentNotNull(condition, "Condition must be not null");
Object value = getParameterValue(name);
if (value != null && !TypeUtils.isAssignable(value.getClass(), type)) {
throw new TypeMismatchException("Value type " + value.getClass().getName()
+ " is not compatible with required type " + type.getName());
}
final T typedValue = (T) value;
if (value != null && condition.test(typedValue)) {
return Optional.of(typedValue);
}
return Optional.empty();
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:23,代码来源:DefaultParameterSet.java
示例15: convert
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public T convert(ResultSet resultSet) throws QueryResultConversionException {
try {
final Object value = dialect.getValueDeserializer().deserializeValue(expression,
getResult(dialect, resultSet, selection));
// check type
if (value != null && !TypeUtils.isAssignable(value.getClass(), expression.getType())) {
throw new QueryResultConversionException("Expected a value of projection type ["
+ expression.getType().getName() + "], got a value of type: " + value.getClass().getName());
}
return (T) value;
} catch (SQLException e) {
throw new QueryResultConversionException(
"Failed to convert query result for expression [" + expression + "]", e);
}
}
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:22,代码来源:QueryExpressionResultSetConverter.java
示例16: 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;
}
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:36,代码来源:ViewNavigationUtils.java
示例17: getNumberFormat
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
/**
* Gets the NumberFormat to use to convert values
* @param locale Locale to use
* @return the numberFormat If a NumberFormat was specified using {@link #setNumberFormat(NumberFormat)}, this one
* is returned. Otherwise, a NumberFormat is obtained using given Locale
*/
public NumberFormat getNumberFormat(Locale locale) {
Locale lcl = (locale != null) ? locale
: LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale())
.orElse(Locale.getDefault());
return (numberFormat != null) ? numberFormat
: TypeUtils.isDecimalNumber(numberType) ? NumberFormat.getNumberInstance(lcl)
: NumberFormat.getIntegerInstance(lcl);
}
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:15,代码来源:StringToNumberConverter.java
示例18: 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;
}
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:36,代码来源:DefaultFieldPropertyRenderer.java
示例19: renderNumber
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
/**
* Renders a numeric value type Field
* @param property Property to render
* @return Field instance
*/
@SuppressWarnings("unchecked")
protected Field<T> renderNumber(Property<T> property) {
// Number format
Class<? extends Number> type = (Class<? extends Number>) property.getType();
int decimals = property.getConfiguration().getParameter(StringValuePresenter.DECIMAL_POSITIONS).orElse(-1);
boolean disableGrouping = property.getConfiguration().getParameter(StringValuePresenter.DISABLE_GROUPING)
.orElse(Boolean.FALSE);
Locale locale = LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale())
.orElse(Locale.getDefault());
NumberFormat numberFormat = LocalizationContext.getCurrent().filter(l -> l.isLocalized())
.map((l) -> l.getNumberFormat(type, decimals, disableGrouping))
.orElse(TypeUtils.isDecimalNumber(property.getType()) ? NumberFormat.getNumberInstance(locale)
: NumberFormat.getIntegerInstance(locale));
if (decimals > -1) {
numberFormat.setMinimumFractionDigits(decimals);
numberFormat.setMaximumFractionDigits(decimals);
}
if (disableGrouping) {
numberFormat.setGroupingUsed(false);
}
return postProcessField(input.number(type).numberFormat(numberFormat).asField(), property);
}
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:34,代码来源:DefaultFieldPropertyRenderer.java
示例20: AbstractViewComponent
import com.holonplatform.core.internal.utils.TypeUtils; //导入依赖的package包/类
/**
* Constructor
* @param type Concrete value type
* @param root Root component
*/
public AbstractViewComponent(Class<? extends T> type, Component root) {
super(root);
this.type = TypeUtils.box(type);
setSizeUndefined();
addStyleName("h-viewcomponent");
}
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:14,代码来源:AbstractViewComponent.java
注:本文中的com.holonplatform.core.internal.utils.TypeUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论