001package fr.aumgn.bukkitutils.localization;
002
003import java.text.MessageFormat;
004import java.util.Collections;
005import java.util.Map;
006import java.util.Set;
007import java.util.Map.Entry;
008
009import org.apache.commons.lang.Validate;
010import org.bukkit.ChatColor;
011
012/**
013 * A set of messages loaded with {@link Localization}
014 */
015public class PluginMessages {
016
017    private Map<String, MessageFormat> map;
018
019    public PluginMessages(Map<String, MessageFormat> map) {
020        Validate.notNull(map);
021        this.map = map;
022    }
023
024    public boolean has(String key) {
025        Validate.notNull(key);
026        return map.containsKey(key);
027    }
028
029    public String get(String key) {
030        return get(key, new Object[0]);
031    }
032
033    public String get(String key, Object... arguments) {
034        if (!map.containsKey(key)) {
035            return ChatColor.RED + "## Missing message for key \""
036                    + key + "\" ##";
037        }
038
039        MessageFormat message = map.get(key);
040        return message.format(arguments);
041    }
042
043    public Set<String> keys() {
044        return Collections.unmodifiableSet(map.keySet());
045    }
046
047    public Set<Entry<String, MessageFormat>> entries() {
048        return Collections.unmodifiableSet(map.entrySet());
049    }
050}