All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.organicdesign.fp.collections.ImInsertOrderSet Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 2.0.13
Show newest version
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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy