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

com.lyncode.xliff.cache.InMemoryPersistentMessageCache Maven / Gradle / Ivy

The newest version!
package com.lyncode.xliff.cache;

import com.google.common.base.Supplier;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class InMemoryPersistentMessageCache implements MessageCache {
    private final Locale defaultLocale;
    private final Map> map = new HashMap>();

    public InMemoryPersistentMessageCache(Locale defaultLocale) {
        this.defaultLocale = defaultLocale;
    }

    @Override
    public String retrieve(Locale locale, String code, Supplier initializer) {
        if (locale == null) locale = defaultLocale;

        if (!map.containsKey(locale))
            map.put(locale, new HashMap());

        if (!map.get(locale).containsKey(code))
            map.get(locale).put(code, initializer.get());

        return map.get(locale).get(code);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy