org.requirementsascode.ModelElementContainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of requirementsascodecore Show documentation
Show all versions of requirementsascodecore Show documentation
Enables you to define and run executable use case specifications, in your code.
package org.requirementsascode;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import org.requirementsascode.exception.ElementAlreadyInModel;
import org.requirementsascode.exception.NoSuchElementInModel;
/**
* Contains static helper methods to ease the implementation of model creation
* and finding elements in it, using maps.
*
* @author b_muth
*/
class ModelElementContainer {
static T findModelElement(String modelElementName,
Map modelElementNameToElementMap) {
Objects.requireNonNull(modelElementName);
Objects.requireNonNull(modelElementNameToElementMap);
if (!hasModelElement(modelElementName, modelElementNameToElementMap)) {
throw new NoSuchElementInModel(modelElementName);
}
T modelElement = modelElementNameToElementMap.get(modelElementName);
return modelElement;
}
static boolean hasModelElement(String modelElementName,
Map modelElementNameToElementMap) {
Objects.requireNonNull(modelElementName);
Objects.requireNonNull(modelElementNameToElementMap);
boolean hasModelElement = modelElementNameToElementMap.containsKey(modelElementName);
return hasModelElement;
}
static void saveModelElement(T modelElement, Map modelElementNameToElementMap) {
Objects.requireNonNull(modelElement);
Objects.requireNonNull(modelElementNameToElementMap);
String modelElementName = modelElement.getName();
if (hasModelElement(modelElementName, modelElementNameToElementMap)) {
throw new ElementAlreadyInModel(modelElementName);
}
modelElementNameToElementMap.put(modelElementName, modelElement);
}
static Collection getModelElements(Map modelElementNameToElementMap) {
Objects.requireNonNull(modelElementNameToElementMap);
return modelElementNameToElementMap.values();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy