@Contract(pure=true)
  public static <T> T @NotNull [] mergeArrayAndCollection(T @NotNull [] array,
                                                          @NotNull Collection<? extends T> collection,
                                                          @NotNull ArrayFactory<? extends T> factory) {
    if (collection.isEmpty()) {
      return array;
    }

    T[] array2;
    try {
      T[] a = factory.create(collection.size());
      array2 = collection.toArray(a);
    }
    catch (ArrayStoreException e) {
      throw new RuntimeException("Bad elements in collection: " + collection, e);
    }

    if (array.length == 0) {
      return array2;
    }

    T[] result = factory.create(array.length + collection.size());
    System.arraycopy(array, 0, result, 0, array.length);
    System.arraycopy(array2, 0, result, array.length, array2.length);
    return result;
  }
@Contract(pure=true)
  public static <T> T @NotNull [] mergeArrayAndCollection(T @NotNull [] array,
                                                          @NotNull Collection<? extends T> collection,
                                                          @NotNull ArrayFactory<? extends T> factory)