com.softicar.platform.common.container.list.MappingList 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.list;
import java.util.AbstractList;
import java.util.List;
import java.util.function.Function;
/**
* A {@link List} that maps the elements from one type to another.
*
* @author Oliver Richers
*/
public class MappingList extends AbstractList {
private final List sourceList;
private final Function mappingFunction;
public MappingList(List sourceList, Function mappingFunction) {
this.sourceList = sourceList;
this.mappingFunction = mappingFunction;
}
@Override
public int size() {
return sourceList.size();
}
@Override
public T get(int index) {
return mappingFunction.apply(sourceList.get(index));
}
}