public void collectionProperties() { // tag::collprops[] final ListPathProperty<String> STR = ListPathProperty.create("str", String.class); // <1> final SetPathProperty<Integer> ITG = SetPathProperty.create("str", Integer.class); // <2> Class<?> elementType = STR.getElementType(); // <3> PropertyBox box = PropertyBox.create(STR, ITG); box.setValue(STR, Collections.singletonList("a")); // <4> List<String> listValue = box.getValue(STR); // <5> box.setValue(ITG, Collections.singleton(1)); // <6> Set<Integer> setValue = box.getValue(ITG); // <7> // end::collprops[] }
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[] }
public void propertyBox3() { // tag::propertybox3[] final StringProperty NAME = StringProperty.create("name"); final StringProperty SURNAME = StringProperty.create("surname"); final VirtualProperty<String> FULL_NAME = VirtualProperty.create(String.class, propertyBox -> { // <1> return propertyBox.getValue(NAME) + " " + propertyBox.getValue(SURNAME); }); PropertyBox propertyBox = PropertyBox.create(NAME, SURNAME, FULL_NAME); // <2> propertyBox.setValue(NAME, "John"); propertyBox.setValue(SURNAME, "Doe"); String fullName = propertyBox.getValue(FULL_NAME); // <3> // end::propertybox3[] }
public void propertyBox2() { // tag::propertybox2[] final PathProperty<Long> ID = PathProperty.create("id", Long.class).withValidator(Validator.notNull()); // <1> final StringProperty NAME = StringProperty.create("name").withValidator(Validator.notBlank()); // <2> final PropertySet<?> PROPERTIES = PropertySet.of(ID, NAME); PropertyBox propertyBox = PropertyBox.create(PROPERTIES); propertyBox.setValue(ID, null); // <3> propertyBox = PropertyBox.builder(PROPERTIES).invalidAllowed(true).build(); // <4> propertyBox.validate(); // <5> // end::propertybox2[] }