| Paste number 66351: | clojure-java data conversion |
| Pasted by: | drewr |
| When: | 9 months, 4 weeks ago |
| Share: | Tweet this! | http://paste.lisp.org/+1F73 |
| Channel: | #clojure |
| Paste contents: |
(defn clean-db [message]
(dissoc message :db))
(defn to-arraylist [l]
(let [arraylist (java.util.ArrayList.)]
(loop [_l l]
(if _l
(let [e (first _l)]
(.add arraylist (convert-type e))
(recur (rest _l)))
arraylist))))
(defn to-hashmap [m]
(let [hashmap (java.util.HashMap.)]
(loop [_m m]
(if _m
(let [[k v] (first _m)]
(.put hashmap k (convert-type v))
(recur (rest _m)))
hashmap))))
(defn convert-type [element]
(cond
(or (instance? clojure.lang.APersistentMap element)
(instance? clojure.lang.MapEntry element))
(to-hashmap (clean-db element))
(or (instance? clojure.lang.APersistentVector element)
(instance? clojure.lang.PersistentList element))
(to-arraylist element)
true element))
This paste has no annotations.