All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.container.list.MappingList Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
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));
	}
}