Gang,
I just wanted to share one really cool thing that came out of using Java 8
with Zest. A bit advanced course, but I think it can come to make Qi4j 3.0
really awesome...
I have been using ValueBuilderFactory.newValueBuilderWithState() quite a
lot, and it used to be really nasty, due to the immense 'noise' that each
function became ananonymous class with all the boilerplate. Instead, we end
up with something like this;
ValueBuilder<T> builder = module.newValueBuilderWithState(
resourceType,
descriptor -> {
String name = descriptor.qualifiedName().name();
return attributes.get( name );
},
descriptor -> null,
descriptor -> null,
descriptor -> null
);
So, even though Qi4j isn't using the Java 8 functions, the compiler has
enough sugar-coating handling of anonymous classes with single methods.
It is also possible, to do MethodReferences in neat ways. Look at this;
manyassoc
.toMap()
.values()
.stream()
.filter( specification::satisfiedBy )
.map( entity -> uow.toValue( entityType, (T) entity ) )
.forEach( result::add );
That filter() nicely accepts Qi4j Specification instances (yeah, the above
is to expand ManyAssocation references to ValueComposites, subject to a
spec)
I can't wait to get going on Qi4j ver 3.0, but it is nice to know that
there are benefits even with the current codebase.
Cheers
--
Niclas Hedhman, Software Developer
http://zest.apache.org - New Energy for Java