
com.artclod.common.collect.HashFSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functional-collections Show documentation
Show all versions of functional-collections Show documentation
FCollections is a series of function style Java Collections
package com.artclod.common.collect;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Function;
import com.artclod.common.collect.base.BaseFSet;
import com.artclod.common.collect.builder.CollectionBuilder;
import com.google.common.collect.Sets;
public class HashFSet extends BaseFSet> {
private static final long serialVersionUID = 1L;
public static HashFSet wrap(HashSet inner) {
return new HashFSet(inner);
}
public static HashFSet create() {
return new HashFSet(Sets.newHashSet());
}
@SafeVarargs
public static HashFSet create(E... elements) {
return new HashFSet(Sets.newHashSet(elements));
}
public static HashFSet create(Iterable extends E> elements) {
return new HashFSet(Sets.newHashSet(elements));
}
public static HashFSet create(Iterator extends E> elements) {
return new HashFSet(Sets.newHashSet(elements));
}
public static HashFSet createWithExpectedSize(int expectedSize) {
return new HashFSet(Sets.newHashSetWithExpectedSize(expectedSize));
}
public HashFSet(HashSet inner) {
super(inner);
}
// This exist so we can create a CollectionBuilder of the right type
private static class HashFSetBuilder extends HashFSet implements CollectionBuilder> {
private static final long serialVersionUID = 1L;
public HashFSetBuilder(HashSet inner) {
super(inner);
}
@Override
public HashFSet build() {
return this;
}
}
@Override
protected CollectionBuilder> builder() {
return new HashFSetBuilder(new HashSet());
}
@Override
protected Iterator reverseIterator() {
return iterator(); // There is no sensible reverse of a HashSet
}
@Override
public FSet map(Function super E, ? extends O> f) {
HashFSet ret = new HashFSet(new HashSet());
for (E e : this) {
ret.add(f.apply(e));
}
return ret;
}
@Override
public HashFSet flatMap(Function super E, ? extends Collection extends O>> mapper) {
HashFSet ret = new HashFSet(new HashSet());
for (E e : this) {
ret.addAll(mapper.apply(e));
}
return ret;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy