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

io.cloudracer.mocktcpserver.responses.Responses Maven / Gradle / Ivy

There is a newer version: 1.7.0
Show newest version
package io.cloudracer.mocktcpserver.responses;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * A DAO class that contains a {@link Map} of incoming messages with corresponding responses i.e. message sent when a specific message is received.
 *
 * @author John McDonnell
 *
 */
public class Responses {

    private final HashMap> messageResponses = new HashMap<>();

    /**
     * Add a {@link ResponseDAO response} to a received message
     *
     * @param receivedMessage the received message.
     * @param response the {@link ResponseDAO response} to send
     */
    public void add(String receivedMessage, ResponseDAO response) {
        if (messageResponses.containsKey(receivedMessage)) {
            messageResponses.get(receivedMessage).add(response);
        } else {
            final List responseDAOList = new ArrayList<>();
            responseDAOList.add(response);
            messageResponses.put(receivedMessage, responseDAOList);
        }
    }

    /**
     * Create a read-only copy of the responses
     *
     * @return a read-only copy of the responses.
     */
    @SuppressWarnings("unchecked")
    public Map> getResponses() {
        return (Map>) messageResponses.clone();
    }

    @Override
    public String toString() {
        return "Responses [messageResponses=" + messageResponses + "]";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy