Source Code Cross Referenced for SortedCharSet.java in  » Parser » chaperon-3.0 » net » sourceforge » chaperon » common » 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 » Parser » chaperon 3.0 » net.sourceforge.chaperon.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright (C) Chaperon. All rights reserved.
003:         *  -------------------------------------------------------------------------
004:         *  This software is published under the terms of the Apache Software License
005:         *  version 1.1, a copy of which has been included  with this distribution in
006:         *  the LICENSE file.
007:         */
008:
009:        package net.sourceforge.chaperon.common;
010:
011:        import net.sourceforge.chaperon.common.Decoder;
012:
013:        /**
014:         * This class represents a set of char values, which means there doesn't exist multiple instances
015:         * of values.
016:         *
017:         * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
018:         * @version CVS $Id: SortedCharSet.java,v 1.3 2003/12/29 14:48:12 benedikta Exp $
019:         */
020:        public class SortedCharSet {
021:            private char elementCount = 0;
022:            private char[] list = new char[10];
023:
024:            //private char dummy;
025:
026:            /**
027:             * Creates an empty set of char values.
028:             */
029:            public SortedCharSet() {
030:            }
031:
032:            /**
033:             * Add a value to this set.
034:             *
035:             * @param value Char value.
036:             *
037:             * @return Index of this value.
038:             */
039:            public void addChar(char value) {
040:                if (list.length < (elementCount + 1)) {
041:                    char[] newList = new char[elementCount + 10];
042:                    System.arraycopy(list, 0, newList, 0, list.length);
043:                    list = newList;
044:                }
045:
046:                list[elementCount++] = value;
047:                sort();
048:            }
049:
050:            /**
051:             * Add the values of an array to this set.
052:             *
053:             * @param array Array of char values.
054:             */
055:            public void addChar(char[] array) {
056:                if (list.length < (elementCount + array.length)) {
057:                    char[] newList = new char[elementCount + array.length];
058:                    System.arraycopy(list, 0, newList, 0, list.length);
059:                    list = newList;
060:                }
061:
062:                System.arraycopy(array, 0, list, elementCount, array.length);
063:                elementCount += array.length;
064:                sort();
065:            }
066:
067:            /**
068:             * Removes a value giving by an index.
069:             *
070:             * @param index Index of the char value.
071:             */
072:            public void removeChar(char index) {
073:                if (index >= elementCount)
074:                    throw new ArrayIndexOutOfBoundsException(index);
075:
076:                elementCount--;
077:                if (index < elementCount)
078:                    System.arraycopy(list, index + 1, list, index, elementCount
079:                            - index);
080:
081:                list[elementCount] = 0;
082:            }
083:
084:            /**
085:             * Return a value from this set given by an index.
086:             *
087:             * @param index Index of the value.
088:             *
089:             * @return Char value.
090:             */
091:            public char getChar(int index) {
092:                if (index >= elementCount)
093:                    throw new ArrayIndexOutOfBoundsException(index);
094:
095:                return list[index];
096:            }
097:
098:            public char[] getChar() {
099:                char[] newList = new char[elementCount];
100:                System.arraycopy(list, 0, newList, 0, elementCount);
101:                return newList;
102:            }
103:
104:            /**
105:             * Returns the count of value in this set.
106:             *
107:             * @return Count of char values.
108:             */
109:            public char getCharCount() {
110:                return elementCount;
111:            }
112:
113:            /**
114:             * Return the index of a value, otherwise -1
115:             *
116:             * @param value Value, which should be found in this set.
117:             *
118:             * @return Index of this value.
119:             */
120:            public int indexOf(char value) {
121:                for (char i = 0; i < elementCount; i++)
122:                    if (list[i] == value)
123:                        return i;
124:
125:                return -1;
126:            }
127:
128:            /**
129:             * If the list contains a value.
130:             *
131:             * @param value Value, which should be found in this set
132:             *
133:             * @return True, if this set contains the value.
134:             */
135:            public boolean contains(char value) {
136:                for (char i = 0; i < elementCount; i++)
137:                    if (list[i] == value)
138:                        return true;
139:
140:                return false;
141:            }
142:
143:            /**
144:             * If this set contains no values.
145:             *
146:             * @return True, if this set is empty.
147:             */
148:            public boolean isEmpty() {
149:                return (elementCount <= 0);
150:            }
151:
152:            /**
153:             * Removes all values from this set
154:             */
155:            public void clear() {
156:                elementCount = 0;
157:            }
158:
159:            /**
160:             * Sort content by a QuickSort algorithm, and eliminate multiple instances.
161:             */
162:            private void sort() {
163:                char c;
164:                boolean modified = false;
165:                do {
166:                    modified = false;
167:
168:                    for (int i = 1; i < elementCount; i++)
169:                        if (list[i - 1] > list[i]) {
170:                            c = list[i - 1];
171:                            list[i - 1] = list[i];
172:                            list[i] = c;
173:
174:                            modified = true;
175:                        } else if (list[i - 1] == list[i]) // eliminate multiple instances
176:                        {
177:                            if (i < (elementCount - 1))
178:                                list[i] = list[--elementCount];
179:                            else
180:                                elementCount--;
181:
182:                            modified = true;
183:                        }
184:                } while (modified);
185:            }
186:
187:            /**
188:             * Return a string representation of the collection.
189:             *
190:             * @return String representation of the collection.
191:             */
192:            public String toString() {
193:                StringBuffer buffer = new StringBuffer();
194:
195:                buffer.append("[");
196:                for (char i = 0; i < elementCount; i++) {
197:                    buffer.append(Decoder.toChar(list[i]));
198:                    if (i < (elementCount - 1))
199:                        buffer.append(",");
200:                }
201:
202:                buffer.append("]");
203:                return buffer.toString();
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.