Skip to content
Browse files

Remove the unnecessary time and other tools.

  • Loading branch information...
1 parent 7a75326 commit a412475fa91b764a3b6e74601018623f0d3b65b3 @Ruiyun committed Jul 31, 2012
Showing with 0 additions and 119 deletions.
  1. +0 −47 src/cljain/tools/predicate.clj
  2. +0 −72 src/cljain/tools/timer.clj
View
47 src/cljain/tools/predicate.clj
@@ -1,47 +0,0 @@
-(ns ^{:author "ruiyun"
- :added "0.2.0"
- :deprecated "0.4.0"}
- cljain.tools.predicate)
-
-(defn in?
- "Chekc whether v is in the coll or not."
- {:added "0.2.0"}
- [v coll]
- (some #(= % v) coll))
-
-(defmacro legal-option?
- "place doc string here"
- {:added "0.2.0"}
- [required? & decl]
- (let [options (first decl)
- decl (next decl)
- option-key (first decl)
- decl (next decl)
- modifier (if (= :by (first decl))
- (fnext decl)
- identity)
- decl (if (= :by (first decl))
- (nnext decl)
- decl)
- f (first decl)
- args (next decl)]
- `(let [popts# (partition-by (partial = ~option-key) ~options)
- opt_exist?# (> (count popts#) 1)]
- (if opt_exist?#
- (let [opt# (~modifier (first (last popts#)))]
- (~f opt# ~@args))
- (not ~required?)))))
-
-(defmacro check-required
- "place doc string here"
- {:arglists '([options option-key :by? option-modifier? f & args])
- :added "0.2.0"}
- [& decl]
- `(legal-option? true ~@decl))
-
-(defmacro check-optional
- "place doc string here"
- {:arglists '([options option-key :by? option-modifier? f & args])
- :added "0.2.0"}
- [& decl]
- `(legal-option? false ~@decl))
View
72 src/cljain/tools/timer.clj
@@ -1,72 +0,0 @@
-(ns ^{:doc "place doc string here"
- :author "ruiyun"}
- cljain.tools.timer
- (:use cljain.tools.predicate)
- (:import [java.util Timer TimerTask Date]))
-
-(defn timer
- "Create a new java.util.Timer object."
- {:added "0.2.0"}
- ([] (Timer.))
- ([name] (Timer. name)))
-
-(defn deamon-timer
- "Create a new java.util.Timer object with deamon option."
- {:added "0.2.0"}
- []
- (Timer. true))
-
-(defmacro task
- "Create a java.util.TimerTask object with some code."
- {:arglists '([body*])
- :added "0.2.0"}
- [& body]
- `(proxy [TimerTask] []
- (run []
- ~@body)))
-
-(defmulti run!
- "Execute a timer task, then return the timer user passed or new created.
- User must set one of the two options:
- :at <time>
- :delay <milliseconds>
-
- Optional, user can set
- :period <milliseconds>"
- {:arglists '([timer? task & options])
- :added "0.2.0"}
- (fn [a & more] (class a)))
-
-(defn- run-task!
- "The 'run!' functions internal implement."
- {:added "0.2.0"}
- [timer task options]
- {:pre [(even? (count options))
- (check-optional options :at #(instance? Date %))
- (check-optional options :delay >= 0)
- (check-optional options :period > 0)]
- :post [(instance? Timer %)]}
- (let [{start-time :at, delay :delay, period :period} (apply array-map options)]
- (cond
- (not (nil? start-time)) (if (nil? period)
- (.schedule timer task start-time)
- (.schedule timer task start-time period))
- (not (nil? delay)) (if (nil? period)
- (.schedule timer task delay)
- (.schedule timer task delay period))
- :else (throw (IllegalArgumentException. "Run a timer task must set :at or :delay option.")))
- timer))
-
-(defmethod run! Timer
- [timer task & options]
- (run-task! timer task options))
-
-(defmethod run! TimerTask
- [task & options]
- (run-task! (timer) task options))
-
-(defn cancel!
- "Terminates a timer, discarding any currently scheduled tasks."
- {:added "0.2.0"}
- [timer]
- (.cancel timer))

0 comments on commit a412475

Please sign in to comment.
Something went wrong with that request. Please try again.