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

com.anrisoftware.resources.images.mapcachedbounded.BundlesMapImpl Maven / Gradle / Ivy

/*
 * Copyright 2012-2016 Erwin Müller 
 *
 * This file is part of resources-images.
 *
 * resources-images is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * resources-images is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with resources-images. If not, see .
 */
package com.anrisoftware.resources.images.mapcachedbounded;

import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import javax.inject.Inject;

import com.anrisoftware.resources.images.api.BundlesMap;
import com.anrisoftware.resources.images.api.ImagesMap;
import com.anrisoftware.resources.images.api.ImagesMapFactory;

/**
 * Uses a {@link HashMap} to store the images for each resource bundle.
 *
 * @author Erwin Mueller, [email protected]
 * @since 1.1
 */
class BundlesMapImpl implements BundlesMap {

    private final Map map;

    private final ImagesMapFactory factory;

    @Inject
    BundlesMapImpl(ImagesMapFactory imagesFactory) {
        this.map = new HashMap();
        this.factory = imagesFactory;
    }

    @Override
    public ImagesMap getImages(ResourceBundle bundle) {
        ImagesMap images = map.get(bundle);
        if (images == null) {
            images = factory.create();
            map.put(bundle, images);
        }
        return images;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy