All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.hermes.api.PatchData Maven / Gradle / Ivy

There is a newer version: 2.6.22
Show newest version
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;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy