com.anrisoftware.resources.texts.maps.TextsMapImpl Maven / Gradle / Ivy
/*
* Copyright 2012-2015 Erwin Müller
*
* This file is part of resources-texts.
*
* resources-texts 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-texts 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-texts. If not, see .
*/
package com.anrisoftware.resources.texts.maps;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import com.anrisoftware.resources.texts.api.TextResource;
import com.anrisoftware.resources.texts.api.TextsMap;
/**
* Uses the Java hash map to store the text resources identified by their name.
*
* @author Erwin Mueller, [email protected]
* @since 1.1
*/
class TextsMapImpl implements TextsMap {
private final TextsMapLogger log;
private final Map texts;
@Inject
TextsMapImpl(TextsMapLogger logger) {
this.log = logger;
this.texts = new HashMap();
}
/**
* Adds a new text resource to the map. Already added text resource with the
* name are discarded.
*
* @param name
* the name of the resource.
*
* @param text
* the {@link TextResource} to add.
*/
@Override
public void putText(String name, TextResource text) {
if (!texts.containsKey(name)) {
texts.put(name, text);
} else {
log.textAlreadyInMap(name);
}
}
/**
* Returns the text resource with the name.
*
* @param name
* the name of the resource.
*
* @return the {@link TextResource} with the name and language, the resource
* with the default language, or null
.
*/
@Override
public TextResource getText(String name) {
TextResource resource = texts.get(name);
return resource;
}
/**
* Check if the map contains a text with the name.
*
* @param name
* the name of the text.
*
* @return true
if the map contains the text or
* false
if not.
*/
@Override
public boolean haveText(String name) {
return texts.containsKey(name);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy