com.softicar.platform.common.container.collection.MappingCollection 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.collection;
import com.softicar.platform.common.container.iterator.MappingIterator;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Function;
/**
* A {@link Collection} that maps the elements from one type to another.
*
* @author Oliver Richers
*/
public class MappingCollection extends AbstractCollection {
private final Collection sourceCollection;
private final Function mappingFunction;
public MappingCollection(Collection sourceCollection, Function mappingFunction) {
this.sourceCollection = sourceCollection;
this.mappingFunction = mappingFunction;
}
@Override
public Iterator iterator() {
return new MappingIterator<>(sourceCollection.iterator(), mappingFunction);
}
@Override
public int size() {
return sourceCollection.size();
}
}