01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.cfg;
17:
18: import java.util.Arrays;
19: import java.util.Collection;
20: import java.util.HashMap;
21: import java.util.Iterator;
22: import java.util.Map;
23:
24: /**
25: * A typed map of deferred binding properties.
26: */
27: public class Properties {
28:
29: private final Map<String, Property> map = new HashMap<String, Property>();
30:
31: private Property[] propertiesLazyArray;
32:
33: /**
34: * Creates the specified property, or returns an existing one by the specified
35: * name if present.
36: */
37: public Property create(String name) {
38: if (name == null) {
39: throw new NullPointerException("name");
40: }
41:
42: Property property = find(name);
43: if (property == null) {
44: property = new Property(name);
45: map.put(name, property);
46: }
47:
48: return property;
49: }
50:
51: public Property find(String name) {
52: return map.get(name);
53: }
54:
55: public Iterator<Property> iterator() {
56: return map.values().iterator();
57: }
58:
59: /**
60: * Lists all properties in sorted order.
61: */
62: public Property[] toArray() {
63: if (propertiesLazyArray == null) {
64: Collection<Property> properties = map.values();
65: int n = properties.size();
66: propertiesLazyArray = properties.toArray(new Property[n]);
67: Arrays.sort(propertiesLazyArray);
68: }
69: return propertiesLazyArray;
70: }
71: }
|