Source Code Cross Referenced for StringToIntTable.java in  » XML » xalan » org » apache » xml » serializer » utils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML » xalan » org.apache.xml.serializer.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2004 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        /*
017:         * $Id: StringToIntTable.java,v 1.1 2004/10/14 18:30:53 minchau Exp $
018:         */
019:        package org.apache.xml.serializer.utils;
020:
021:        /**
022:         * A very simple lookup table that stores a list of strings, the even
023:         * number strings being keys, and the odd number strings being values.
024:         * 
025:         * This class is a copy of the one in org.apache.xml.utils. 
026:         * It exists to cut the serializers dependancy on that package.
027:         * 
028:         * This class is not a public API, it is only public so it can be used
029:         * in org.apache.xml.serializer.
030:         *  
031:         * @xsl.usage internal
032:         */
033:        public final class StringToIntTable {
034:
035:            public static final int INVALID_KEY = -10000;
036:
037:            /** Block size to allocate          */
038:            private int m_blocksize;
039:
040:            /** Array of strings this table points to. Associated with ints
041:             * in m_values         */
042:            private String m_map[];
043:
044:            /** Array of ints this table points. Associated with strings from
045:             * m_map.         */
046:            private int m_values[];
047:
048:            /** Number of ints in the table          */
049:            private int m_firstFree = 0;
050:
051:            /** Size of this table         */
052:            private int m_mapSize;
053:
054:            /**
055:             * Default constructor.  Note that the default
056:             * block size is very small, for small lists.
057:             */
058:            public StringToIntTable() {
059:
060:                m_blocksize = 8;
061:                m_mapSize = m_blocksize;
062:                m_map = new String[m_blocksize];
063:                m_values = new int[m_blocksize];
064:            }
065:
066:            /**
067:             * Construct a StringToIntTable, using the given block size.
068:             *
069:             * @param blocksize Size of block to allocate
070:             */
071:            public StringToIntTable(int blocksize) {
072:
073:                m_blocksize = blocksize;
074:                m_mapSize = blocksize;
075:                m_map = new String[blocksize];
076:                m_values = new int[m_blocksize];
077:            }
078:
079:            /**
080:             * Get the length of the list.
081:             *
082:             * @return the length of the list 
083:             */
084:            public final int getLength() {
085:                return m_firstFree;
086:            }
087:
088:            /**
089:             * Append a string onto the vector.
090:             *
091:             * @param key String to append
092:             * @param value The int value of the string
093:             */
094:            public final void put(String key, int value) {
095:
096:                if ((m_firstFree + 1) >= m_mapSize) {
097:                    m_mapSize += m_blocksize;
098:
099:                    String newMap[] = new String[m_mapSize];
100:
101:                    System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
102:
103:                    m_map = newMap;
104:
105:                    int newValues[] = new int[m_mapSize];
106:
107:                    System
108:                            .arraycopy(m_values, 0, newValues, 0,
109:                                    m_firstFree + 1);
110:
111:                    m_values = newValues;
112:                }
113:
114:                m_map[m_firstFree] = key;
115:                m_values[m_firstFree] = value;
116:
117:                m_firstFree++;
118:            }
119:
120:            /**
121:             * Tell if the table contains the given string.
122:             *
123:             * @param key String to look for
124:             *
125:             * @return The String's int value
126:             * 
127:             */
128:            public final int get(String key) {
129:
130:                for (int i = 0; i < m_firstFree; i++) {
131:                    if (m_map[i].equals(key))
132:                        return m_values[i];
133:                }
134:
135:                return INVALID_KEY;
136:            }
137:
138:            /**
139:             * Tell if the table contains the given string. Ignore case.
140:             *
141:             * @param key String to look for
142:             *
143:             * @return The string's int value
144:             */
145:            public final int getIgnoreCase(String key) {
146:
147:                if (null == key)
148:                    return INVALID_KEY;
149:
150:                for (int i = 0; i < m_firstFree; i++) {
151:                    if (m_map[i].equalsIgnoreCase(key))
152:                        return m_values[i];
153:                }
154:
155:                return INVALID_KEY;
156:            }
157:
158:            /**
159:             * Tell if the table contains the given string.
160:             *
161:             * @param key String to look for
162:             *
163:             * @return True if the string is in the table
164:             */
165:            public final boolean contains(String key) {
166:
167:                for (int i = 0; i < m_firstFree; i++) {
168:                    if (m_map[i].equals(key))
169:                        return true;
170:                }
171:
172:                return false;
173:            }
174:
175:            /**
176:             * Return array of keys in the table.
177:             * 
178:             * @return Array of strings
179:             */
180:            public final String[] keys() {
181:                String[] keysArr = new String[m_firstFree];
182:
183:                for (int i = 0; i < m_firstFree; i++) {
184:                    keysArr[i] = m_map[i];
185:                }
186:
187:                return keysArr;
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.