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

com.laamella.parameter_source.InMemoryStringParameterSource 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 InMemoryStringParameterSource implements StringParameterSource {
    private final Map storage = new HashMap<>();

    public InMemoryStringParameterSource put(String key, String s) {
        requireNonNull(key);

        storage.put(key, s);
        return this;
    }

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy