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

io.higgs.http.server.params.HttpSession Maven / Gradle / Ivy

There is a newer version: 0.0.24
Show newest version
package io.higgs.http.server.params;

import java.util.HashMap;

/**
 * @author Courtney Robinson 
 */
public class HttpSession extends HashMap {
    private final HashMap flash = new HashMap<>();

    /**
     * Adds a key value pair to the session which is good for one use.
     * Once the object is retrieved it is automatically removed
     */
    public V flash(K key, V value) {
        return flash.put(key, value);
    }

    @Override
    public V get(Object key) {
        V val = super.get(key);
        if (val == null) {
            val = flash.get(key);
            if (val != null) {
                flash.remove(key);
            }
        }
        return val;
    }

    /**
     * @return Total combination of normal session objects and flash objects
     */
    public int getSize() {
        return size() + flash.size();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy