<commit_before>/*
 * This file is part of the GOsa project -  http://gosa-project.org
 *
 * Copyright:
 *    (C) 2010-2017 GONICUS GmbH, Germany, http://www.gonicus.de
 *
 * License:
 *    LGPL-2.1: http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * See the LICENSE file in the project's top-level directory for details.
 */

//noinspection JSUnusedGlobalSymbols
/**
 * This Mixin allows method hooks which can be called before or after a method.
 * This is a possible way circumvent the problem that mixin cannot override methods of
 * the including classes, instead one can add an "after" hook for the method.
 * The downside is that the main class method has to be augmented with calls to the hook processor.
 *
 *  <h3>Example</h3>
 *  Adding child controls by Mixins:
 *  To add child controls by Mixins you have to add an 'after' hook to the '_createChildControlImpl' method.
 *  E.g. if the Mixin's child control generating method is called '__createMixinChildControlImpl' you can add the hook like this:
 *  <pre class="javascript">
 *    this.addHook("after", "_createChildControlImpl", this.__createMixinChildControlImpl, this);
 *  </pre>
 *  Having done that you have to add the processor call to the main classes '_createChildControlImpl'-method like this:
 *  <pre class="javascript">
 *   _createChildControlImpl: function(id) {
 *      var control;
 *
 *      switch(id) {
 *        ...
 *      }
 *      if (!control) {
 *        control = this.processHooks("after", "_createChildControlImpl", id);
 *      }
 *
 *      return control || this.base(arguments, id);
 *   }
 *  </pre>
 */
qx.Mixin.define("gosa.util.MMethodChaining", {

  /*
   *****************************************************************************
   MEMBERS
   *****************************************************************************
   */
  members : {
    __hooks: null,

    /**
     * Add a method hook. Usually the callbacks should not return anything. If it does
     * the processor stops at that point and returns the value, other callbacks in that chain
     * are not executed in that case.
     *
     * @param type {String} 'before' or 'after'
     * @param method {String} original method this hook id added to
     * @param callback {Function} callback to be called as hook
     * @param context {Object}
     * @return {String} hook id
     */
    addHook: function(type, method, callback, context) {
      if (!this.__hooks) {
        this.__hooks = {
          before: {},
          after: {}
        };
      }
      if (qx.core.Environment.get('qx.debug')) {
        this.assertKeyInMap(type, this.__hooks);
      }
      if (!this.__hooks[type][method]) {
        this.__hooks[type][method] = [[callback, context]];
      } else {
        this.__hooks[type][method].push([callback, context]);
      }
      return type+"|"+method+"|"+this.__hooks[type][method].length-1;
    },

    /**
     * Removes a method hook by the given id
     * @param id {String} Hook id
     * @return {Boolean} True if the hook has been deleted successfully
     */
    removeHook: function(id) {
      var parts = id.split("|");
      return this.__hooks[parts[0]][parts[1]].splice([parts[2]], 1).length === 1;
    },

    /**
     * Process the hooks for a given method and type.
     * This method requires the arguments type, method. All additions arguments are passed to the<commit_msg>make it static<commit_after>/*
 * This file is part of the GOsa project -  http://gosa-project.org
 *
 * Copyright:
 *    (C) 2010-2017 GONICUS GmbH, Germany, http://www.gonicus.de
 *
 * License:
 *    LGPL-2.1: http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * See the LICENSE file in the project's top-level directory for details.
 */

//noinspection JSUnusedGlobalSymbols
/**
 * This Mixin allows method hooks which can be called before or after a method.
 * This is a possible way circumvent the problem that mixin cannot override methods of
 * the including classes, instead one can add an "after" hook for the method.
 * The downside is that the main class method has to be augmented with calls to the hook processor.
 *
 *  <h3>Example</h3>
 *  Adding child controls by Mixins:
 *  To add child controls by Mixins you have to add an 'after' hook to the '_createChildControlImpl' method.
 *  E.g. if the Mixin's child control generating method is called '__createMixinChildControlImpl' you can add the hook like this:
 *  <pre class="javascript">
 *    this.addHook("after", "_createChildControlImpl", this.__createMixinChildControlImpl, this);
 *  </pre>
 *  Having done that you have to add the processor call to the main classes '_createChildControlImpl'-method like this:
 *  <pre class="javascript">
 *   _createChildControlImpl: function(id) {
 *      var control;
 *
 *      switch(id) {
 *        ...
 *      }
 *      if (!control) {
 *        control = this.processHooks("after", "_createChildControlImpl", id);
 *      }
 *
 *      return control || this.base(arguments, id);
 *   }
 *  </pre>
 */
qx.Mixin.define("gosa.util.MMethodChaining", {

  /*
   *****************************************************************************
   MEMBERS
   *****************************************************************************
   */
  members : {
    __hooks: null,

    /**
     * Add a method hook. Usually the callbacks should not return anything. If it does
     * the processor stops at that point and returns the value, other callbacks in that chain
     * are not executed in that case.
     *
     * @param type {String} 'before' or 'after'
     * @param method {String} original method this hook id added to
     * @param callback {Function} callback to be called as hook
     * @param context {Object}
     * @return {String} hook id
     */
    addHook: function(type, method, callback, context) {
      if (!this.__hooks) {
        this.__hooks = {
          before: {},
          after: {}
        };
      }
      if (qx.core.Environment.get('qx.debug')) {
        qx.core.Assert.assertKeyInMap(type, this.__hooks);
      }
      if (!this.__hooks[type][method]) {
        this.__hooks[type][method] = [[callback, context]];
      } else {
        this.__hooks[type][method].push([callback, context]);
      }
      return type+"|"+method+"|"+this.__hooks[type][method].length-1;
    },

    /**
     * Removes a method hook by the given id
     * @param id {String} Hook id
     * @return {Boolean} True if the hook has been deleted successfully
     */
    removeHook: function(id) {
      var parts = id.split("|");
      return this.__hooks[parts[0]][parts[1]].splice([parts[2]], 1).length === 1;
    },

    /**
     * Process the hooks for a given method and type.
     * This method requires the arguments type, method. All additions arguments are passed to the
{'fraction_non_alphanumeric': 0.15965766563376124, 'fraction_numerical': 0.005902316659288771, 'mean_word_length': 2.9338363319791063, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4940460', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1915, 'n_words': 655}