@Override
 public synchronized void sortRows(final Comparator<Integer> cmp) {
   ensureChangeAllowed();
   final int[] perm = ArrayUtil.createPermutation(cmp, rows());
   ArrayUtil.applyPermutation(matrix, perm);
   ArrayUtil.applyPermutation(heights, perm);
   ArrayUtil.applyPermutation(rowNames, perm);
 }
  @Override
  public synchronized void sortColumns(final Comparator<Integer> cmp) {
    ensureChangeAllowed();
    final ArrayList<T> column = new ArrayList<>();
    final int[] perm = ArrayUtil.createPermutation(cmp, cols());
    ArrayUtil.applyPermutation(
        new Swapable() {

          @Override
          public void swap(final int col1, final int col2) {
            setColumn(setColumn(getColumn(column, col1), col2), col1);
          }
        },
        perm);
    column.clear();
    ArrayUtil.applyPermutation(widths, perm);
    ArrayUtil.applyPermutation(colNames, perm);
  }