<commit_before>package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;

public final class MainPanel extends JPanel {
    private final JTextField textField = new JTextField("soccer");
    public MainPanel() {
        super(new BorderLayout());
        final JTree tree1 = new JTree();
        tree1.setExpandsSelectedPaths(false);

        final JTree tree2 = new JTree();
        tree2.setExpandsSelectedPaths(true);

        JPanel p1 = new JPanel(new GridLayout(1, 2));
        p1.setBorder(BorderFactory.createTitledBorder("setExpandsSelectedPaths"));
        p1.add(makeTitledScrollPane(tree1, "false"));
        p1.add(makeTitledScrollPane(tree2, "true"));

        JPanel p2 = new JPanel(new BorderLayout());
        p2.add(textField);
        p2.add(new JButton(new AbstractAction("Select") {
            @Override public void actionPerformed(ActionEvent e) {
                String q = textField.getText().trim();
                searchTree(tree1, tree1.getPathForRow(0), q);
                searchTree(tree2, tree2.getPathForRow(0), q);
            }
        }), BorderLayout.EAST);

        add(p1);
        add(p2, BorderLayout.SOUTH);
        setPreferredSize(new Dimension(320, 240));
    }
    private static JScrollPane makeTitledScrollPane(Component view, String title) {
        JScrollPane scroll = new JScrollPane(view);
        scroll.setBorder(BorderFactory.createTitledBorder(title));
        return scroll;
    }
    private static void searchTree(JTree tree, TreePath path, String q) {
        TreeNode node = (TreeNode) path.getLastPathComponent();
        if (Objects.isNull(node)) {
            return;
        }
        if (node.toString().equals(q)) {
            tree.addSelectionPath(path);
        }
        if (!node.isLeaf() && node.getChildCount() >= 0) {
            Enumeration e = node.children();
            while (e.hasMoreElements()) {
                searchTree(tree, path.pathByAddingChild(e.nextElement()), q);
            }
        }
    }
    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.DISPOSE_ON_CLOSE);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();<commit_msg>refactor: use o instanceof TreeNode instead of Objects.isNull(o)<commit_after>package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;

public final class MainPanel extends JPanel {
    private final JTextField textField = new JTextField("soccer");
    public MainPanel() {
        super(new BorderLayout());
        final JTree tree1 = new JTree();
        tree1.setExpandsSelectedPaths(false);

        final JTree tree2 = new JTree();
        tree2.setExpandsSelectedPaths(true);

        JPanel p1 = new JPanel(new GridLayout(1, 2));
        p1.setBorder(BorderFactory.createTitledBorder("setExpandsSelectedPaths"));
        p1.add(makeTitledScrollPane(tree1, "false"));
        p1.add(makeTitledScrollPane(tree2, "true"));

        JPanel p2 = new JPanel(new BorderLayout());
        p2.add(textField);
        p2.add(new JButton(new AbstractAction("Select") {
            @Override public void actionPerformed(ActionEvent e) {
                String q = textField.getText().trim();
                searchTree(tree1, tree1.getPathForRow(0), q);
                searchTree(tree2, tree2.getPathForRow(0), q);
            }
        }), BorderLayout.EAST);

        add(p1);
        add(p2, BorderLayout.SOUTH);
        setPreferredSize(new Dimension(320, 240));
    }
    private static JScrollPane makeTitledScrollPane(Component view, String title) {
        JScrollPane scroll = new JScrollPane(view);
        scroll.setBorder(BorderFactory.createTitledBorder(title));
        return scroll;
    }
    private static void searchTree(JTree tree, TreePath path, String q) {
        Object o = path.getLastPathComponent();
        if (o instanceof TreeNode) {
            TreeNode node = (TreeNode) o;
            if (node.toString().equals(q)) {
                tree.addSelectionPath(path);
            }
            if (!node.isLeaf() && node.getChildCount() >= 0) {
                Enumeration e = node.children();
                while (e.hasMoreElements()) {
                    searchTree(tree, path.pathByAddingChild(e.nextElement()), q);
                }
            }
        }
    }
    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.DISPOSE_ON_CLOSE);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
{'fraction_non_alphanumeric': 0.117, 'fraction_numerical': 0.010666666666666666, 'mean_word_length': 2.4748118123914304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4038084', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1670, 'n_words': 340}