@Override public ID getItemId(PropertyBox item) { if (item != null) { return item.getValueIfPresent(identifierProperty) .orElseThrow(() -> new DataAccessException("The identifier property [" + identifierProperty + "] is not present in PropertyBox item [" + item + "]")); } return null; }
@Override public ID getItemId(PropertyBox item) { if (item != null) { return item.getValueIfPresent(identifierProperty) .orElseThrow(() -> new DataAccessException("The identifier property [" + identifierProperty + "] is not present in PropertyBox item [" + item + "]")); } return null; }
@Override public Builder<PropertyBox, F> itemIdentifier(Property<?> identifierProperty) { ObjectUtils.argumentNotNull(identifierProperty, "Identifier property must be not null"); dataProvider.setItemIdentifier(item -> { if (item != null) { return item.getValueIfPresent(identifierProperty) .orElseThrow(() -> new DataAccessException("The identifier property [" + identifierProperty + "] is not present in PropertyBox item [" + item + "]")); } return null; }); return this; }
@SuppressWarnings("unchecked") @Override public B dataSource(ItemDataProvider<PropertyBox> dataProvider, final Property... identifierProperties) { ObjectUtils.argumentNotNull(identifierProperties, "Identifier properties must be not null"); if (identifierProperties.length == 0) { throw new IllegalArgumentException("Identifier properties must be not empty"); } final PropertySet<?> propertySet = PropertySet.builderOf(identifierProperties) .identifiers(Arrays.asList(identifierProperties)).build(); return dataSource(dataProvider, item -> { PropertyBox.Builder builder = PropertyBox.builder(propertySet); for (Property p : identifierProperties) { item.getValueIfPresent(p).ifPresent(v -> builder.set(p, v)); } return builder.build(); }); }
try { propertyBox.getValueIfPresent(property).ifPresent(value -> {
/** * Clone this PropertyBox using given <code>propertySet</code>, i.e. create a new PropertyBox and copy all given set * property values from this box to the newly created box. * @param <P> Actual property type * @param propertySet Property set of the cloned PropertyBox (not null) * @return A new, cloned, PropertyBox instance with given property set */ @SuppressWarnings("unchecked") default <P extends Property> PropertyBox cloneBox(PropertySet<P> propertySet) { ObjectUtils.argumentNotNull(propertySet, "Property set must be not null"); Builder builder = builder(propertySet).invalidAllowed(true); propertySet.forEach(p -> { if (!p.isReadOnly()) { this.getValueIfPresent(p).ifPresent(v -> builder.set(p, v)); } }); return builder.invalidAllowed(this.isInvalidAllowed()).build(); }
public void propertyBox() { // tag::propertybox[] final PathProperty<Long> ID = PathProperty.create("id", Long.class); final StringProperty NAME = StringProperty.create("name"); final PropertySet<?> PROPERTIES = PropertySet.of(ID, NAME); PropertyBox propertyBox = PropertyBox.create(ID, NAME); // <1> propertyBox = PropertyBox.create(PROPERTIES); // <2> propertyBox.setValue(ID, 1L); // <3> propertyBox.setValue(NAME, "testName"); // <4> propertyBox = PropertyBox.builder(PROPERTIES).set(ID, 1L).set(NAME, "testName").build(); // <5> Long id = propertyBox.getValue(ID); // <6> String name = propertyBox.getValueIfPresent(NAME).orElse("default"); // <7> boolean containsNotNullId = propertyBox.containsValue(ID); // <8> PropertyBox ids = propertyBox.cloneBox(ID); // <9> // end::propertybox[] }