Skip to content

Commit b80e1fe

Browse files
bronsastuarthalloway
authored andcommitted
CLJ-1242: equals doesn't throw on sorted collections
Signed-off-by: Stuart Halloway <[email protected]>
1 parent 2ff700e commit b80e1fe

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/jvm/clojure/lang/PersistentTreeMap.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ public boolean containsKey(Object key){
9494
return entryAt(key) != null;
9595
}
9696

97+
public boolean equals(Object obj){
98+
try {
99+
return super.equals(obj);
100+
} catch (ClassCastException e) {
101+
return false;
102+
}
103+
}
104+
105+
public boolean equiv(Object obj){
106+
try {
107+
return super.equiv(obj);
108+
} catch (ClassCastException e) {
109+
return false;
110+
}
111+
}
112+
97113
public PersistentTreeMap assocEx(Object key, Object val) {
98114
Box found = new Box(null);
99115
Node t = add(tree, key, val, found);

src/jvm/clojure/lang/PersistentTreeSet.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ static public PersistentTreeSet create(Comparator comp, ISeq items){
4242
this._meta = meta;
4343
}
4444

45+
public boolean equals(Object obj){
46+
try {
47+
return super.equals(obj);
48+
} catch (ClassCastException e) {
49+
return false;
50+
}
51+
}
52+
53+
public boolean equiv(Object obj){
54+
try {
55+
return super.equiv(obj);
56+
} catch (ClassCastException e) {
57+
return false;
58+
}
59+
}
60+
4561
public IPersistentSet disjoin(Object key) {
4662
if(contains(key))
4763
return new PersistentTreeSet(meta(),impl.without(key));

test/clojure/test_clojure/data_structures.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@
202202
(hash-map :a 1 :b 2)
203203
(array-map :a 1 :b 2))
204204

205+
(is (not= (sorted-set :a) (sorted-set 1)))
206+
205207
; sorted-set vs. hash-set
206208
(is (not= (class (sorted-set 1)) (class (hash-set 1))))
207209
(are [x y] (= x y)

0 commit comments

Comments
 (0)