<commit_before>package com.javacreed.api.swing.common.table;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

import javax.swing.table.AbstractTableModel;

public class BasicTableModel<T> extends AbstractTableModel implements Iterable<T> {

  @FunctionalInterface
  public static interface RowEqualizer<E> {
    boolean areEquals(E a, E b);
  }

  private static final long serialVersionUID = 3543147549154064649L;

  private final RowEqualizer<T> rowEqualizer = this::defaultAreRowEquals;

  private final transient List<Column<T>> columns = new ArrayList<>();

  private List<T> rows = new ArrayList<>();

  public void addColumn(final Column<T> column) {
    this.columns.add(column);
    fireTableStructureChanged();
  }

  public int addRow(final T row) {
    final int index = this.rows.size();
    this.rows.add(row);
    fireTableRowsInserted(index, index);
    return index;
  }

  public int addRowIfUnique(final T row) {
    for (int i = 0, size = rows.size(); i < size; i++) {
      final T existing = rows.get(i);
      if (rowEqualizer.areEquals(row, existing)) {
        return -(i - 1);
      }
    }

    return addRow(row);
  }

  public void addRows(final Collection<T> rows) {
    if (false == rows.isEmpty()) {
      final int index = this.rows.size();
      this.rows.addAll(rows);
      fireTableRowsInserted(index, rows.size() - 1);
    }
  }

  public void addRowsIfUnique(final Collection<T> rows) {
    for (final T row : rows) {
      addRowIfUnique(row);
    }
  }

  public void clear() {
    clearSilently();
    fireTableDataChanged();
  }

  public void clearSilently() {
    rows.clear();
  }

  protected boolean defaultAreRowEquals(final T a, final T b) {
    if (a == null) {
      return b == null;
    }

    return a.equals(b);
  }

  public int findRowIndex(final T object) {
    for (int i = 0, size = rows.size(); i < size; i++) {
      if (object.equals(rows.get(i))) {
        return i;
      }
    }

    return -1;
  }

  @Override
  public Class<?> getColumnClass(final int columnIndex) {
    return columns.get(columnIndex).getType();
  }

  @Override
  public int getColumnCount() {
    return columns.size();
  }

  @Override
  public String getColumnName(final int columnIndex) {
    return columns.get(columnIndex).getName();
  }

  public T getRowAt(final int index) {
    return rows.get(index);
  }

  @Override
  public int getRowCount() {
    return rows.size();
  }

  public List<T> getRows() {
    return rows;
  }

  public Stream<T> getRowsAsStream() {
    return rows.stream();
  }

  @Override
  public Object getValueAt(final int rowIndex, final int columnIndex) {
    final T row = rows.get(rowIndex);
    return columns.get(columnIndex).get(row);
  }

  @Override
  public boolean isCellEditable(final int rowIndex, final int columnIndex) {
    final T row = rows.get(rowIndex);
    return columns.get(columnIndex).isEditable(row);
  }

  public boolean isEmpty() {
    return rows.isEmpty();
  }

  @Override
  public Iterator<T> iterator() {
    return rows.iterator();
  }

  public void removeRowAt(final int rowIndex) {
    rows.remove(rowIndex);
    fireTableRowsDeleted(rowIndex, rowIndex);
  }

