org.organicdesign.fp.collections.ImInsertOrderSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of UncleJim Show documentation
Show all versions of UncleJim Show documentation
Immutable Clojure collections and a Transformation abstraction for Java 8+, immutably, type-safely, and with good performance. Name will change to "Paguro" in November 2016.
package org.organicdesign.fp.collections;
import java.io.Serializable;
import java.util.Map;
import static org.organicdesign.fp.collections.ImInsertOrderMap.setComparator;
public class ImInsertOrderSet implements ImSet, Serializable {
// For serializable. Make sure to change whenever internal data format changes.
private static final long serialVersionUID = 20160915083900L;
private final ImInsertOrderMap inner;
private ImInsertOrderSet(ImInsertOrderMap m) { inner = m; }
private static final ImInsertOrderSet EMPTY = new ImInsertOrderSet<>(ImInsertOrderMap.empty());
@SuppressWarnings("unchecked")
private static ImInsertOrderSet empty() { return EMPTY; }
/** To keep constructor private. */
static ImInsertOrderSet ofMap(ImInsertOrderMap map) {
return new ImInsertOrderSet<>(map);
}
@SuppressWarnings("SuspiciousMethodCalls")
@Override public boolean contains(Object o) { return inner.containsKey(o); }
@Override public UnmodSortedIterator iterator() {
return inner.toImSortedSet(setComparator())
.map(Map.Entry::getKey)
.toImList().iterator();
}
@SuppressWarnings("unchecked")
@Override public ImInsertOrderSet put(E e) {
return new ImInsertOrderSet<>((ImInsertOrderMap)
((ImInsertOrderMap) inner).assoc(e, e));
}
@Override public int size() { return inner.size(); }
@Override public ImInsertOrderSet without(E key) {
return new ImInsertOrderSet<>(inner).without(key);
}
}