| 15 | import java.util.Comparator; |
| 16 | |
| 17 | public class PersistentTreeSet extends APersistentSet implements IObj, Reversible, Sorted{ |
| 18 | static public final PersistentTreeSet EMPTY = new PersistentTreeSet(null, PersistentTreeMap.EMPTY); |
| 19 | final IPersistentMap _meta; |
| 20 | |
| 21 | |
| 22 | static public PersistentTreeSet create(ISeq items){ |
| 23 | PersistentTreeSet ret = EMPTY; |
| 24 | for(; items != null; items = items.next()) |
| 25 | { |
| 26 | ret = (PersistentTreeSet) ret.cons(items.first()); |
| 27 | } |
| 28 | return ret; |
| 29 | } |
| 30 | |
| 31 | static public PersistentTreeSet create(Comparator comp, ISeq items){ |
| 32 | PersistentTreeSet ret = new PersistentTreeSet(null, new PersistentTreeMap(null, comp)); |
| 33 | for(; items != null; items = items.next()) |
| 34 | { |
| 35 | ret = (PersistentTreeSet) ret.cons(items.first()); |
| 36 | } |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | PersistentTreeSet(IPersistentMap meta, IPersistentMap impl){ |
| 41 | super(impl); |
| 42 | this._meta = meta; |
| 43 | } |
| 44 | |
| 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 | |
| 61 | public IPersistentSet disjoin(Object key) { |
| 62 | if(contains(key)) |
| 63 | return new PersistentTreeSet(meta(),impl.without(key)); |
| 64 | return this; |
| 65 | } |
| 66 | |
| 67 | public IPersistentSet cons(Object o){ |
| 68 | if(contains(o)) |
| 69 | return this; |
| 70 | return new PersistentTreeSet(meta(),impl.assoc(o,o)); |
| 71 | } |
| 72 | |
| 73 | public IPersistentCollection empty(){ |
| 74 | return new PersistentTreeSet(meta(),(PersistentTreeMap)impl.empty()); |
nothing calls this directly
no outgoing calls
no test coverage detected