<commit_before>package zephyr.plugin.common.control;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import rlpark.plugin.utils.events.Listener;
import rlpark.plugin.utils.events.Signal;
import rlpark.plugin.utils.time.Clock;
import zephyr.plugin.common.ZephyrPluginCommon;
import zephyr.plugin.common.internal.SavedSettings;
import zephyr.plugin.common.utils.Helper;

public class Control implements Listener<Clock> {
  public Signal<Control> onModeChange = new Signal<Control>();
  private final Map<Clock, Integer> suspended = new LinkedHashMap<Clock, Integer>();

  public Control() {
  }

  public void connectSuspendOnJobStarting() {
    ZephyrPluginCommon.viewBinder().onClockAdded.connect(new Listener<Clock>() {
      @Override
      public void listen(Clock clock) {
        if (!Helper.booleanState(SavedSettings.STARTSUSPENDED, false))
          return;
        suspendClock(clock);
        onModeChange.fire(Control.this);
      }
    });
  }

  public void step() {
    for (Map.Entry<Clock, Integer> entry : suspended.entrySet())
      suspended.put(entry.getKey(), 1);
    notifyAll(getToWakeUp());
  }

  public void suspend() {
    assert !isSuspended();
    for (Clock clock : ZephyrPluginCommon.viewBinder().getClocks())
      suspendClock(clock);
    onModeChange.fire(this);
  }

  protected void suspendClock(Clock clock) {
    if (!clock.isSuspendable)
      return;
    suspended.put(clock, 0);
    clock.onTick.connect(this);
  }

  public void resume() {
    assert isSuspended();
    List<Clock> toWakeUp = getToWakeUp();
    for (Clock clock : toWakeUp)
      clock.onTick.disconnect(this);<commit_msg>Prevent from clock being suspended multiple times<commit_after>package zephyr.plugin.common.control;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import rlpark.plugin.utils.events.Listener;
import rlpark.plugin.utils.events.Signal;
import rlpark.plugin.utils.time.Clock;
import zephyr.plugin.common.ZephyrPluginCommon;
import zephyr.plugin.common.internal.SavedSettings;
import zephyr.plugin.common.utils.Helper;

public class Control implements Listener<Clock> {
  public Signal<Control> onModeChange = new Signal<Control>();
  private final Map<Clock, Integer> suspended = new LinkedHashMap<Clock, Integer>();

  public Control() {
  }

  public void connectSuspendOnJobStarting() {
    ZephyrPluginCommon.viewBinder().onClockAdded.connect(new Listener<Clock>() {
      @Override
      public void listen(Clock clock) {
        if (!Helper.booleanState(SavedSettings.STARTSUSPENDED, false))
          return;
        suspendClock(clock);
        onModeChange.fire(Control.this);
      }
    });
  }

  public void step() {
    for (Map.Entry<Clock, Integer> entry : suspended.entrySet())
      suspended.put(entry.getKey(), 1);
    notifyAll(getToWakeUp());
  }

  public void suspend() {
    assert !isSuspended();
    for (Clock clock : ZephyrPluginCommon.viewBinder().getClocks())
      suspendClock(clock);
    onModeChange.fire(this);
  }

  protected void suspendClock(Clock clock) {
    if (!clock.isSuspendable)
      return;
    Integer previous = suspended.put(clock, 0);
    if (previous == null)
      clock.onTick.connect(this);
  }

  public void resume() {
    assert isSuspended();
    List<Clock> toWakeUp = getToWakeUp();
    for (Clock clock : toWakeUp)
      clock.onTick.disconnect(this);
{'fraction_non_alphanumeric': 0.11868322263933007, 'fraction_numerical': 0.001155067860236789, 'mean_word_length': 3.9344729344729346, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5012430', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1067, 'n_words': 216}