Roll android_tools support library to 25.1.0
[android_tools.git] / sdk / sources / android-23 / java / util / ListResourceBundle.java
blob7809b9a2d1416f6555b20ef6807005773c9db7e4
1 /*
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.
18 package java.util;
20 /**
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.
25 * @see ResourceBundle
26 * @since 1.1
28 public abstract class ListResourceBundle extends ResourceBundle {
29 HashMap<String, Object> table;
31 /**
32 * Constructs a new instance of this class.
34 public ListResourceBundle() {
37 /**
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
41 * resource.
43 * @return a {@code Object} array containing the resources.
45 protected abstract Object[][] getContents();
47 @Override
48 public Enumeration<String> getKeys() {
49 initializeTable();
50 if (parent != null) {
51 return new Enumeration<String>() {
52 Iterator<String> local = table.keySet().iterator();
54 Enumeration<String> pEnum = parent.getKeys();
56 String nextElement;
58 private boolean findNext() {
59 if (nextElement != null) {
60 return true;
62 while (pEnum.hasMoreElements()) {
63 String next = pEnum.nextElement();
64 if (!table.containsKey(next)) {
65 nextElement = next;
66 return true;
69 return false;
72 public boolean hasMoreElements() {
73 if (local.hasNext()) {
74 return true;
76 return findNext();
79 public String nextElement() {
80 if (local.hasNext()) {
81 return local.next();
83 if (findNext()) {
84 String result = nextElement;
85 nextElement = null;
86 return result;
88 // Cause an exception
89 return pEnum.nextElement();
92 } else {
93 return new Enumeration<String>() {
94 Iterator<String> it = table.keySet().iterator();
96 public boolean hasMoreElements() {
97 return it.hasNext();
100 public String nextElement() {
101 return it.next();
107 @Override
108 public final Object handleGetObject(String key) {
109 initializeTable();
110 if (key == null) {
111 throw new NullPointerException("key == null");
113 return table.get(key);
116 private synchronized void initializeTable() {
117 if (table == null) {
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.
133 * @since 1.6
135 protected Set<String> handleKeySet() {
136 initializeTable();
137 return table.keySet();