use of org.eclipse.microprofile.openapi.models.Extensible in project wildfly-swarm by wildfly-swarm.
the class MergeUtil method mergeMaps.
/**
* Merges two Maps. Any values missing from Map1 but present in Map2 will be added. If a value
* is present in both maps, it will be overridden or merged.
* @param values1
* @param values2
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Map mergeMaps(Map values1, Map values2) {
if (values1 == null && values2 == null) {
return null;
}
if (values1 != null && values2 == null) {
return values1;
}
if (values1 == null && values2 != null) {
return values2;
}
for (Object key : values2.keySet()) {
if (values1.containsKey(key)) {
Object pval1 = values1.get(key);
Object pval2 = values2.get(key);
if (pval1 instanceof Map) {
values1.put(key, mergeMaps((Map) pval1, (Map) pval2));
} else if (pval1 instanceof List) {
values1.put(key, mergeLists((List) pval1, (List) pval2));
} else if (pval1 instanceof Constructible) {
values1.put(key, mergeObjects(pval1, pval2));
} else {
values1.put(key, pval2);
}
} else {
Object pval2 = values2.get(key);
values1.put(key, pval2);
}
}
if (values1 instanceof Constructible) {
if (values1 instanceof Reference) {
Reference ref1 = (Reference) values1;
Reference ref2 = (Reference) values2;
if (ref2.getRef() != null) {
ref1.setRef(ref2.getRef());
}
}
if (values1 instanceof Extensible) {
Extensible extensible1 = (Extensible) values1;
Extensible extensible2 = (Extensible) values2;
extensible1.setExtensions(mergeMaps(extensible1.getExtensions(), extensible2.getExtensions()));
}
if (values1 instanceof APIResponses) {
APIResponses responses1 = (APIResponses) values1;
APIResponses responses2 = (APIResponses) values2;
responses1.defaultValue(mergeObjects(responses1.getDefault(), responses2.getDefault()));
}
}
return values1;
}
Aggregations