
org.apache.servicecomb.config.common.ConfigurationChangedEvent Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.servicecomb.config.common;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class ConfigurationChangedEvent {
private final Map added;
private final Map deleted;
private final Map updated;
private final boolean changed;
private Map complete;
private ConfigurationChangedEvent(Map added, Map updated,
Map deleted, boolean changed) {
this.added = added;
this.deleted = deleted;
this.updated = updated;
this.changed = changed;
}
public static ConfigurationChangedEvent createIncremental(Map latest, Map last) {
Map itemsCreated = new HashMap<>();
Map itemsDeleted = new HashMap<>();
Map itemsModified = new HashMap<>();
boolean changed = false;
for (Map.Entry entry : latest.entrySet()) {
String itemKey = entry.getKey();
if (!last.containsKey(itemKey)) {
itemsCreated.put(itemKey, entry.getValue());
changed = true;
} else if (!Objects.equals(last.get(itemKey), latest.get(itemKey))) {
itemsModified.put(itemKey, entry.getValue());
changed = true;
}
}
for (String itemKey : last.keySet()) {
if (!latest.containsKey(itemKey)) {
itemsDeleted.put(itemKey, null);
changed = true;
}
}
ConfigurationChangedEvent event = ConfigurationChangedEvent
.createIncremental(itemsCreated, itemsModified, itemsDeleted, changed);
event.complete = latest;
return event;
}
private static ConfigurationChangedEvent createIncremental(Map added, Map updated,
Map deleted, boolean changed) {
return new ConfigurationChangedEvent(added, updated, deleted, changed);
}
public final Map getAdded() {
return added;
}
public final Map getUpdated() {
return updated;
}
public final Map getDeleted() {
return deleted;
}
public final Map getComplete() {
return complete;
}
public final boolean isChanged() {
return changed;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy