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

net.thucydides.core.requirements.RequirementsMerger Maven / Gradle / Ivy

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy