2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 * {@code ListResourceBundle} is the abstract superclass of classes which provide
22 * resources by implementing the {@code getContents()} method to return
23 * the list of resources.
28 public abstract class ListResourceBundle
extends ResourceBundle
{
29 HashMap
<String
, Object
> table
;
32 * Constructs a new instance of this class.
34 public ListResourceBundle() {
38 * Returns an {@code Object} array containing the resources of this
39 * {@code ListResourceBundle}. Each element in the array is an array of two
40 * elements, the first is the resource key string and the second is the
43 * @return a {@code Object} array containing the resources.
45 protected abstract Object
[][] getContents();
48 public Enumeration
<String
> getKeys() {
51 return new Enumeration
<String
>() {
52 Iterator
<String
> local
= table
.keySet().iterator();
54 Enumeration
<String
> pEnum
= parent
.getKeys();
58 private boolean findNext() {
59 if (nextElement
!= null) {
62 while (pEnum
.hasMoreElements()) {
63 String next
= pEnum
.nextElement();
64 if (!table
.containsKey(next
)) {
72 public boolean hasMoreElements() {
73 if (local
.hasNext()) {
79 public String
nextElement() {
80 if (local
.hasNext()) {
84 String result
= nextElement
;
89 return pEnum
.nextElement();
93 return new Enumeration
<String
>() {
94 Iterator
<String
> it
= table
.keySet().iterator();
96 public boolean hasMoreElements() {
100 public String
nextElement() {
108 public final Object
handleGetObject(String key
) {
111 throw new NullPointerException("key == null");
113 return table
.get(key
);
116 private synchronized void initializeTable() {
118 Object
[][] contents
= getContents();
119 table
= new HashMap
<String
, Object
>(contents
.length
/ 3 * 4 + 3);
120 for (Object
[] content
: contents
) {
121 if (content
[0] == null || content
[1] == null) {
122 throw new NullPointerException("null entry");
124 table
.put((String
) content
[0], content
[1]);
130 * Returns a set of the keys in this ResourceBundle but not in its parents.
132 * @return a set of the keys in this ResourceBundle but not in its parents.
135 protected Set
<String
> handleKeySet() {
137 return table
.keySet();