KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > cfg > Properties


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * A typed map of deferred binding properties.
26  */

27 public class Properties {
28
29   private final Map JavaDoc map = new HashMap JavaDoc();
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 JavaDoc name) {
38     if (name == null) {
39       throw new NullPointerException JavaDoc("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 JavaDoc name) {
52     return (Property) map.get(name);
53   }
54
55   public Iterator JavaDoc 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 JavaDoc properties = map.values();
65       int n = properties.size();
66       propertiesLazyArray = (Property[]) properties.toArray(new Property[n]);
67       Arrays.sort(propertiesLazyArray);
68     }
69     return propertiesLazyArray;
70   }
71 }
72
Popular Tags