Skip to content
This repository was archived by the owner on Aug 10, 2023. It is now read-only.
This repository was archived by the owner on Aug 10, 2023. It is now read-only.

Vaadin utils - compose value providers #4

@javier-godoy

Description

@javier-godoy

ValueProvider extends SerializableFunction. However, one cannot use Function.compose because the return type of Function.compose is Function instead of ValueProvider

Consider the following helper method:

public static <R, T, V> ValueProvider<T, V> compose(final ValueProvider<? super T, ? extends R> this_,
			final ValueProvider<? super R, ? extends V> after) {
		Objects.requireNonNull(this_);
		Objects.requireNonNull(after);
		return (T t) -> Optional.ofNullable(this_.apply(t)).map(after).orElse(null);
}

it allows you to specifiy a ValueProvider by composing method references
grid.addColumn(compose(Person::getAddress, Address::getCity)) instead of grid.addColumn(p->Optional.ofNullable(p.getAddress()).map(Address::getCity))


This contribution contains Personal Intellectual Property that is and remains owned by its Author. To the fullest extent possible, the Appjars Project and its controlling shareholder are granted a non-exclusive, irrevocable and transferable license under the terms stated in section 1(D) of the Amendment to the Agreement on Intellectual Property in effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions