org.cloudfoundry.multiapps.controller.process.util.ElementUpdater Maven / Gradle / Ivy
package org.cloudfoundry.multiapps.controller.process.util;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.SetUtils;
import org.cloudfoundry.multiapps.common.util.MapUtil;
public interface ElementUpdater {
List updateList(List oldList, List newList);
Set updateSet(Set oldSet, Set newSet);
Map updateMap(Map oldMap, Map newMap);
class AttributeReplacer implements ElementUpdater {
@Override
public List updateList(List oldList, List newList) {
return newList;
}
@Override
public Set updateSet(Set oldSet, Set newSet) {
return newSet;
}
@Override
public Map updateMap(Map oldMap, Map newMap) {
return newMap;
}
}
class AttributeMerger implements ElementUpdater {
@Override
public List updateList(List oldList, List newList) {
List newPartsOnly = ListUtils.subtract(newList, oldList);
return ListUtils.union(oldList, newPartsOnly);
}
@Override
public Set updateSet(Set oldSet, Set newSet) {
return SetUtils.union(oldSet, newSet)
.toSet();
}
@Override
public Map updateMap(Map oldMap, Map newMap) {
return MapUtil.merge(oldMap, newMap);
}
}
static ElementUpdater getUpdater(UpdateStrategy updateStrategy) {
if (updateStrategy == UpdateStrategy.REPLACE) {
return new AttributeReplacer();
}
return new AttributeMerger();
}
enum UpdateStrategy {
REPLACE, MERGE
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy