delegation with default methods

public class Property extends BaseEntity {

    public static interface Owner<T extends BaseEntity & Owner<T>> {

        List<Property> getProperties();

        default void setProperties(List<Property> properties) {

        default T properties(List<Property> properties) {
            return (T) this;

        default T addProperty(@NotNull final Property property) {
            return (T) this;

        default T addProperty(@NotNull final String name,
                              @NotNull final String value) {
            return addProperty(new Property().name(name).value(value));

        default Stream<Property> propertyStream() {
            return getProperties().stream();

        default T filterProperties(@NotNull final java.util.function.Predicate<Property> predicate) {
            return properties(propertyStream().filter(predicate).collect(toList()));

    @Column(name = "NAME", nullable = false)
    private String name;

    @Column(name = "VALUE_", nullable = false)
    private String value;
public class Event extends BaseEntity implements Property.Owner<Event> {

    public List<Property> getProperties() {
        return (properties = ofNullable(properties).orElse(new ArrayList<>()));

    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER,
               mappedBy = "event", orphanRemoval = true)
    private List<Property> properties;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s