1 | /*
|
---|
2 | * Copyright 2000-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of 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,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.util;
|
---|
18 |
|
---|
19 | import java.util.Hashtable;
|
---|
20 | import java.util.Enumeration;
|
---|
21 |
|
---|
22 | /** Hashtable implementation that allows delayed construction
|
---|
23 | * of expensive objects
|
---|
24 | *
|
---|
25 | * All operations that need access to the full list of objects
|
---|
26 | * will call initAll() first. Get and put are cheap.
|
---|
27 | *
|
---|
28 | * @since Ant 1.6
|
---|
29 | */
|
---|
30 | public class LazyHashtable extends Hashtable {
|
---|
31 | protected boolean initAllDone = false;
|
---|
32 |
|
---|
33 | public LazyHashtable() {
|
---|
34 | super();
|
---|
35 | }
|
---|
36 |
|
---|
37 | /** Used to be part of init. It must be done once - but
|
---|
38 | * we delay it until we do need _all_ tasks. Otherwise we
|
---|
39 | * just get the tasks that we need, and avoid costly init.
|
---|
40 | */
|
---|
41 | protected void initAll() {
|
---|
42 | if (initAllDone) {
|
---|
43 | return;
|
---|
44 | }
|
---|
45 | initAllDone = true;
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | public Enumeration elements() {
|
---|
50 | initAll();
|
---|
51 | return super.elements();
|
---|
52 | }
|
---|
53 |
|
---|
54 | public boolean isEmpty() {
|
---|
55 | initAll();
|
---|
56 | return super.isEmpty();
|
---|
57 | }
|
---|
58 |
|
---|
59 | public int size() {
|
---|
60 | initAll();
|
---|
61 | return super.size();
|
---|
62 | }
|
---|
63 |
|
---|
64 | public boolean contains(Object value) {
|
---|
65 | initAll();
|
---|
66 | return super.contains(value);
|
---|
67 | }
|
---|
68 |
|
---|
69 | public boolean containsKey(Object value) {
|
---|
70 | initAll();
|
---|
71 | return super.containsKey(value);
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Delegates to {@link #contains contains}.
|
---|
76 | */
|
---|
77 | public boolean containsValue(Object value) {
|
---|
78 | return contains(value);
|
---|
79 | }
|
---|
80 |
|
---|
81 | public Enumeration keys() {
|
---|
82 | initAll();
|
---|
83 | return super.keys();
|
---|
84 | }
|
---|
85 |
|
---|
86 | // XXX Unfortunately JDK1.2 adds entrySet(), keySet(), values() -
|
---|
87 | // implementing this requires a small hack, we can add it later.
|
---|
88 | }
|
---|