1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * @LastModified: Oct 2017
4 */
5 /*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements. See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21 /*
22 * $Id: CustomStringPool.java,v 1.2.4.1 2005/09/15 08:14:59 suresh_emailid Exp $
23 */
28
29 /**
30 * CustomStringPool is an example of an application-provided data structure for a
31 * DTM implementation to hold symbol references, e.g. element names. It will
32 * follow the DTMStringPool interface and use two simple methods
33 * indexToString(int i) and stringToIndex(String s) to map between a set of
34 * string values and a set of integer index values. Therefore, an application
35 * may improve DTM processing speed by substituting the DTM symbol resolution
36 * tables with application specific quick symbol resolution tables.
37 * <p>
38 * %REVIEW% The only difference between this an DTMStringPool seems to be that
39 * it uses a java.lang.Hashtable full of Integers rather than implementing its
40 * own hashing. Joe deliberately avoided that approach when writing
41 * DTMStringPool, since it is both much more memory-hungry and probably slower
42 * -- especially in JDK 1.1.x, where Hashtable is synchronized. We need to
43 * either justify this implementation or discard it.
44 *
45 * <p>
46 * Status: In progress, under discussion.
47 *
48 */
49 public class CustomStringPool extends DTMStringPool {
50
51 final Map<String, Integer> m_stringToInt = new HashMap<>();
52 public static final int NULL = -1;
53
54 public CustomStringPool() {
55 super();
56 }
57
58 public void removeAllElements() {
59 m_intToString.clear();
60 if (m_stringToInt != null) {
61 m_stringToInt.clear();
62 }
63 }
64
65 /**
66 * @return string whose value is uniquely identified by this integer index.
67 * @throws java.lang.IndexOutOfBoundsException if index doesn't map to
|
1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 */
4 /*
5 * Licensed to the Apache Software Foundation (ASF) under one or more
6 * contributor license agreements. See the NOTICE file distributed with
7 * this work for additional information regarding copyright ownership.
8 * The ASF licenses this file to You under the Apache License, Version 2.0
9 * (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 /*
21 * $Id: CustomStringPool.java,v 1.2.4.1 2005/09/15 08:14:59 suresh_emailid Exp $
22 */
27
28 /**
29 * CustomStringPool is an example of an application-provided data structure for a
30 * DTM implementation to hold symbol references, e.g. element names. It will
31 * follow the DTMStringPool interface and use two simple methods
32 * indexToString(int i) and stringToIndex(String s) to map between a set of
33 * string values and a set of integer index values. Therefore, an application
34 * may improve DTM processing speed by substituting the DTM symbol resolution
35 * tables with application specific quick symbol resolution tables.
36 * <p>
37 * %REVIEW% The only difference between this an DTMStringPool seems to be that
38 * it uses a java.lang.Hashtable full of Integers rather than implementing its
39 * own hashing. Joe deliberately avoided that approach when writing
40 * DTMStringPool, since it is both much more memory-hungry and probably slower
41 * -- especially in JDK 1.1.x, where Hashtable is synchronized. We need to
42 * either justify this implementation or discard it.
43 *
44 * <p>
45 * Status: In progress, under discussion.
46 *
47 * @LastModified: Oct 2017
48 */
49 public class CustomStringPool extends DTMStringPool {
50
51 final Map<String, Integer> m_stringToInt = new HashMap<>();
52 public static final int NULL = -1;
53
54 public CustomStringPool() {
55 super();
56 }
57
58 public void removeAllElements() {
59 m_intToString.clear();
60 if (m_stringToInt != null) {
61 m_stringToInt.clear();
62 }
63 }
64
65 /**
66 * @return string whose value is uniquely identified by this integer index.
67 * @throws java.lang.IndexOutOfBoundsException if index doesn't map to
|