当前位置: 首页>>代码示例>>Java>>正文


Java TypeUtils类代码示例

本文整理汇总了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);
}
 
开发者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


注:本文中的com.holonplatform.core.internal.utils.TypeUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。