org.archifacts.integration.c4.model.C4ModelComputer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of archifacts-c4-model Show documentation
Show all versions of archifacts-c4-model Show documentation
archifacts C4 Model integration
The newest version!
package org.archifacts.integration.c4.model;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.archifacts.core.model.Archifact;
import com.structurizr.model.ModelItem;
public final class C4ModelComputer {
private final Set> computationRules = new HashSet<>();
private final Map> mappings = new ConcurrentHashMap<>();
private final C4ModelLookup lookup;
private final ComputationFunction defaultComputation;
public C4ModelComputer(final C4ModelLookup lookup, final ComputationFunction defaultComputation) {
this.lookup = lookup;
this.defaultComputation = defaultComputation;
}
public void addComputationRule(final ModelItemComputationRule computationRule) {
computationRules.add(computationRule);
}
public Set compute(final ARCHIFACT archifact) {
return mappings.computeIfAbsent(archifact, a -> computationRules.stream()
.filter(rule -> rule.test(a))
.collect(Collectors.>toOptionalSingleton())
.orElse(defaultComputation)
.apply(a, lookup));
}
public Map> getMappings() {
return mappings;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy