forked from ghaskins/clojure-protobuf
/
common.clj
53 lines (41 loc) · 1.87 KB
/
common.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(ns protobuf.common)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Utility Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn get-class
[this]
(:protobuf-class (.contents this)))
(defn get-instance
[this]
(:instance (.contents this)))
(defn get-wrapper
[this]
(:java-wrapper (.contents this)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Behaviours ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def associative-behaviour
{:containsKey (fn [this data] (.containsKey (get-instance this) data))
:entryAt (fn [this data] (.entryAt (get-instance this) data))})
(def iterable-behaviour
{:forEach (fn [this consumer] (.forEach (get-instance this) consumer))
:iterator (fn [this] (.iterator (get-instance this)))
:spliterator (fn [this] (.spliterator (get-instance this)))})
(def lookup-behaviour
{:valAt (fn ([this k] (.valAt (get-instance this) k))
([this k fallback] (.valAt (get-instance this) k fallback)))})
(def persistent-collection-behaviour
{:cons (fn [this o] (.cons (get-instance this) o))
:count (fn [this] (.count (get-instance this)))
:empty (fn [this] (.empty (get-instance this)))
:equiv (fn [this o]
(and (= (get-class this) (get-class o))
(.equiv (get-instance this) (get-instance o))))})
(def persistent-map-behaviour
{:assoc (fn [this k v] (.assoc (get-instance this) k v))
:assocEx (fn [m k v] (throw (new Exception)))
:without (fn [this k] (.without (get-instance this) k))})
(def printable-behaviour
{:toString (fn [this] (.toString (get-instance this)))})
(def seqable-behaviour
{:seq (fn [this] (.seq (get-instance this)))})