<commit_before>package com.wmba.actiondispatcher;

import com.wmba.actiondispatcher.persist.PersistedActionHolder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;

import rx.Observable;
import rx.Scheduler;
import rx.Single;
import rx.SingleSubscriber;

public class ActionDispatcher {
  private final Object mPersistentLock = new Object();

  private final ExecutorCache mExecutorCache = new ExecutorCache();

  private final KeySelector mKeySelector;
  private final ActionPreparer mActionPreparer;
  private final ActionLogger mActionLogger;
  private final ActionPersister mActionPersister;

  /**
   * Is null until the persisted Actions have been loaded. If no Actions are loaded, it is replaced
   * with an empty list.
   */
  private List<PersistedActionHolder> mPersistedActions = null;
  private boolean mPendingRunPersistentActions = false;

  /**
   * Used for queueing actions before the persisted Actions have loaded when the dispatcher is
   * first starting. Both of these lists are kept in sync, and always modified under the
   * mPersistentLock.
   */
  private List<Executor> mQueuedActionExecutors = null;
  private List<Runnable> mQueuedActionRunnables = null;

  public ActionDispatcher(KeySelector keySelector, ActionPreparer actionPreparer,
      ActionLogger actionLogger, ActionPersister actionPersister,
      Map<String, Executor> executorMap, final boolean delayPersistentActionLoading) {
    mKeySelector = keySelector;
    mActionPreparer = actionPreparer;
    mActionLogger = actionLogger;
    mActionPersister = actionPersister;

    for (Map.Entry<String, Executor> entry : executorMap.entrySet()) {
      mExecutorCache.setExecutor(entry.getValue(), entry.getKey());
    }

    if (mActionPersister != null) {
      Executor executor = mExecutorCache.getExecutorForKey(KeySelector.ASYNC_KEY);
      executor.execute(new Runnable() {
        @Override public void run() {
          try {
            List<PersistedActionHolder> persistedActions = mActionPersister.getPersistedActions();
            if (persistedActions == null) {
              persistedActions = new ArrayList<PersistedActionHolder>(0);
            }

            if (mActionLogger != null)
              mActionLogger.logDebug("Loaded " + persistedActions.size() + " persistent Actions");
<commit_msg>fix tests<commit_after>package com.wmba.actiondispatcher;

import com.wmba.actiondispatcher.persist.PersistedActionHolder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;

import rx.Observable;
import rx.Scheduler;
import rx.Single;
import rx.SingleSubscriber;

public class ActionDispatcher {
  private final Object mPersistentLock = new Object();

  private final ExecutorCache mExecutorCache = new ExecutorCache();

  private final KeySelector mKeySelector;
  private final ActionPreparer mActionPreparer;
  private final ActionLogger mActionLogger;
  private final ActionPersister mActionPersister;

  /**
   * Is null until the persisted Actions have been loaded. If no Actions are loaded, it is replaced
   * with an empty list.
   */
  private List<PersistedActionHolder> mPersistedActions = null;
  private boolean mPendingRunPersistentActions = false;

  /**
   * Used for queueing actions before the persisted Actions have loaded when the dispatcher is
   * first starting. Both of these lists are kept in sync, and always modified under the
   * mPersistentLock.
   */
  private List<Executor> mQueuedActionExecutors = null;
  private List<Runnable> mQueuedActionRunnables = null;

  public ActionDispatcher(KeySelector keySelector, ActionPreparer actionPreparer,
      ActionLogger actionLogger, ActionPersister actionPersister,
      Map<String, Executor> executorMap, final boolean delayPersistentActionLoading) {
    mKeySelector = keySelector;
    mActionPreparer = actionPreparer;
    mActionLogger = actionLogger;
    mActionPersister = actionPersister;

    if (executorMap != null) {
      for (Map.Entry<String, Executor> entry : executorMap.entrySet()) {
        mExecutorCache.setExecutor(entry.getValue(), entry.getKey());
      }
    }

    if (mActionPersister != null) {
      Executor executor = mExecutorCache.getExecutorForKey(KeySelector.ASYNC_KEY);
      executor.execute(new Runnable() {
        @Override public void run() {
          try {
            List<PersistedActionHolder> persistedActions = mActionPersister.getPersistedActions();
            if (persistedActions == null) {
              persistedActions = new ArrayList<PersistedActionHolder>(0);
            }

            if (mActionLogger != null)
              mActionLogger.logDebug("Loaded " + persistedActions.size() + " persistent Actions");

{'fraction_non_alphanumeric': 0.07712820512820513, 'fraction_numerical': 0.00041025641025641023, 'mean_word_length': 4.02680412371134, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '1890320', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1293, 'n_words': 366}