use of io.fabric8.maven.core.util.KindAndName in project fabric8-maven-plugin by fabric8io.
the class DependencyEnricher method filterAndAddItemsToBuilder.
public void filterAndAddItemsToBuilder(KubernetesListBuilder builder, List<HasMetadata> items) {
Map<KindAndName, Integer> aIndexMap = new HashMap<>();
int nItems = 0;
// Populate map with existing items in the builder
for (int index = 0; index < builder.getItems().size(); index++, nItems++) {
HasMetadata aItem = builder.getItems().get(index);
KindAndName aKey = new KindAndName(aItem);
aIndexMap.put(aKey, index);
}
for (HasMetadata item : items) {
KindAndName aKey = new KindAndName(item);
if (aIndexMap.containsKey(aKey)) {
// Merge the override fragments, and remove duplicate
HasMetadata duplicateItem = builder.getItems().get(aIndexMap.get(aKey));
item = KubernetesResourceUtil.mergeResources(item, duplicateItem, log, false);
builder.setToItems(aIndexMap.get(aKey), item);
} else {
aIndexMap.put(aKey, nItems++);
builder.addToItems(item);
}
}
}
Aggregations