code: public static <T, K, V, P, C extends Collection<V>> HashMap<K, HashMap<P, C>> groupTwice(
  			Collection<T> entities, Function<T, K> keyMapper1,
  			Function<T, P> keyMapper2, Function<T, V> valueMapper,
  			Supplier<C> collectionFactory) {
  		if (entities == null)
  			return null;
  		return entities.stream().collect(
  				Collectors.groupingBy(keyMapper1, HashMap::new, Collectors
  						.groupingBy(keyMapper2, HashMap::new, Collectors
  								.mapping(valueMapper, Collectors
  										.toCollection(collectionFactory)))));
  	}
docs: Grouping into 2 levels
  
  @param entities
  @param keyMapper1
  @param keyMapper2
  @param valueMapper
  @param collectionFactory
  @return