fitnesse.util.partitioner.MapBasedListPartitioner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse Show documentation
Show all versions of fitnesse Show documentation
The fully integrated standalone wiki, and acceptance testing framework.
The newest version!
package fitnesse.util.partitioner;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;
/**
* Partitions list based on map indicating known positions for elenents.
* @param list element type
*/
public class MapBasedListPartitioner extends FunctionBasedListPartitioner {
private final Map positionMap;
public MapBasedListPartitioner(Function keyFunction, Map positionMap) {
this(keyFunction, positionMap, (parts, nf) -> new EqualLengthListPartitioner().split(nf, parts.size()));
}
public MapBasedListPartitioner(Function keyFunction, Map positionMap,
BiFunction>, List, List>> notFoundFunction) {
super(
t -> {
String key = keyFunction.apply(t);
Integer value = positionMap.get(key);
return Optional.ofNullable(value);
},
notFoundFunction);
this.positionMap = positionMap;
}
@Override
protected List addUsingPositionFunction(List source, List> result) {
if (positionMap.isEmpty()) {
return source;
} else {
return super.addUsingPositionFunction(source, result);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy