• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PropertyValueConverter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.holonplatform.core.property.PropertyValueConverter的典型用法代码示例。如果您正苦于以下问题:Java PropertyValueConverter类的具体用法?Java PropertyValueConverter怎么用?Java PropertyValueConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PropertyValueConverter类属于com.holonplatform.core.property包,在下文中一共展示了PropertyValueConverter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: write

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的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


示例2: input7

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
public void input7() {
	// tag::input7[]
	Input<Integer> integerInput = Components.input.number(Integer.class).build();

	Input<Boolean> booleanInput = Input.from(integerInput, // <1>
			Converter.from(value -> Result.ok((value == null) ? null : (value ? 1 : 0)),
					value -> (value == null) ? Boolean.FALSE : (value.intValue() > 0)));

	Boolean boolValue = booleanInput.getValue();

	final Property<Boolean> BOOL_PROPERTY = PathProperty.create("bool", Boolean.class);
	booleanInput = Input.from(integerInput, BOOL_PROPERTY, PropertyValueConverter.numericBoolean(Integer.class)); // <2>

	Input<Long> longInput = Input.from(new TextField(), // <3>
			Converter.from(value -> Result.ok((value == null) ? null : value.toString()),
					value -> (value == null || value.trim().isEmpty()) ? null : Long.parseLong(value)));
	// end::input7[]
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:19,代码来源:ExampleInput.java


示例3: processBeanProperty

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Builder<?> processBeanProperty(Builder<?> property, Class<?> beanOrNestedClass) {
	property.getAnnotation(Enumerated.class).ifPresent(a -> {
		final EnumType enumType = a.value();
		if (enumType == EnumType.STRING) {
			((Builder) property).converter(PropertyValueConverter.enumByName());
		} else {
			((Builder) property).converter(PropertyValueConverter.enumByOrdinal());
		}
		LOGGER.debug(() -> "JpaEnumeratedBeanPropertyPostProcessor: setted property [" + property
				+ "] value converter to default enumeration converter using [" + enumType.name() + "] mode");
	});
	return property;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:16,代码来源:JpaEnumeratedBeanPropertyPostProcessor.java


示例4: processPropertyResult

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
/**
 * Process a query result value bound to given <code>property</code>, applying any suitable property value
 * conversion.
 * @param property Property
 * @param value Result value
 * @return Processed value
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object processPropertyResult(Property property, Object value) {
	return property.getConverter()
			.filter(c -> value == null
					|| TypeUtils.isAssignable(value.getClass(), ((PropertyValueConverter<?, ?>) c).getModelType()))
			.map(c -> ((PropertyValueConverter<?, Object>) c).fromModel(value, property)).orElse(value);
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:15,代码来源:AbstractConverter.java


示例5: builtinConverters

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
public void builtinConverters() {
	// tag::bultincnv[]
	PropertyValueConverter.numericBoolean(Integer.class); // <1>
	PropertyValueConverter.localDate(); // <2>
	PropertyValueConverter.localDateTime(); // <3>
	PropertyValueConverter.enumByOrdinal(); // <4>
	PropertyValueConverter.enumByName(); // <5>
	// end::bultincnv[]
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:10,代码来源:ExampleProperty.java


示例6: checkupPropertyValue

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
/**
 * Check property value before putting it in PropertyBox.
 * @param <T> Property and value type
 * @param property Property
 * @param value Property value
 * @return Checked property value
 * @throws TypeMismatchException Value is not consistent with property type
 */
@SuppressWarnings("unchecked")
protected <T> T checkupPropertyValue(Property<T> property, T value) throws TypeMismatchException {
	return validatePropertyValue(property,
			property.getConverter()
					.filter(c -> (value == null || TypeUtils.isAssignable(value.getClass(), c.getModelType())))
					.map(cv -> ((PropertyValueConverter<T, Object>) cv).fromModel(value, property))
					.orElseGet(() -> checkValueTypeConsistency(property, value)));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:17,代码来源:AbstractPropertyBox.java


示例7: fromModel

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public E fromModel(String value, Property<E> property)
		throws com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException {
	if (value != null) {
		try {
			return Enum.valueOf((Class<E>) ((enumType != null) ? enumType : property.getType()), value);
		} catch (@SuppressWarnings("unused") IllegalArgumentException e) {
			throw new PropertyConversionException(property, "Unable to convert value to required Enum type "
					+ ((enumType != null) ? enumType : property.getType()) + "invalid enum value: " + value);
		}
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:15,代码来源:EnumByNameConverter.java


示例8: toModel

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Override
public String toModel(E value, Property<E> property)
		throws com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException {
	if (value != null) {
		return value.name();
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:9,代码来源:EnumByNameConverter.java


示例9: fromModel

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Override
public LocalDateTime fromModel(Date value, Property<LocalDateTime> property)
		throws com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException {
	return ConversionUtils.toLocalDateTime(value);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:6,代码来源:LocalDateTimeConverter.java


示例10: toModel

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Override
public Date toModel(LocalDateTime value, Property<LocalDateTime> property)
		throws com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException {
	return ConversionUtils.fromLocalDateTime(value);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:6,代码来源:LocalDateTimeConverter.java


示例11: fromModel

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Override
public TYPE fromModel(MODEL value, Property<TYPE> property)
		throws com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException {
	return fromModel.apply(value);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:6,代码来源:CallbackPropertyValueConverter.java


示例12: toModel

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Override
public MODEL toModel(TYPE value, Property<TYPE> property)
		throws com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException {
	return toModel.apply(value);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:6,代码来源:CallbackPropertyValueConverter.java


示例13: getConverter

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Override
public Optional<PropertyValueConverter<T, ?>> getConverter() {
	return Optional.ofNullable(converter);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:5,代码来源:AbstractProperty.java


示例14: fromModel

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Override
public LocalDate fromModel(Date value, Property<LocalDate> property)
		throws com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException {
	return ConversionUtils.toLocalDate(value);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:6,代码来源:LocalDateConverter.java


示例15: toModel

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Override
public Date toModel(LocalDate value, Property<LocalDate> property)
		throws com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException {
	return ConversionUtils.fromLocalDate(value);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:6,代码来源:LocalDateConverter.java


示例16: fromModel

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Override
public TestEnum2 fromModel(String value, Property<TestEnum2> property)
		throws com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException {
	return TestEnum2.parse(value);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:6,代码来源:TestValueConverter.java


示例17: toModel

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Override
public String toModel(TestEnum2 value, Property<TestEnum2> property)
		throws com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException {
	return (value != null) ? value.getStringValue() : null;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:6,代码来源:TestValueConverter.java


示例18: testPropertyConverters

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
@Test
public void testPropertyConverters() {

	NumericBooleanConverter<Integer> pc = new NumericBooleanConverter<>(int.class);

	PathProperty<Boolean> p = PathProperty.create("test", boolean.class).converter(pc);

	assertNotNull(p.getConverter());

	Boolean cnv = pc.fromModel(null, p);
	assertNotNull(cnv);
	assertEquals(Boolean.FALSE, cnv);

	cnv = pc.fromModel(Integer.valueOf(0), p);
	assertNotNull(cnv);
	assertEquals(Boolean.FALSE, cnv);

	cnv = pc.fromModel(Integer.valueOf(1), p);
	assertNotNull(cnv);
	assertEquals(Boolean.TRUE, cnv);

	Integer mod = pc.toModel(Boolean.FALSE, p);
	assertNotNull(mod);
	assertEquals(new Integer(0), mod);

	mod = pc.toModel(Boolean.TRUE, p);
	assertNotNull(mod);
	assertEquals(new Integer(1), mod);

	NumericBooleanConverter<Long> pc2 = new NumericBooleanConverter<>(Long.class);

	PathProperty<Boolean> p2 = PathProperty.create("test", boolean.class).converter(pc2);

	Long lm = pc2.toModel(Boolean.FALSE, p2);
	assertNotNull(lm);
	assertEquals(new Long(0), lm);

	lm = pc2.toModel(Boolean.TRUE, p2);
	assertNotNull(lm);
	assertEquals(new Long(1), lm);

	p2 = PathProperty.create("test", boolean.class).converter(PropertyValueConverter.numericBoolean(Long.class));

	lm = pc2.toModel(Boolean.FALSE, p2);
	assertNotNull(lm);
	assertEquals(new Long(0), lm);

	lm = pc2.toModel(Boolean.TRUE, p2);
	assertNotNull(lm);
	assertEquals(new Long(1), lm);

	p = PathProperty.create("test", boolean.class).converter(Integer.class, v -> v != null && v > 0,
			v -> v ? 1 : 0);

	assertEquals(new Integer(0), p.getConvertedValue(false));
	assertEquals(new Integer(1), p.getConvertedValue(true));

	@SuppressWarnings("unchecked")
	PropertyBox box = PropertyBox.builder(p).set((Property) p, new Integer(1)).build();
	assertTrue(box.getValue(p));

	// Enums

	final PathProperty<TestEnum> ENMP = PathProperty.create("testenum", TestEnum.class)
			.converter(PropertyValueConverter.enumByOrdinal());

	@SuppressWarnings("unchecked")
	PropertyBox eb = PropertyBox.builder(ENMP).set((Property) ENMP, new Integer(1)).build();
	assertEquals(TestEnum.B, eb.getValue(ENMP));

	assertEquals(new Integer(0), ENMP.getConvertedValue(TestEnum.A));

	final PathProperty<TestEnum> ENMP2 = PathProperty.create("testenum", TestEnum.class)
			.converter(PropertyValueConverter.enumByName());

	@SuppressWarnings("unchecked")
	PropertyBox eb2 = PropertyBox.builder(ENMP2).set((Property) ENMP2, "C").build();
	assertEquals(TestEnum.C, eb2.getValue(ENMP2));

	assertEquals("A", ENMP2.getConvertedValue(TestEnum.A));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:82,代码来源:TestProperty.java


示例19: from

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
/**
 * Create a new {@link Input} from another {@link Input} with a different value type, using given
 * {@link PropertyValueConverter} to perform value conversions.
 * @param <T> New value type
 * @param <V> Original value type
 * @param input Actual input (not null)
 * @param property Property to provide to the converter
 * @param converter Value converter (not null)
 * @return A new {@link Input} of the converted value type
 */
static <T, V> Input<T> from(Input<V> input, Property<T> property, PropertyValueConverter<T, V> converter) {
	ObjectUtils.argumentNotNull(converter, "PropertyValueConverter must be not null");
	return new InputConverterAdapter<>(input, Converter.from(value -> converter.toModel(value, property),
			value -> converter.fromModel(value, property), e -> e.getMessage()));
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:16,代码来源:Input.java


示例20: bind

import com.holonplatform.core.property.PropertyValueConverter; //导入依赖的package包/类
/**
 * Bind the given <code>property</code> to given <code>input</code> instance with different value type, using a
 * {@link PropertyValueConverter} to perform value conversions. If the property was already bound to a
 * {@link Input}, the old input will be replaced by the new input.
 * <p>
 * This method also adds property validators to given {@link Input} when applicable.
 * </p>
 * @param <T> Property type
 * @param <V> Input value type type
 * @param property Property (not null)
 * @param input Input to bind (not null)
 * @param converter Value converter (not null)
 * @return this
 */
default <T, V> B bind(Property<T> property, Input<V> input, PropertyValueConverter<T, V> converter) {
	return bind(property, Input.from(input, property, converter));
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:18,代码来源:PropertyInputGroup.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Message类代码示例发布时间:2022-05-23
下一篇:
Java Region类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap