code: public static <T, K, V, P> HashMap<K, HashMap<P, V>> matrix(
  			Collection<T> entities, Function<T, K> keyMapper1,
  			Function<T, P> keyMapper2, Function<T, V> valueMapper) {
  		if (entities == null)
  			return null;
  		return entities.stream().collect(
  				Collectors.groupingBy(keyMapper1, HashMap::new, Collectors
  						.toMap(keyMapper2, valueMapper, (a, b) -> a,
  								HashMap::new)));
  	}
docs: Similar to grouping into 2 levels except each unit is not a Collection
  but a single object
  
  @param entities
  @param keyMapper1
  @param keyMapper2
  @param valueMapper
  @return