View Javadoc

1   /*
2    * This file is part of hyphenType. hyphenType is free software: you can
3    * redistribute it and/or modify it under the terms of the GNU General Public
4    * License as published by the Free Software Foundation, either version 3 of the
5    * License, or (at your option) any later version. hyphenType is distributed in
6    * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
8    * the GNU General Public License for more details. You should have received a
9    * copy of the GNU General Public License along with hyphenType. If not, see
10   * <http://www.gnu.org/licenses/>.
11   */
12  package org.hyphenType.util.resourcebundles;
13  
14  import java.util.ListResourceBundle;
15  import java.util.Map;
16  
17  /**
18   * A simple list resource bundle whose content can be manipulated externally.
19   * This class is useful when testing a class that reads from a resource bundle.
20   * 
21   * @author Aurelio Akira M. Matsui
22   */
23  public class ConfigurableListResourceBundle extends ListResourceBundle {
24  
25      private Object[][] contents = null;
26  
27      public ConfigurableListResourceBundle(Object[][] contents) {
28          this.contents = contents;
29      }
30  
31      public ConfigurableListResourceBundle(Map<?, ?> contentsMap) {
32          contents = new Object[contentsMap.size()][2];
33          for (int i = 0; i < contentsMap.size(); i++) {
34              contents[i][0] = contentsMap.keySet().toArray()[i];
35              contents[i][1] = contentsMap.get(contents[i][0]);
36          }
37      }
38  
39      @Override
40      protected Object[][] getContents() {
41          return contents;
42      }
43  }