pl.allegro.tech.hermes.api.PatchData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hermes-api Show documentation
Show all versions of hermes-api Show documentation
Fast and reliable message broker built on top of Kafka.
package pl.allegro.tech.hermes.api;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import pl.allegro.tech.hermes.api.jackson.PatchDataDeserializer;
import pl.allegro.tech.hermes.api.jackson.PatchDataSerializer;
import java.util.HashMap;
import java.util.Map;
@JsonDeserialize(using = PatchDataDeserializer.class)
@JsonSerialize(using = PatchDataSerializer.class)
public class PatchData {
private final Map patch;
public PatchData(Map patch) {
this.patch = patch;
}
public static PatchData from(Map patch) {
return new PatchData(patch);
}
public static Builder patchData() {
return new Builder();
}
public Map getPatch() {
return patch;
}
public boolean valueChanged(String field, Object originalValue) {
return patch.containsKey(field) && !patch.get(field).equals(originalValue);
}
public static class Builder {
private final Map map = new HashMap<>();
public PatchData build() {
return PatchData.from(map);
}
public Builder set(String field, Object value) {
this.map.put(field, value);
return this;
}
}
}