Java Lists: Group by element property (as Ruby group_by method)

This is a very funny function, similar to group_by from Ruby.
It takes a collection and it transforms to a hash, having keys the property *groupBy*, and values the objects having that property.

A usage example:

collectionToHash(users, "name"); // returns a hash where the keys are the distinct user names, and the values are lists of users having that property.

Continue reading

Advertisements

Products in multiple categories. Find similar products.

This is a draft

– product model

– product can be inĀ  more than one categories, on multiple levels of the tree (i can attach the product anywhere i want); no restriction on this what so ever.

– categories are organized as a nested set (logical organized as a tree)

Problem: need to find similar products based on this taxonomy; sorting from ‘most similar’ to ‘least similar’
Continue reading