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

io.muserver.rest.LowercasedMultivaluedHashMap Maven / Gradle / Ivy

There is a newer version: 2.0.3
Show newest version
package io.muserver.rest;

import javax.ws.rs.core.AbstractMultivaluedMap;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;

class LowercasedMultivaluedHashMap extends AbstractMultivaluedMap {

    LowercasedMultivaluedHashMap() {
        super(new LowercasedHashMap<>());
    }

    private static class LowercasedHashMap extends HashMap {
        @Override
        public V get(Object key) {
            return super.get(toLower(key));
        }

        @Override
        public boolean containsKey(Object key) {
            return super.containsKey(toLower(key));
        }

        @Override
        public V put(String key, V value) {
            return super.put(key.toLowerCase(), value);
        }

        @Override
        public void putAll(Map m) {
            for (Entry entry : m.entrySet()) {
                put(entry.getKey(), entry.getValue());
            }
        }

        @Override
        public V remove(Object key) {
            return super.remove(toLower(key));
        }

        @Override
        public V getOrDefault(Object key, V defaultValue) {
            return super.getOrDefault(toLower(key), defaultValue);
        }

        @Override
        public V putIfAbsent(String key, V value) {
            return super.putIfAbsent(key.toLowerCase(), value);
        }

        @Override
        public boolean remove(Object key, Object value) {
            return super.remove(toLower(key), value);
        }

        @Override
        public boolean replace(String key, V oldValue, V newValue) {
            return super.replace(key.toLowerCase(), oldValue, newValue);
        }

        @Override
        public V replace(String key, V value) {
            return super.replace(key.toLowerCase(), value);
        }

        @Override
        public V computeIfAbsent(String key, Function mappingFunction) {
            return super.computeIfAbsent(key.toLowerCase(), mappingFunction);
        }

        @Override
        public V computeIfPresent(String key, BiFunction remappingFunction) {
            return super.computeIfPresent(key.toLowerCase(), remappingFunction);
        }

        @Override
        public V compute(String key, BiFunction remappingFunction) {
            return super.compute(key.toLowerCase(), remappingFunction);
        }

        @Override
        public V merge(String key, V value, BiFunction remappingFunction) {
            return super.merge(key.toLowerCase(), value, remappingFunction);
        }

        private static Object toLower(Object val) {
            if (val instanceof String) {
                return ((String) val).toLowerCase();
            }
            return val;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy