<commit_before>package org.yawni.wn.browser;

import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.text.DefaultEditorKit;

class ActionHelper {
  private static final Map<String, Action> ACTIONS;
  private static final String SELECT_ALL_CUT = "SELECT_ALL_CUT";
  static {
    final DefaultEditorKit dek = new DefaultEditorKit();
    ACTIONS = new HashMap<String, Action>();
    final Action[] actionsArray = dek.getActions();
    for (int i = 0; i < actionsArray.length; i++) {
      final Action a = actionsArray[i];
      //System.err.println("a: "+a+" name: "+a.getValue(Action.NAME));
      ACTIONS.put((String) a.getValue(Action.NAME), a);
    }
    assert ACTIONS.containsKey(DefaultEditorKit.selectAllAction);
    assert ACTIONS.containsKey(DefaultEditorKit.cutAction);
    // goal: composite action: selectAllAction + cutAction
    ACTIONS.put(SELECT_ALL_CUT, compose(ACTIONS.get(DefaultEditorKit.selectAllAction), ACTIONS.get(DefaultEditorKit.cutAction)));
  }

  private static Action compose(final Action... actions) {
    assert actions.length >= 2;
    String name = "";
    int ai = 0;
    for (final Action action : actions) {
      final String aname = (String) action.getValue(Action.NAME);
      assert aname != null && aname.length() > 0;
      name += aname;
      if (ai != actions.length - 1) {
        name += "-";
      }
    }
    return new AbstractAction(name) {
      private static final long serialVersionUID = 1L;

      public void actionPerformed(final ActionEvent e) {
        for (final Action action : actions) {
          action.actionPerformed(e);
        }
      }
    };
  }

  static Action selectAllCut() {
    return ACTIONS.get(SELECT_ALL_CUT);
  }
}<commit_msg>added comments, clear() action (doesnt put content on clipboard though)<commit_after>package org.yawni.wn.browser;

import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.JTextComponent;
import javax.swing.text.TextAction;

// TODO
// call this EditorKitHelper / StyledEditorKitHelper
class ActionHelper {
  private static final Map<String, Action> ACTIONS;
  private static final String SELECT_ALL_CUT = "SELECT_ALL_CUT";
  private static final String CLEAR = "CLEAR";
  static {
    final DefaultEditorKit dek = new DefaultEditorKit();
    ACTIONS = new HashMap<String, Action>();
    final Action[] actionsArray = dek.getActions();
    for (int i = 0; i < actionsArray.length; i++) {
      final Action a = actionsArray[i];
      //System.err.println("a: "+a+" name: "+a.getValue(Action.NAME));
      ACTIONS.put((String) a.getValue(Action.NAME), a);
    }
    assert ACTIONS.containsKey(DefaultEditorKit.selectAllAction);
    assert ACTIONS.containsKey(DefaultEditorKit.cutAction);
    // goal: composite action: selectAllAction + cutAction
    ACTIONS.put(SELECT_ALL_CUT, compose(ACTIONS.get(DefaultEditorKit.selectAllAction), ACTIONS.get(DefaultEditorKit.cutAction)));
    ACTIONS.put(CLEAR, new TextAction("clear") {
      public void actionPerformed(ActionEvent e) {
        final JTextComponent target = getTextComponent(e);
        if (target != null) {
          target.setText("");
        }
      }
    });
  }

  private static Action compose(final Action... actions) {
    assert actions.length >= 2;
    String name = "";
    int ai = 0;
    for (final Action action : actions) {
      final String aname = (String) action.getValue(Action.NAME);
      assert aname != null && aname.length() > 0;
      name += aname;
      if (ai != actions.length - 1) {
        name += "-";
      }
    }
    return new AbstractAction(name) {
      private static final long serialVersionUID = 1L;

      public void actionPerformed(final ActionEvent e) {
        for (final Action action : actions) {
          action.actionPerformed(e);
        }
      }
    };
  }

  static Action selectAllCut() {
    return ACTIONS.get(SELECT_ALL_CUT);
  }
  static Action clear() {
    return ACTIONS.get(CLEAR);
  }
}
{'fraction_non_alphanumeric': 0.11884265901482544, 'fraction_numerical': 0.0028694404591104736, 'mean_word_length': 3.3079299691040163, 'pattern_counts': {'":': 0, '<': 9, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2367631', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1237, 'n_words': 310}