  public boolean removeRowObject(final T object) {
    final int rowIndex = findRowIndex(object);
    if (rowIndex == -1) {<commit_msg>Manual Row Ordering<commit_after>package com.javacreed.api.swing.common.table;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

import javax.swing.table.AbstractTableModel;

public class BasicTableModel<T> extends AbstractTableModel implements Iterable<T> {

  @FunctionalInterface
  public static interface RowEqualizer<E> {
    boolean areEquals(E a, E b);
  }

  private static final long serialVersionUID = 3543147549154064649L;

  private final RowEqualizer<T> rowEqualizer = this::defaultAreRowEquals;

  private final transient List<Column<T>> columns = new ArrayList<>();

  private List<T> rows = new ArrayList<>();

  public void addColumn(final Column<T> column) {
    this.columns.add(column);
    fireTableStructureChanged();
  }

  public int addRow(final T row) {
    final int index = this.rows.size();
    this.rows.add(row);
    fireTableRowsInserted(index, index);
    return index;
  }

  public int addRowIfUnique(final T row) {
    for (int i = 0, size = rows.size(); i < size; i++) {
      final T existing = rows.get(i);
      if (rowEqualizer.areEquals(row, existing)) {
        return -(i - 1);
      }
    }

    return addRow(row);
  }

  public void addRows(final Collection<T> rows) {
    if (false == rows.isEmpty()) {
      final int index = this.rows.size();
      this.rows.addAll(rows);
      fireTableRowsInserted(index, rows.size() - 1);
    }
  }

  public void addRowsIfUnique(final Collection<T> rows) {
    for (final T row : rows) {
      addRowIfUnique(row);
    }
  }

  public void clear() {
    clearSilently();
    fireTableDataChanged();
  }

  public void clearSilently() {
    rows.clear();
  }

  protected boolean defaultAreRowEquals(final T a, final T b) {
    if (a == null) {
      return b == null;
    }

    return a.equals(b);
  }

  public int findRowIndex(final T object) {
    for (int i = 0, size = rows.size(); i < size; i++) {
      if (object.equals(rows.get(i))) {
        return i;
      }
    }

    return -1;
  }

  @Override
  public Class<?> getColumnClass(final int columnIndex) {
    return columns.get(columnIndex).getType();
  }

  @Override
  public int getColumnCount() {
    return columns.size();
  }

  @Override
  public String getColumnName(final int columnIndex) {
    return columns.get(columnIndex).getName();
  }

  public T getRowAt(final int index) {
    return rows.get(index);
  }

  @Override
  public int getRowCount() {
    return rows.size();
  }

  public List<T> getRows() {
    return rows;
  }

  public Stream<T> getRowsAsStream() {
    return rows.stream();
  }

  @Override
  public Object getValueAt(final int rowIndex, final int columnIndex) {
    final T row = rows.get(rowIndex);
    return columns.get(columnIndex).get(row);
  }

  @Override
  public boolean isCellEditable(final int rowIndex, final int columnIndex) {
    final T row = rows.get(rowIndex);
    return columns.get(columnIndex).isEditable(row);
  }

  public boolean isEmpty() {
    return rows.isEmpty();
  }

  @Override
  public Iterator<T> iterator() {
    return rows.iterator();
  }

  public boolean moveRowDown(final int index) {
    /* Last row */
    if (index == rows.size() - 1) {
      return false;
    }

    final T a = rows.get(index);
    final T b = rows.get(index + 1);

    rows.set(index, b);
    rows.set(index + 1, a);

    fireTableRowsUpdated(index, index + 1);
    return true;
  }

  public int moveRowDown(final T row) {
    final int index = findRowIndex(row);
    if (index == -1) {
      return -1;
    }

    if (moveRowDown(index)) {
      return index + 1;
    }

    return index;
  }

  public boolean moveRowUp(final int index) {
    /* Last row */
    if (index == 0) {
      return false;
    }

    final T a = rows.get(index);
    final T b = rows.get(index - 1);

    rows.set(index, b);
    rows.set(index - 1, a);

    fireTableRowsUpdated(index - 1, index);
    return true;
  }

  public int moveRowUp(final T row) {
    final int index = findRowIndex(row);
    if (index == -1) {
      return -1;
    }

    if (moveRowUp(index)) {
      return index - 1;
    }

    return index;
  }

  public void removeRowAt(final int rowIndex) {
    rows.remove(rowIndex);
    fireTableRowsDeleted(rowIndex, rowIndex);
  }

  public boolean removeRowObject(final T object) {
    final int rowIndex = findRowIndex(object);
    if (rowIndex == -1) {
{'fraction_non_alphanumeric': 0.1220059880239521, 'fraction_numerical': 0.007984031936127744, 'mean_word_length': 3.018546365914787, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1920020', 'n_tokens_mistral': 2660, 'n_tokens_neox': 2549, 'n_words': 677}