Source Code Cross Referenced for StringToStringTable.java in  » XML » xalan » org » apache » xml » 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.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: StringToStringTable.java,v 1.5 2004/02/17 04:21:14 minchau Exp $
018:         */
019:        package org.apache.xml.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:         * @xsl.usage internal
025:         */
026:        public class StringToStringTable {
027:
028:            /** Size of blocks to allocate          */
029:            private int m_blocksize;
030:
031:            /** Array of strings this contains          */
032:            private String m_map[];
033:
034:            /** Number of strings this contains           */
035:            private int m_firstFree = 0;
036:
037:            /** Size of this table           */
038:            private int m_mapSize;
039:
040:            /**
041:             * Default constructor.  Note that the default
042:             * block size is very small, for small lists.
043:             */
044:            public StringToStringTable() {
045:
046:                m_blocksize = 16;
047:                m_mapSize = m_blocksize;
048:                m_map = new String[m_blocksize];
049:            }
050:
051:            /**
052:             * Construct a StringToStringTable, using the given block size.
053:             *
054:             * @param blocksize Size of blocks to allocate 
055:             */
056:            public StringToStringTable(int blocksize) {
057:
058:                m_blocksize = blocksize;
059:                m_mapSize = blocksize;
060:                m_map = new String[blocksize];
061:            }
062:
063:            /**
064:             * Get the length of the list.
065:             *
066:             * @return Number of strings in the list
067:             */
068:            public final int getLength() {
069:                return m_firstFree;
070:            }
071:
072:            /**
073:             * Append a string onto the vector.
074:             * The strings go to the even locations in the array 
075:             * and the values in the odd. 
076:             *
077:             * @param key String to add to the list 
078:             * @param value Value of the string
079:             */
080:            public final void put(String key, String value) {
081:
082:                if ((m_firstFree + 2) >= m_mapSize) {
083:                    m_mapSize += m_blocksize;
084:
085:                    String newMap[] = new String[m_mapSize];
086:
087:                    System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
088:
089:                    m_map = newMap;
090:                }
091:
092:                m_map[m_firstFree] = key;
093:
094:                m_firstFree++;
095:
096:                m_map[m_firstFree] = value;
097:
098:                m_firstFree++;
099:            }
100:
101:            /**
102:             * Tell if the table contains the given string.
103:             *
104:             * @param key String to look up
105:             *
106:             * @return return the value of the string or null if not found. 
107:             */
108:            public final String get(String key) {
109:
110:                for (int i = 0; i < m_firstFree; i += 2) {
111:                    if (m_map[i].equals(key))
112:                        return m_map[i + 1];
113:                }
114:
115:                return null;
116:            }
117:
118:            /**
119:             * Remove the given string and its value from this table.
120:             *
121:             * @param key String to remove from the table
122:             */
123:            public final void remove(String key) {
124:
125:                for (int i = 0; i < m_firstFree; i += 2) {
126:                    if (m_map[i].equals(key)) {
127:                        if ((i + 2) < m_firstFree)
128:                            System.arraycopy(m_map, i + 2, m_map, i,
129:                                    m_firstFree - (i + 2));
130:
131:                        m_firstFree -= 2;
132:                        m_map[m_firstFree] = null;
133:                        m_map[m_firstFree + 1] = null;
134:
135:                        break;
136:                    }
137:                }
138:            }
139:
140:            /**
141:             * Tell if the table contains the given string. Ignore case
142:             *
143:             * @param key String to look up
144:             *
145:             * @return The value of the string or null if not found
146:             */
147:            public final String getIgnoreCase(String key) {
148:
149:                if (null == key)
150:                    return null;
151:
152:                for (int i = 0; i < m_firstFree; i += 2) {
153:                    if (m_map[i].equalsIgnoreCase(key))
154:                        return m_map[i + 1];
155:                }
156:
157:                return null;
158:            }
159:
160:            /**
161:             * Tell if the table contains the given string in the value.
162:             *
163:             * @param val Value of the string to look up
164:             *
165:             * @return the string associated with the given value or null if not found
166:             */
167:            public final String getByValue(String val) {
168:
169:                for (int i = 1; i < m_firstFree; i += 2) {
170:                    if (m_map[i].equals(val))
171:                        return m_map[i - 1];
172:                }
173:
174:                return null;
175:            }
176:
177:            /**
178:             * Get the nth element.
179:             *
180:             * @param i index of the string to look up.
181:             *
182:             * @return The string at the given index.
183:             */
184:            public final String elementAt(int i) {
185:                return m_map[i];
186:            }
187:
188:            /**
189:             * Tell if the table contains the given string.
190:             *
191:             * @param key String to look up
192:             *
193:             * @return True if the given string is in this table 
194:             */
195:            public final boolean contains(String key) {
196:
197:                for (int i = 0; i < m_firstFree; i += 2) {
198:                    if (m_map[i].equals(key))
199:                        return true;
200:                }
201:
202:                return false;
203:            }
204:
205:            /**
206:             * Tell if the table contains the given string.
207:             *
208:             * @param val value to look up
209:             *
210:             * @return True if the given value is in the table.
211:             */
212:            public final boolean containsValue(String val) {
213:
214:                for (int i = 1; i < m_firstFree; i += 2) {
215:                    if (m_map[i].equals(val))
216:                        return true;
217:                }
218:
219:                return false;
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.