Last time I was describing how to enable Tomcat for projects maintained by Gradle in post with title called "IntelliJ with Tomcat and Gradle using Gretty plugin". The thing that I found recently even a better way to achieve that! Moreover this way is less invasive in terms of that you do not need to append any configuration to your gradle scripts! This better way is known as a Smart Tomcat! It is a plugin for IntelliJ which allow you to configure literally everything around your app if it should be run on Tomcat.
Smart Tomcat - IntelliJ IDEA Plugins
Most sophisticated informations and issues related with widely known IT sector and many more ;-)
Sunday, 9 July 2017
Convert Map into Map of List - Java 8
Last time I was looking for a way to convert a Map into a Map of List. In otherwise direction, I mean backward from value up to key. Below you might find an solution for that problem using of course main Java 8 components like stream, filter, grouping and mapping.
Results
Key : HOME with List of DOG, CAT, TURTLE and RABBIT
Key : NOT_HOME with List of LION, HIPPO, TIGER, ZEBRA
Map<String, String> input = new HashMap<>(); input.put("SHARK", null); input.put("DOG", "HOME"); input.put("CAT", "HOME"); input.put("TURTLE", "HOME"); input.put("RABBIT", "HOME"); input.put("LION", "NOT_HOME"); input.put("HIPPO", "NOT_HOME"); input.put("TIGER", "NOT_HOME"); input.put("ZEBRA", "NOT_HOME"); Map<String, List<String>> result = input.entrySet().stream() .filter(i -> i.getValue() != null) .collect(Collectors.groupingBy(i -> i.getValue(), Collectors.mapping(i -> i.getKey(), Collectors.toList())));
Results
Key : HOME with List of DOG, CAT, TURTLE and RABBIT
Key : NOT_HOME with List of LION, HIPPO, TIGER, ZEBRA