From e4d7da7d19adc08ec6617cfdea3ab9a52b9bdab0 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 7 Aug 2006 19:04:48 +0000 Subject: [PATCH] Added getAll(). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4300 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/util/MessageBundle.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/java/com/threerings/util/MessageBundle.java b/src/java/com/threerings/util/MessageBundle.java index 0d3be595f..09e8b1d0c 100644 --- a/src/java/com/threerings/util/MessageBundle.java +++ b/src/java/com/threerings/util/MessageBundle.java @@ -22,6 +22,8 @@ package com.threerings.util; import java.text.MessageFormat; +import java.util.Collection; +import java.util.Enumeration; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -193,6 +195,28 @@ public class MessageBundle return (msg != null) ? msg : key; } + /** + * Adds all messages whose key starts with the specified prefix to the + * supplied collection. + * + * @param includeParent if true, messages from our parent bundle (and its + * parent bundle, all the way up the chain will be included). + */ + public void getAll (String prefix, Collection messages, + boolean includeParent) + { + Enumeration iter = _bundle.getKeys(); + while (iter.hasMoreElements()) { + String key = iter.nextElement(); + if (key.startsWith(prefix)) { + messages.add(get(key)); + } + } + if (includeParent && _parent != null) { + _parent.getAll(prefix, messages, includeParent); + } + } + /** * Returns true if we have a translation mapping for the supplied key, * false if not.