<commit_before>package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.event.*;
import java.io.*;
import java.net.URISyntaxException;
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.table.*;

public final class MainPanel extends JPanel {
    private static final int IMAGE_ID = 0;
    private final FileModel model = new FileModel();
    private final JTable table = new JTable(model);
    private transient MediaTracker tracker;

    private class ImageDropTargetListener extends DropTargetAdapter {
        @Override public void dragOver(DropTargetDragEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                dtde.acceptDrag(DnDConstants.ACTION_COPY);
                return;
            }
            dtde.rejectDrag();
        }
        @Override public void drop(DropTargetDropEvent dtde) {
            try {
                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                    dtde.acceptDrop(DnDConstants.ACTION_COPY);
                    Transferable transferable = dtde.getTransferable();
                    List list = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor);
                    for (Object o: list) {
                        if (o instanceof File) {
                            addImageFile((File) o);
                        }
                    }
                    dtde.dropComplete(true);
                    return;
                }
            } catch (UnsupportedFlavorException | IOException ex) {
                ex.printStackTrace();
            }
            dtde.rejectDrop();
        }
    }

    public MainPanel() {
        super(new BorderLayout());
        table.setAutoCreateRowSorter(true);

        JScrollPane scroll = new JScrollPane(table);
        scroll.setComponentPopupMenu(new TablePopupMenu());
        table.setInheritsPopupMenu(true);

        DropTargetListener dtl = new ImageDropTargetListener();
        new DropTarget(table, DnDConstants.ACTION_COPY, dtl, true);
        new DropTarget(scroll.getViewport(), DnDConstants.ACTION_COPY, dtl, true);

        TableColumn col = table.getColumnModel().getColumn(0);
        col.setMinWidth(60);
        col.setMaxWidth(60);
        col.setResizable(false);

        try {
            addImageFile(new File(getClass().getResource("test.png").toURI()));
        } catch (URISyntaxException ex) {
            ex.printStackTrace();
        }
        add(scroll);
        setPreferredSize(new Dimension(320, 240));
    }

    private void addImageFile(File file) {
        String path = file.getAbsolutePath();
        Image img = Toolkit.getDefaultToolkit().createImage(path);
        if (Objects.isNull(tracker)) {
            tracker = new MediaTracker((Container) this);
        }
        tracker.addImage(img, IMAGE_ID);
        try {
            tracker.waitForID(IMAGE_ID);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        } finally {
            if (!tracker.isErrorID(IMAGE_ID)) {
                model.addTest(new Test(file.getName(), path,
                                       img.getWidth(this), img.getHeight(this)));
            }
            tracker.removeImage(img);
        }
    }

    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class FileModel extends DefaultTableModel {
    private static final List<ColumnContext> COLUMN_LIST = Arrays.asList(
        new ColumnContext("No.",       Integer.class, false),
        new ColumnContext("Name",      String.class,  false),
        new ColumnContext("Full Path", String.class,  false),
        new ColumnContext("Width",     Integer.class, false),
        new ColumnContext("Height",    Integer.class, false)
    );
    private int number;
    public void addTest(Test t) {
        Object[] obj = {
            number, t.getName(), t.getComment(),
            t.getWidth(), t.getHeight()
        };
        super.addRow(obj);
        number++;
    }
    @Override public boolean isCellEditable(int row, int col) {
        return COLUMN_LIST.get(col).isEditable;
    }
    @Override public Class<?> getColumnClass(int column) {
        return COLUMN_LIST.get(column).columnClass;
    }
    @Override public int getColumnCount() {
        return COLUMN_LIST.size();<commit_msg>refactor: use Optional.orElseGet instead of if (Objects.isNull(o)) {...}<commit_after>package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.event.*;
import java.io.*;
import java.net.URISyntaxException;
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.table.*;

public final class MainPanel extends JPanel {
    private static final int IMAGE_ID = 0;
    private final FileModel model = new FileModel();
    private final JTable table = new JTable(model);
    private transient MediaTracker tracker;

    private class ImageDropTargetListener extends DropTargetAdapter {
        @Override public void dragOver(DropTargetDragEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                dtde.acceptDrag(DnDConstants.ACTION_COPY);
                return;
            }
            dtde.rejectDrag();
        }
        @Override public void drop(DropTargetDropEvent dtde) {
            try {
                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                    dtde.acceptDrop(DnDConstants.ACTION_COPY);
                    Transferable transferable = dtde.getTransferable();
                    ((List<?>) transferable.getTransferData(DataFlavor.javaFileListFlavor))
                        .stream().filter(o -> o instanceof File).forEach(o -> addImageFile((File) o));
//                     List list = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor);
//                     for (Object o: list) {
//                         if (o instanceof File) {
//                             addImageFile((File) o);
//                         }
//                     }
                    dtde.dropComplete(true);
                    return;
                }
            } catch (UnsupportedFlavorException | IOException ex) {
                ex.printStackTrace();
            }
            dtde.rejectDrop();
        }
    }

    public MainPanel() {
        super(new BorderLayout());
        table.setAutoCreateRowSorter(true);

        JScrollPane scroll = new JScrollPane(table);
        scroll.setComponentPopupMenu(new TablePopupMenu());
        table.setInheritsPopupMenu(true);

        DropTargetListener dtl = new ImageDropTargetListener();
        new DropTarget(table, DnDConstants.ACTION_COPY, dtl, true);
        new DropTarget(scroll.getViewport(), DnDConstants.ACTION_COPY, dtl, true);

        TableColumn col = table.getColumnModel().getColumn(0);
        col.setMinWidth(60);
        col.setMaxWidth(60);
        col.setResizable(false);

        try {
            addImageFile(new File(getClass().getResource("test.png").toURI()));
        } catch (URISyntaxException ex) {
            ex.printStackTrace();
        }
        add(scroll);
        setPreferredSize(new Dimension(320, 240));
    }

    private void addImageFile(File file) {
        String path = file.getAbsolutePath();
        Image img = Toolkit.getDefaultToolkit().createImage(path);
        tracker = Optional.ofNullable(tracker).orElseGet(() -> new MediaTracker((Container) this));
        tracker.addImage(img, IMAGE_ID);
        try {
            tracker.waitForID(IMAGE_ID);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        } finally {
            if (!tracker.isErrorID(IMAGE_ID)) {
                model.addTest(new Test(file.getName(), path, img.getWidth(this), img.getHeight(this)));
            }
            tracker.removeImage(img);
        }
    }

    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class FileModel extends DefaultTableModel {
    private static final List<ColumnContext> COLUMN_LIST = Arrays.asList(
        new ColumnContext("No.",       Integer.class, false),
        new ColumnContext("Name",      String.class,  false),
        new ColumnContext("Full Path", String.class,  false),
        new ColumnContext("Width",     Integer.class, false),
        new ColumnContext("Height",    Integer.class, false)
    );
    private int number;
    public void addTest(Test t) {
        Object[] obj = {
            number, t.getName(), t.getComment(), t.getWidth(), t.getHeight()
        };
        super.addRow(obj);
        number++;
    }
    @Override public boolean isCellEditable(int row, int col) {
        return COLUMN_LIST.get(col).isEditable;
    }
    @Override public Class<?> getColumnClass(int column) {
        return COLUMN_LIST.get(column).columnClass;
    }
    @Override public int getColumnCount() {
        return COLUMN_LIST.size();
{'fraction_non_alphanumeric': 0.10876928867143394, 'fraction_numerical': 0.0026345502446368085, 'mean_word_length': 2.183288409703504, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2001721', 'n_tokens_mistral': 2908, 'n_tokens_neox': 2851, 'n_words': 581}