private static boolean addToMaps(final Object o,
                                   final Map<Object, int[]> counts,
                                   final Map<Object, List<Set<Object>>> map,
                                   final int index,
                                   final List<Object> results,
                                   final boolean singleValuedInvocation,
                                   final boolean intersect) {
    final Object primaryKey = getPrimaryKey(o, singleValuedInvocation);
    if (primaryKey != null || singleValuedInvocation) {
      final List<Set<Object>> list = map.get(primaryKey);
      final int[] indices = counts.get(primaryKey);
      int objIndex = intersect? indices[index] : indices[index]++;
      if (list.size() <= objIndex) {
        list.add(new LinkedHashSet<>());
      }
      list.get(objIndex).add(o);
      return false;
    }

    results.add(o);
    return true;
  }
private static boolean addToMaps(final Object o,
                                   final Map<Object, int[]> counts,
                                   final Map<Object, List<Set<Object>>> map,
                                   final int index,
                                   final List<Object> results,
                                   final boolean singleValuedInvocation,
                                   final boolean intersect)