mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 10:30:56 +00:00
Invert chronological order so that latest message is at the top of the tree.
This commit is contained in:
parent
09563d1480
commit
8ac8c808ae
@ -14,18 +14,7 @@
|
||||
insertion-point (find-chronological-insertion-point root 99 event-map)]
|
||||
(should= 0 insertion-point)))
|
||||
|
||||
(it "returns zero if time is earlier than all events in tree"
|
||||
(let [root (DefaultMutableTreeNode.)
|
||||
child-id 1
|
||||
child (DefaultMutableTreeNode. child-id)
|
||||
_ (.add ^DefaultMutableTreeNode root child)
|
||||
event {:id 99 :created-at 1}
|
||||
event-map {99 event
|
||||
child-id {:created-at 10}}
|
||||
insertion-point (find-chronological-insertion-point root 99 event-map)]
|
||||
(should= 0 insertion-point)))
|
||||
|
||||
(it "returns 1 when event is later than only event in tree"
|
||||
(it "returns zero if time is later than all events in tree"
|
||||
(let [root (DefaultMutableTreeNode.)
|
||||
child-id 1
|
||||
child (DefaultMutableTreeNode. child-id)
|
||||
@ -34,10 +23,21 @@
|
||||
event-map {99 event
|
||||
child-id {:created-at 10}}
|
||||
insertion-point (find-chronological-insertion-point root 99 event-map)]
|
||||
(should= 0 insertion-point)))
|
||||
|
||||
(it "returns 1 when event is ealier than only event in tree"
|
||||
(let [root (DefaultMutableTreeNode.)
|
||||
child-id 1
|
||||
child (DefaultMutableTreeNode. child-id)
|
||||
_ (.add ^DefaultMutableTreeNode root child)
|
||||
event {:id 99 :created-at 5}
|
||||
event-map {99 event
|
||||
child-id {:created-at 10}}
|
||||
insertion-point (find-chronological-insertion-point root 99 event-map)]
|
||||
(should= 1 insertion-point))
|
||||
)
|
||||
|
||||
(it "returns n when event is later than n events in tree"
|
||||
(it "returns n when event is earlier than n events in tree"
|
||||
(let [root (DefaultMutableTreeNode.)
|
||||
child-id 1
|
||||
child-1 (DefaultMutableTreeNode. child-id)
|
||||
@ -46,7 +46,7 @@
|
||||
_ (.add ^DefaultMutableTreeNode root child-1)
|
||||
_ (.add ^DefaultMutableTreeNode root child-2)
|
||||
_ (.add ^DefaultMutableTreeNode root child-3)
|
||||
event {:id 99 :created-at 20}
|
||||
event {:id 99 :created-at 5}
|
||||
event-map {99 event
|
||||
child-id {:created-at 10}
|
||||
(+ 1 child-id) {:created-at 10}
|
||||
@ -54,7 +54,7 @@
|
||||
insertion-point (find-chronological-insertion-point root 99 event-map)]
|
||||
(should= 3 insertion-point)))
|
||||
|
||||
(it "returns chronological insertion point"
|
||||
(it "returns chronological insertion point above first earliest"
|
||||
(let [root (DefaultMutableTreeNode.)
|
||||
child-id 1
|
||||
child-1 (DefaultMutableTreeNode. child-id)
|
||||
@ -63,11 +63,11 @@
|
||||
_ (.add ^DefaultMutableTreeNode root child-1)
|
||||
_ (.add ^DefaultMutableTreeNode root child-2)
|
||||
_ (.add ^DefaultMutableTreeNode root child-3)
|
||||
event {:id 99 :created-at 25}
|
||||
event {:id 99 :created-at 15}
|
||||
event-map {99 event
|
||||
child-id {:created-at 10}
|
||||
child-id {:created-at 30}
|
||||
(+ 1 child-id) {:created-at 20}
|
||||
(+ 2 child-id) {:created-at 30}}
|
||||
(+ 2 child-id) {:created-at 10}}
|
||||
insertion-point (find-chronological-insertion-point root 99 event-map)]
|
||||
(should= 2 insertion-point))
|
||||
)
|
||||
|
@ -64,14 +64,15 @@
|
||||
orphans (get-in @ui-context [:orphaned-references parent-id])]
|
||||
(if (empty? orphans)
|
||||
nil
|
||||
(loop [orphans orphans]
|
||||
(if (empty? orphans)
|
||||
nil
|
||||
(let [orphan-id (first orphans)
|
||||
orphan-node (DefaultMutableTreeNode. orphan-id)]
|
||||
(.add ^DefaultMutableTreeNode parent-node orphan-node)
|
||||
(swap! ui-context update-in [:node-map orphan-id] conj orphan-node)
|
||||
(recur (rest orphans))))
|
||||
(do
|
||||
(loop [orphans orphans]
|
||||
(if (empty? orphans)
|
||||
nil
|
||||
(let [orphan-id (first orphans)
|
||||
orphan-node (DefaultMutableTreeNode. orphan-id)]
|
||||
(.add ^DefaultMutableTreeNode parent-node orphan-node)
|
||||
(swap! ui-context update-in [:node-map orphan-id] conj orphan-node)
|
||||
(recur (rest orphans)))))
|
||||
(swap! ui-context assoc-in [:orphaned-references parent-id] nil))))
|
||||
)
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
(let [comparator (fn [node1 node2]
|
||||
(let [v1 (->> node1 .getUserObject (get event-map) :created-at)
|
||||
v2 (->> node2 .getUserObject (get event-map) :created-at)]
|
||||
(compare v1 v2)))
|
||||
(compare v2 v1)))
|
||||
children (enumeration-seq (.children root))
|
||||
dummy-node (DefaultMutableTreeNode. event-id)
|
||||
insertion-point (if (nil? children)
|
||||
|
Loading…
Reference in New Issue
Block a user