use of eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory in project hale by halestudio.
the class HelperFunctionsExtension method addToCategory.
/**
* Add the given functions to the given category.
*
* @param category the category path
* @param functions the functions to add to the category
*/
private void addToCategory(String category, Iterable<HelperFunctionWrapper> functions) {
Iterable<String> path = Splitter.on('.').omitEmptyStrings().split(category);
Category cat = new Category(path);
Map<String, HelperFunctionOrCategory> catMap = children.get(cat);
if (catMap == null) {
catMap = new HashMap<>();
children.put(cat, catMap);
}
for (HelperFunctionWrapper function : functions) {
Object previous = catMap.put(function.getName(), function);
if (previous != null) {
log.error(MessageFormat.format("Duplicate helper function {0}.{1}", cat, function.getName()));
}
}
// make sure category is listed
while (cat != null) {
Category parent = cat.getParent();
Map<String, HelperFunctionOrCategory> parentMap = children.get(parent);
if (parentMap == null) {
parentMap = new HashMap<>();
children.put(parent, parentMap);
}
parentMap.put(cat.getName(), cat);
// check parent category
cat = parent;
}
}
Aggregations