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

org.enodeframework.messaging.Message Maven / Gradle / Ivy

There is a newer version: 1.1.10
Show newest version
package org.enodeframework.messaging;

import org.enodeframework.common.utilities.IdGenerator;
import org.enodeframework.common.utilities.SystemClock;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public abstract class Message implements IMessage {
    protected String id;
    protected Date timestamp;
    protected Map items;

    public Message(String id) {
        this.id = id;
        this.timestamp = new Date();
        this.items = new HashMap<>();
    }

    public Message() {
        this(IdGenerator.nextId());
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    @Override
    public Date getTimestamp() {
        return timestamp;
    }

    @Override
    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    @Override
    public Map getItems() {
        return items;
    }

    @Override
    public void setItems(Map items) {
        this.items = items;
    }

    @Override
    public void mergeItems(Map mitems) {
        if (mitems == null || mitems.size() == 0) {
            return;
        }
        if (this.items == null) {
            this.items = new HashMap<>();
        }
        for (Map.Entry entry : mitems.entrySet()) {
            if (!this.items.containsKey(entry.getKey())) {
                this.items.put(entry.getKey(), entry.getValue());
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy