com.ajjpj.afoundation.collection.immutable.AListSet Maven / Gradle / Ivy
The newest version!
package com.ajjpj.afoundation.collection.immutable;
import com.ajjpj.afoundation.collection.AEquality;
import java.util.Arrays;
/**
* @author arno
*/
public class AListSet extends MapAsSetWrapper> {
@SuppressWarnings ("unchecked")
private static final AListSet EMPTY_EQUALS = new AListSet (AListMap.empty (AEquality.EQUALS));
@SuppressWarnings ("unchecked")
private static final AListSet EMPTY_IDENTITY = new AListSet (AListMap.empty (AEquality.IDENTITY));
public static AListSet empty () {
return empty (AEquality.EQUALS);
}
@SuppressWarnings ("unchecked")
public static AListSet empty (AEquality equality) {
if (equality == AEquality.EQUALS) {
return EMPTY_EQUALS;
}
if (equality == AEquality.IDENTITY) {
return EMPTY_IDENTITY;
}
return new AListSet<> (AHashMap. empty (equality));
}
@SuppressWarnings ("unchecked")
public static AListSet create (T... elements) {
return create (AEquality.EQUALS, elements);
}
public static AListSet create (Iterable elements) {
return create (AEquality.EQUALS, elements);
}
@SuppressWarnings ("unchecked")
public static AListSet create (AEquality equality, T... elements) {
return create (equality, Arrays.asList (elements));
}
public static AListSet create (AEquality equality, Iterable elements) {
AListSet result = empty (equality);
for (T el: elements) {
result = result.added (el);
}
return result;
}
public static AListSet create (AHashMap inner) {
return new AListSet<> (inner);
}
public AListSet (AMap inner) {
super (inner);
}
@Override protected AListSet wrapAsSet (AMap inner) {
return new AListSet<> (inner);
}
}