yegor256 / cactoos

Object-Oriented Java primitives, as an alternative to Google Guava and Apache Commons
https://www.cactoos.org
MIT License
742 stars 165 forks source link

MultiMap implementation similar to Guava MultiMap implementations. #1249

Open fanifieiev opened 4 years ago

fanifieiev commented 4 years ago

The Takes framework code contains a lot of boilerplate when using, for instance, Map<String, Collection<String>>. Example of boilerplate:

final Map<String, List<String>> map = new HashMap<>();
 .....
 .....
 if (!map.containsKey(key)) {
     map.put(key, new LinkedList<>());
 }
 map.get(key).add(<some_string>)
 .......

Would be great to have something like:

final CollectionMap<String, String> map = new CollectionMapOf(
   "key1", "value1", "value2"
);
 ....
 map.put("key1", "value3");
 map.put("key2", "value4"); //without checking if the value collection exists

Note: Need to think about specific implementation of collection passed to CollectionMapOf or create dedicated implementations for each use case like:

0crat commented 4 years ago

@paulodamaso/z please, pay attention to this issue

victornoel commented 4 years ago

@fanifieiev @paulodamaso I've already raised this question in the past: do we target with cactoos a lib with mostly OO decorators (such as those on Iterable and Iterator that are really great and unique in the Java world I think), or do we want cactoos to become a fully fledged collection implementation library?

The latest is a huge endeavour, and I wonder what anybody would gain from it: while the decorators provides something that does not already exists, there are many libraries implementing collections and they as OO as possible (because the java collection api is not great).

fanifieiev commented 4 years ago

@fanifieiev @paulodamaso I've already raised this question in the past: do we target with cactoos a lib with mostly OO decorators (such as those on Iterable and Iterator that are really great and unique in the Java world I think), or do we want cactoos to become a fully fledged collection implementation library?

The latest is a huge endeavour, and I wonder what anybody would gain from it: while the decorators provides something that does not already exists, there are many libraries implementing collections and they as OO as possible (because the java collection api is not great).

@victornoel In the description of Cactoos project it is stated that the target of the project is: Object-Oriented Java primitives, as an alternative to Google Guava and Apache Commons, so why should this feature not be there then?

victornoel commented 4 years ago

@fanifieiev so in the end, this is out of scope of cactoos for now until v1 is released, and then we can take into the scope