package org.springframework.data.crossstore;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;
public class HashMapChangeSet implements ChangeSet {
private final Map<String, Object> values;
public HashMapChangeSet(Map<String, Object> values) {
this.values = values;
}
public HashMapChangeSet() {
this(new HashMap<>());
}
public void set(String key, Object o) {
values.put(key, o);
}
public String toString() {
return "HashMapChangeSet: values=[" + values + "]";
}
public Map<String, Object> getValues() {
return Collections.unmodifiableMap(values);
}
@Nullable
public Object removeProperty(String k) {
return this.values.remove(k);
}
@Nullable
public <T> T get(String key, Class<T> requiredClass, ConversionService conversionService) {
Object value = values.get(key);
if (value == null) {
return null;
}
return conversionService.convert(value, requiredClass);
}
}