com.softicar.platform.common.container.set.MappingSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.container.set;
import com.softicar.platform.common.container.iterator.MappingIterator;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Set;
import java.util.function.Function;
/**
* A {@link Set} that maps the elements using a {@link Function}.
*
* @author Oliver Richers
*/
public class MappingSet extends AbstractSet {
private final Set sourceSet;
private final Function mappingFunction;
public MappingSet(Set sourceSet, Function mappingFunction) {
this.sourceSet = sourceSet;
this.mappingFunction = mappingFunction;
}
@Override
public int size() {
return sourceSet.size();
}
@Override
public Iterator iterator() {
return new MappingIterator<>(sourceSet.iterator(), mappingFunction);
}
}