<commit_before>(ns subrosa.observable
  (:import [org.jboss.netty.channel Channel])
  (:gen-class :extends java.util.Observable
              :state state
              :init init
              :constructors {[String] []}
              :methods [[ENGAGENOTIFICATIONSIMMEDIATELY
                         [org.jboss.netty.channel.Channel String]
                         void]]))

(defn -init [string]
  [[] (ref string)])

(defn -ENGAGENOTIFICATIONSIMMEDIATELY [this channel args]
  (.setChanged this)
  (.notifyObservers this [@(.state this) channel args]))

(def get-observable
  (memoize (fn [cmd] (subrosa.observable. cmd))))

(defn add-observer [cmd fn]
  (let [observable (get-observable (.toLowerCase (str cmd)))
        observer (reify java.util.Observer
                   (update [this observable args]
                           (apply fn args)))]
    (.addObserver observable observer)
    observer))

(let [observers (atom {})]
  (defn replace-observer [token cmd fn]
    (let [observable (get-observable (.toLowerCase (str cmd)))]
      (when-let [observer (@observers (str token cmd))]
        (.deleteObserver observable observer))<commit_msg>the command stored inside an observable instance doesn't need to be a ref, it can just be a string<commit_after>(ns subrosa.observable
  (:import [org.jboss.netty.channel Channel])
  (:gen-class :extends java.util.Observable
              :state state
              :init init
              :constructors {[String] []}
              :methods [[ENGAGENOTIFICATIONSIMMEDIATELY
                         [org.jboss.netty.channel.Channel String]
                         void]]))

(defn -init [string]
  [[] string])

(defn -ENGAGENOTIFICATIONSIMMEDIATELY [this channel args]
  (.setChanged this)
  (.notifyObservers this [(.state this) channel args]))

(def get-observable
  (memoize (fn [cmd] (subrosa.observable. cmd))))

(defn add-observer [cmd fn]
  (let [observable (get-observable (.toLowerCase (str cmd)))
        observer (reify java.util.Observer
                   (update [this observable args]
                     (apply fn args)))]
    (.addObserver observable observer)
    observer))

(let [observers (atom {})]
  (defn replace-observer [token cmd fn]
    (let [observable (get-observable (.toLowerCase (str cmd)))]
      (when-let [observer (@observers (str token cmd))]
        (.deleteObserver observable observer))
{'fraction_non_alphanumeric': 0.1226968174204355, 'fraction_numerical': 0.0, 'mean_word_length': 2.5550595238095237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4523494', 'n_tokens_mistral': 739, 'n_tokens_neox': 702, 'n_words': 198}