本文整理汇总了Java中com.holonplatform.core.internal.utils.TypeUtils类的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils类的具体用法?Java TypeUtils怎么用?Java TypeUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeUtils类属于com.holonplatform.core.internal.utils包,在下文中一共展示了TypeUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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();
}
示例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);
}
}
示例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;
}
示例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();
}
};
}
示例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();
}
};
}
示例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();
}
};
}
示例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();
}
};
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}