From d14937991a9059c8f57c7b0584f10bd99f7ff976 Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Tue, 18 Nov 2008 19:25:19 +0000 Subject: [PATCH] Allow those using message bundles to get all the keys that start with a particular prefix, just like they can get all the translations that match a prefix. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5555 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/util/MessageBundle.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/java/com/threerings/util/MessageBundle.java b/src/java/com/threerings/util/MessageBundle.java index 659115fff..645c22da2 100644 --- a/src/java/com/threerings/util/MessageBundle.java +++ b/src/java/com/threerings/util/MessageBundle.java @@ -202,6 +202,28 @@ public class MessageBundle } } + /** + * Adds all keys for 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 getAllKeys (String prefix, Collection keys, + boolean includeParent) + { + Enumeration iter = _bundle.getKeys(); + while (iter.hasMoreElements()) { + String key = iter.nextElement(); + if (key.startsWith(prefix)) { + keys.add(key); + } + } + if (includeParent && _parent != null) { + _parent.getAllKeys(prefix, keys, includeParent); + } + } + /** * Returns true if we have a translation mapping for the supplied key, * false if not.