Piet Souris wrote:hi Mike,
for the toMap you need two mappers, one that maps the element to a key, and one that maps the element to a value (and if there is a possibility of having non unique keys, a BiFunction that tells what to do with the values in that case). You already have the key mapper, you need a value mapper. So the second argument would be: word -> word, or somewhat more stylish: Function.identity().
In that last case: why does the method reference: Function::identity not work?
Piet Souris wrote:Given that you must deal with synonyms, a Map<String, List<Word>> seems more reasonable.
With the toMap, it means that when we have two equal Strings, we need to put the two associated Words into a List. Now, that is not so easy to accomplish with the toMap method, but the alternative mappng method is in this case very much easier. I'm talking about the Collectors.groupingBy method. See the API of the Collectors class; we can use the simplest version, only specifying the key. So we get:
Piet Souris wrote:In that last case: why does the method reference: Function::identity not work?
Stephan van Hulst wrote:Function.identity() takes no arguments and returns a Function<T,T>, so Function::identity is a Supplier<Function<T,T>>, not a Function<T,T>.
In other words, Function.identity() supplies the identity function, it's not the identity function itself.
Piet Souris wrote:why do you use a Word factory 'valueOf', instead of a good old fashioned constructor? Is that the current trend perhaps?
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDFhtttp://www.e-iceblue.com/free-apis.html