/** * Get given {@link PropertyBox} as a map of {@link Path} and {@link TypedExpression} values. * @param value The property box value (not null) * @param includeNullValues Whether to set <code>null</code> property box values to the <code>null</code> value * @return Values map */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected Map<Path<?>, TypedExpression<?>> asPathValues(PropertyBox value, boolean includeNullValues) { ObjectUtils.argumentNotNull(value, "PropertyBox must be not null"); final Map<Path<?>, TypedExpression<?>> values = new HashMap<>(value.size()); final PathPropertyBoxAdapter propertyBoxAdapter = PathPropertyBoxAdapter.create(value); propertyBoxAdapter.paths().forEach(path -> { propertyBoxAdapter.getValueOrElse(path, pathWithNoValue -> { if (includeNullValues) { values.put(path, NullExpression.create(path)); } }).ifPresent(val -> { values.put(path, (val instanceof TypedExpression) ? (TypedExpression<?>) val : ConstantConverterExpression.create((Path) path, val)); }); }); return values; }
public void pathPropertyBoxAdapter() { // tag::ppba[] final StringProperty STR = StringProperty.create("str"); final NumericProperty<Integer> ITG = NumericProperty.integerType("itg"); final PropertySet<?> SET = PropertySet.of(STR, ITG); final Path<String> PATH = Path.of("str", String.class); PropertyBox box = PropertyBox.builder(SET).set(STR, "test1").set(ITG, 1).build(); PathPropertyBoxAdapter adapter = PathPropertyBoxAdapter.create(box); // <1> boolean contains = adapter.containsValue(PATH); // <2> Optional<String> value = adapter.getValue(PATH); // <3> adapter.setValue(PATH, "value"); // <4> // end::ppba[] }