
com.artclod.common.collect.LinkedHashFSet 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.Iterator;
import java.util.LinkedHashSet;
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 LinkedHashFSet extends BaseFSet> {
private static final long serialVersionUID = 1L;
public static LinkedHashFSet wrap(LinkedHashSet inner) {
return new LinkedHashFSet(inner);
}
public static LinkedHashFSet create() {
return new LinkedHashFSet(Sets.newLinkedHashSet());
}
@SafeVarargs
public static LinkedHashFSet create(E... elements) {
LinkedHashFSet linkedHashFSet = new LinkedHashFSet(Sets.newLinkedHashSetWithExpectedSize(elements.length));
for(int i = 0; i < elements.length; i++) {
linkedHashFSet.add(elements[i]);
}
return linkedHashFSet;
}
public static LinkedHashFSet create(Iterable extends E> elements) {
return new LinkedHashFSet(Sets.newLinkedHashSet(elements));
}
public static LinkedHashFSet createWithExpectedSize(int expectedSize) {
return new LinkedHashFSet(Sets.newLinkedHashSetWithExpectedSize(expectedSize));
}
public LinkedHashFSet(LinkedHashSet inner) {
super(inner);
}
// This exist so we can create a CollectionBuilder of the right type
private static class LinkedHashFSetBuilder extends LinkedHashFSet implements CollectionBuilder> {
private static final long serialVersionUID = 1L;
public LinkedHashFSetBuilder(LinkedHashSet inner) {
super(inner);
}
@Override
public LinkedHashFSet build() {
return this;
}
}
@Override
protected CollectionBuilder> builder() {
return new LinkedHashFSetBuilder(new LinkedHashSet());
}
@Override
protected Iterator reverseIterator() {
return iterator(); // There is no sensible reverse of a HashSet
}
@Override
public LinkedHashFSet map(Function super E, ? extends O> f) {
LinkedHashFSet ret = new LinkedHashFSet(new LinkedHashSet());
for (E e : this) {
ret.add(f.apply(e));
}
return ret;
}
@Override
public LinkedHashFSet flatMap(Function super E, ? extends Collection extends O>> mapper) {
LinkedHashFSet ret = new LinkedHashFSet(new LinkedHashSet());
for (E e : this) {
ret.addAll(mapper.apply(e));
}
return ret;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy