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

com.laamella.parameter_source.InMemoryParameterSource Maven / Gradle / Ivy

There is a newer version: 1.0
Show newest version
package com.laamella.parameter_source;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

/**
 * This source has no external storage.
 * It only contains key-value pairs that have been put in using the "put" method.
 */
public class InMemoryParameterSource implements ParameterSource {
    private final Map storage = new HashMap<>();

    @Override
    public Optional getOptionalObject(String key) {
        requireNonNull(key);

        return Optional.ofNullable(storage.get(key));
    }

    public InMemoryParameterSource put(String key, Object o) {
        requireNonNull(key);

        storage.put(key, o);

        return this;
    }
}