public static <D extends PsiElement> Map<D, List<D>> factorDuplicates(D[] elements, HashingStrategy<D> strategy) {
    if (elements == null || elements.length == 0) {
      return Collections.emptyMap();
    }

    Map<D, List<D>> map = CollectionFactory.createCustomHashingStrategyMap(strategy);
    for (D element : elements) {
      List<D> list = map.get(element);
      if (list == null) {
        list = new ArrayList<>();
      }
      list.add(element);
      map.put(element, list);
    }

    return map;
  }
public static <D extends PsiElement> Map<D, List<D>> factorDuplicates(D[] elements, HashingStrategy<D> strategy)