<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 TreeComboBox<DefaultMutableTreeNode> combo = new TreeComboBox<>();
    public MainPanel() {
        super(new BorderLayout());
        DefaultComboBoxModel<DefaultMutableTreeNode> model1 = new DefaultComboBoxModel<>();
        DefaultComboBoxModel<DefaultMutableTreeNode> model2 = new DefaultComboBoxModel<>();
        TreeModel tm = makeModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) tm.getRoot();
//         Enumeration<?> depth = root.depthFirstEnumeration();
//         while (depth.hasMoreElements()) {
//             DefaultMutableTreeNode node = (DefaultMutableTreeNode) depth.nextElement();
//             if (node.isRoot()) {
//                 break;
//             }
//             model.insertElementAt(node, 0);
//         }
        makeComboBoxModel(model1, root);
        makeComboBoxModel(model2, root);
        combo.setModel(model2);
        combo.setSelectedIndex(-1);

        Box box = Box.createVerticalBox();
        box.add(createPanel(new JComboBox<>(model1), "default:"));
        box.add(Box.createVerticalStrut(5));
        box.add(createPanel(combo, "Tree ComboBoxModel:"));
        box.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        add(box, BorderLayout.NORTH);
        setPreferredSize(new Dimension(320, 240));
    }
    private static void makeComboBoxModel(DefaultComboBoxModel<DefaultMutableTreeNode> model, DefaultMutableTreeNode node) {
        if (!node.isRoot()) {
            model.addElement(node);
        }
        if (!node.isLeaf() && node.getChildCount() >= 0) {
            Enumeration<?> e = node.children();
            while (e.hasMoreElements()) {
                makeComboBoxModel(model, (DefaultMutableTreeNode) e.nextElement());
            }
        }
    }
    private static TreeModel makeModel() {
        return new JTree().getModel();
//         DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
//         DefaultMutableTreeNode set1 = new DefaultMutableTreeNode("Set 001");
//         DefaultMutableTreeNode set2 = new DefaultMutableTreeNode("Set 002");
//         DefaultMutableTreeNode set3 = new DefaultMutableTreeNode("Set 003");
//         set1.add(new DefaultMutableTreeNode("111111111"));
//         set1.add(new DefaultMutableTreeNode("22222222222"));
//         set1.add(new DefaultMutableTreeNode("33333"));
//         set2.add(new DefaultMutableTreeNode("asdfasdfas"));
//         set2.add(set3);
//         set2.add(new DefaultMutableTreeNode("asdf"));
//         set3.add(new DefaultMutableTreeNode("asdfasdfasdf"));
//         set3.add(new DefaultMutableTreeNode("qwerqwer"));
//         set3.add(new DefaultMutableTreeNode("zvxcvzxcvzxzxcvzxcv"));
//         root.add(set1);<commit_msg>refactor: use Collections.list(enum).stream() instead of while (enum.hasMoreElements())<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 TreeComboBox<DefaultMutableTreeNode> combo = new TreeComboBox<>();
    public MainPanel() {
        super(new BorderLayout());
        DefaultComboBoxModel<DefaultMutableTreeNode> model1 = new DefaultComboBoxModel<>();
        DefaultComboBoxModel<DefaultMutableTreeNode> model2 = new DefaultComboBoxModel<>();
        TreeModel tm = makeModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) tm.getRoot();
//         Enumeration<?> depth = root.depthFirstEnumeration();
//         while (depth.hasMoreElements()) {
//             DefaultMutableTreeNode node = (DefaultMutableTreeNode) depth.nextElement();
//             if (node.isRoot()) {
//                 break;
//             }
//             model.insertElementAt(node, 0);
//         }
        makeComboBoxModel(model1, root);
        makeComboBoxModel(model2, root);
        combo.setModel(model2);
        combo.setSelectedIndex(-1);

        Box box = Box.createVerticalBox();
        box.add(createPanel(new JComboBox<>(model1), "default:"));
        box.add(Box.createVerticalStrut(5));
        box.add(createPanel(combo, "Tree ComboBoxModel:"));
        box.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        add(box, BorderLayout.NORTH);
        setPreferredSize(new Dimension(320, 240));
    }
    private static void makeComboBoxModel(DefaultComboBoxModel<DefaultMutableTreeNode> model, DefaultMutableTreeNode node) {
        if (!node.isRoot()) {
            model.addElement(node);
        }
        if (!node.isLeaf() && node.getChildCount() > 0) {
            Collections.list((Enumeration<?>) node.children()).stream()
              .filter(DefaultMutableTreeNode.class::isInstance)
              .map(DefaultMutableTreeNode.class::cast)
              .forEach(n -> makeComboBoxModel(model, n));
        }
    }
    private static TreeModel makeModel() {
        return new JTree().getModel();
//         DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
//         DefaultMutableTreeNode set1 = new DefaultMutableTreeNode("Set 001");
//         DefaultMutableTreeNode set2 = new DefaultMutableTreeNode("Set 002");
//         DefaultMutableTreeNode set3 = new DefaultMutableTreeNode("Set 003");
//         set1.add(new DefaultMutableTreeNode("111111111"));
//         set1.add(new DefaultMutableTreeNode("22222222222"));
//         set1.add(new DefaultMutableTreeNode("33333"));
//         set2.add(new DefaultMutableTreeNode("asdfasdfas"));
//         set2.add(set3);
//         set2.add(new DefaultMutableTreeNode("asdf"));
//         set3.add(new DefaultMutableTreeNode("asdfasdfasdf"));
//         set3.add(new DefaultMutableTreeNode("qwerqwer"));
//         set3.add(new DefaultMutableTreeNode("zvxcvzxcvzxzxcvzxcv"));
//         root.add(set1);
{'fraction_non_alphanumeric': 0.13640792465086066, 'fraction_numerical': 0.02273465410847678, 'mean_word_length': 2.9658725048293624, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '2483926', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1730, 'n_words': 310}