net.thucydides.core.requirements.RequirementsMerger Maven / Gradle / Ivy
package net.thucydides.core.requirements;
import net.serenitybdd.core.collect.NewList;
import net.serenitybdd.core.collect.NewList;
import net.thucydides.core.requirements.model.Requirement;
import java.util.ArrayList;
import java.util.List;
/**
* Created by john on 16/04/2015.
*/
public class RequirementsMerger {
public List merge(Iterable baseRequirements, Iterable newRequirements) {
List mergedRequirements = new ArrayList<>();
baseRequirements.forEach(
req -> mergedRequirements.add(req)
);
for(Requirement newRequirement : newRequirements) {
mergeNewRequirement(newRequirement, mergedRequirements);
}
return NewList.copyOf(mergedRequirements);
}
private void mergeNewRequirement(Requirement newRequirement, List existingRequirements) {
if (!existingRequirements.contains(newRequirement)) {
existingRequirements.add(newRequirement);
} else {
Requirement existing = existingRequirements.remove(existingRequirements.indexOf(newRequirement));
existingRequirements.add(existing.merge(newRequirement));
}
}
}