private static <T> List<T> removeIndices(@NotNull JList<T> list, int @NotNull [] indices, @Nullable Condition<? super T> condition) {
    if (indices.length == 0) {
      return new ArrayList<>(0);
    }
    ListModel<T> model = list.getModel();
    ListModelExtension<T, ListModel<T>> extension = getExtension(model);
    int firstSelectedIndex = indices[0];
    ArrayList<T> removedItems = new ArrayList<>();
    int deletedCount = 0;
    for (int idx1 : indices) {
      int index = idx1 - deletedCount;
      if (index < 0 || index >= model.getSize()) continue;
      T obj = extension.get(model, index);
      if (condition == null || condition.value(obj)) {
        removedItems.add(obj);
        extension.remove(model, index);
        deletedCount++;
      }
    }
    if (model.getSize() == 0) {
      list.clearSelection();
    }
    else if (list.getSelectedValue() == null) {
      // if nothing remains selected, set selected row
      if (firstSelectedIndex >= model.getSize()) {
        list.setSelectedIndex(model.getSize() - 1);
      }
      else {
        list.setSelectedIndex(firstSelectedIndex);
      }
    }
    return removedItems;
  }
private static <T> List<T> removeIndices(@NotNull JList<T> list, int @NotNull [] indices, @Nullable Condition<? super T> condition)