Source Code Cross Referenced for ItemList.java in  » Ajax » zk » org » zkforge » json » simple » 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 » Ajax » zk » org.zkforge.json.simple 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ItemList.java,v 1.1 2006/04/15 14:10:48 platform Exp $
003:         * Created on 2006-3-24
004:         */
005:        package org.zkforge.json.simple;
006:
007:        import java.util.ArrayList;
008:        import java.util.List;
009:        import java.util.StringTokenizer;
010:
011:        /**
012:         * �����÷ָ��ֿ���һ��item.�ָ��}��һ����һ��item.ÿ��item}�߲����ǿհ׷�.
013:         * ���磺
014:         * |a:b:c| => |a|,|b|,|c|
015:         * |:| => ||,||
016:         * |a:| => |a|,||
017:         * @author FangYidong<fangyidong@yahoo.com.cn>
018:         */
019:        public class ItemList {
020:            private String sp = ",";
021:            List items = new ArrayList();
022:
023:            public ItemList() {
024:            }
025:
026:            /**
027:             * 
028:             * @param s �ָ����һ���ַ�����
029:             */
030:            public ItemList(String s) {
031:                this .split(s, sp, items);
032:            }
033:
034:            /**
035:             * 
036:             * @param s �ָ����һ���ַ�����
037:             * @param sp �ָ��
038:             */
039:            public ItemList(String s, String sp) {
040:                this .sp = s;
041:                this .split(s, sp, items);
042:            }
043:
044:            /**
045:             * 
046:             * @param s
047:             * @param sp
048:             * @param isMultiToken sp�Ƿ�Ϊ��ָ��
049:             */
050:            public ItemList(String s, String sp, boolean isMultiToken) {
051:                split(s, sp, items, isMultiToken);
052:            }
053:
054:            public List getItems() {
055:                return this .items;
056:            }
057:
058:            public String[] getArray() {
059:                return (String[]) this .items.toArray();
060:            }
061:
062:            public void split(String s, String sp, List append,
063:                    boolean isMultiToken) {
064:                if (s == null || sp == null)
065:                    return;
066:                if (isMultiToken) {
067:                    StringTokenizer tokens = new StringTokenizer(s, sp);
068:                    while (tokens.hasMoreTokens()) {
069:                        append.add(tokens.nextToken().trim());
070:                    }
071:                } else {
072:                    this .split(s, sp, append);
073:                }
074:            }
075:
076:            public void split(String s, String sp, List append) {
077:                if (s == null || sp == null)
078:                    return;
079:                int pos = 0;
080:                int prevPos = 0;
081:                do {
082:                    prevPos = pos;
083:                    pos = s.indexOf(sp, pos);
084:                    if (pos == -1)
085:                        break;
086:                    append.add(s.substring(prevPos, pos).trim());
087:                    pos += sp.length();
088:                } while (pos != -1);
089:                append.add(s.substring(prevPos).trim());
090:            }
091:
092:            /**
093:             * ���÷ָ��.
094:             * @param sp �ָ��
095:             */
096:            public void setSP(String sp) {
097:                this .sp = sp;
098:            }
099:
100:            /**
101:             * ���뵥��item.
102:             * @param i �����λ��(֮ǰ)
103:             * @param item
104:             */
105:            public void add(int i, String item) {
106:                if (item == null)
107:                    return;
108:                items.add(i, item.trim());
109:            }
110:
111:            /**
112:             * ���뵥��item.
113:             * @param item
114:             */
115:            public void add(String item) {
116:                if (item == null)
117:                    return;
118:                items.add(item.trim());
119:            }
120:
121:            /**
122:             * ��һ��item.
123:             * @param list �����list
124:             */
125:            public void addAll(ItemList list) {
126:                items.addAll(list.items);
127:            }
128:
129:            /**
130:             * ��һ��item.
131:             * @param s �ָ����һ���ַ�����
132:             */
133:            public void addAll(String s) {
134:                this .split(s, sp, items);
135:            }
136:
137:            /**
138:             * ��һ��item.
139:             * @param s �ָ����һ���ַ�����
140:             * @param sp �ָ��
141:             */
142:            public void addAll(String s, String sp) {
143:                this .split(s, sp, items);
144:            }
145:
146:            public void addAll(String s, String sp, boolean isMultiToken) {
147:                this .split(s, sp, items, isMultiToken);
148:            }
149:
150:            /**
151:             * ��õ�i��item. 0-based.
152:             * @param i
153:             * @return
154:             */
155:            public String get(int i) {
156:                return (String) items.get(i);
157:            }
158:
159:            /**
160:             * ���item��.
161:             * @return
162:             */
163:            public int size() {
164:                return items.size();
165:            }
166:
167:            /**
168:             * �÷ָ��ָ�ı�ʾ.
169:             */
170:            public String toString() {
171:                return toString(sp);
172:            }
173:
174:            /**
175:             * �÷ָ��ָ�ı�ʾ.
176:             * @param sp ����ø÷ָ��ָ�.
177:             * @return
178:             */
179:            public String toString(String sp) {
180:                StringBuffer sb = new StringBuffer();
181:
182:                for (int i = 0; i < items.size(); i++) {
183:                    if (i == 0)
184:                        sb.append(items.get(i));
185:                    else {
186:                        sb.append(sp);
187:                        sb.append(items.get(i));
188:                    }
189:                }
190:                return sb.toString();
191:
192:            }
193:
194:            /**
195:             * �������item.
196:             */
197:            public void clear() {
198:                items.clear();
199:            }
200:
201:            /**
202:             * ��λ.�����ݣ����ָ�����Ĭ��ֵ.
203:             */
204:            public void reset() {
205:                sp = ",";
206:                items.clear();
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.