Casting Query and SerializablePredicate

Hello,

I just upgraded from Vaadin 8.4.5 to 8.9.1.
And doing so I was going to works against some Warning from my Eclipse.

One I already spent time to try figure out how to properly write the lines of code without reaching any Warning is still not resolved, and I got stuck.
(I resumed with Vaadin 7, some one and half year ago from my school Java 1.4 Swing knowledge. Sorry for that)

The useCase is easy, I want to write the count of lines or count of lines where boolean = true, in the footer of my Grid.
This is working.

However the code below. (duplicate line is to show how far I reached in the casting)
The xxx.getDataProvider().size( new Query(areActive)) give a Warning on the .size()

		SerializablePredicate<LicenseUsage> areActive = (uu) -> { 
			if(uu.getIsActive() != null) return uu.getIsActive();
			else return false;
		};	
		
		private void refreshFooter() {
			footer.getCell("licenseFK").setText(""+licenseUsagesTable.getDataProvider().size(new Query<>()));
			footer.getCell("isActive").setText(""+licenseUsagesTable.getDataProvider().size( new Query(areActive)));
			footer.getCell("isActive").setText(""+licenseUsagesTable.getDataProvider().size( new Query<LicenseUsage, SerializablePredicate<LicenseUsage>>(areActive)));
		}

I already searched in this forum, where the initial implementation idea comes from,
and in the Vaadin javaDoc :
https://vaadin.com/api/framework/8.9.1/com/vaadin/data/provider/Query.html
https://vaadin.com/api/framework/8.9.1/com/vaadin/server/SerializablePredicate.html

https://vaadin.com/api/framework/8.9.1/com/vaadin/ui/Grid.html
https://vaadin.com/api/framework/8.9.1/com/vaadin/data/provider/DataProvider.html

The warnings/errors in eclipse are :

for new Query(areActive) :

Description Resource Path Location Type

Query is a raw type. References to generic type Query<T,F> should be parameterized ShowAllLicenseUsagesLayoutFactory.java /licenseStoreDemo/src/main/java/com/cflamain/ui/licenseUsage line 379 Java Problem

Type safety: The constructor Query(Object) belongs to the raw type Query. References to generic type Query<T,F> should be parameterized ShowAllLicenseUsagesLayoutFactory.java /licenseStoreDemo/src/main/java/com/cflamain/ui/licenseUsage line 379 Java Problem

Type safety: The expression of type Query needs unchecked conversion to conform to Query<LicenseUsage,capture#26-of ?> ShowAllLicenseUsagesLayoutFactory.java /licenseStoreDemo/src/main/java/com/cflamain/ui/licenseUsage line 379 Java Problem

So then I try to parametrize the Query object. but …

for new Query<LicenseUsage, SerializablePredicate<LicenseUsage>>(areActive) :

Description Resource Path Location Type

The method size(Query<LicenseUsage,capture#27-of ?>) in the type DataProvider<LicenseUsage,capture#27-of ?> is not applicable for the arguments (Query<LicenseUsage,SerializablePredicate>) ShowAllLicenseUsagesLayoutFactory.java /licenseStoreDemo/src/main/java/com/cflamain/ui/licenseUsage line 380 Java Problem

And ther I tryed already many cast of the Query inside the .sizr() but I dont find anything valid.

Do someone whould have a deeper understanding of the type-paramnietrization and casting and could help me resolve this please.

Any explanation on what I am missing will be appreciated.

Thanks,

FLAMAIN Christophe.

SerializablePredicate is a serilializable version of a Predicate, which part of the Java 8 standard interfaces. Where ever you see Predicate, you can use Lambda expression as a parameter. Lambda expressions functional programming. Other interfaces typical for lambda expressions in Vaadin are SerializableConsumer and ValueProvider (the later accepts also function reference). If Lambda expression is new as a term to you, I recommend to google Java and Lambda expressions for further tutorials on the topic (there are plenty of them).

To get started with the topic you asked, i.e. data providers with query call backs and filtering, check this blog

https://www.flowingcode.com/2019/04/lazy-filtered-sorted-vaadin-grid.html

Thanks Tatu,
this is an interessting blog post. easy to understand, and it did highlighted me some further improvement I could or should bring in my implementation.
This also gave me some more inside in one of my many mistakes I made when I resumed java coding and bind my filterheader textfields, one to one to parameter of my backendcall (directly from UI to backend DAO provider). This is anyway now already replaced with a ListDataProvider “filter” plugin/add-on from the Directory. (This has some limits, but so far quick and convenient).

For my initial case however, after even trying to find a way to declare lambda expressions straight in the Query instead of using the SerializablePredicate, the .size() method still throw
either warning of not beeing casted
footer.getCell("isActive").setText(""+licenseUsagesTable.getDataProvider().size( new Query(areActive)));
or compilation errors of not matching the .size() arguments.
footer.getCell("isActive").setText(""+licenseUsagesTable.getDataProvider().size( new Query<LicenseUsage, SerializablePredicate<LicenseUsage>>(areActive)));

In this last case I am certain of the T = Type for the Query Casting, but not on the F = Filter, which ecplise IDE continue to complain as expecting a capture
capture#27-of ?>
Which I struggle to get its parent Class name.

where the query contructor accept SerializablePredicate<LicenseUsage>, the .size(query) dont aggree.

I will continue search on this, but I hope this is possible to avoid the @SuppressWarnings({ "rawtypes", "unchecked" }) as a workaround, and find how to declare properly the casting.

or any similar implementations which whould be valid.