Source Code Cross Referenced for StringList.java in  » Web-Framework » RSF » uk » org » ponder » stringutil » 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 » Web Framework » RSF » uk.org.ponder.stringutil 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Sep 16, 2004
003:         */
004:        package uk.org.ponder.stringutil;
005:
006:        import java.util.ArrayList;
007:        import java.util.Collection;
008:        import java.util.Iterator;
009:
010:        import uk.org.ponder.util.UniversalRuntimeException;
011:
012:        /**
013:         * A convenience wrapper for a type-safe list of String objects.
014:         * 
015:         * @author Antranig Basman (antranig@caret.cam.ac.uk)
016:         * 
017:         */
018:        public class StringList extends ArrayList {
019:
020:            public StringList() {
021:            }
022:
023:            public StringList(Collection tocopy) {
024:                append(tocopy);
025:            }
026:
027:            public StringList(String string) {
028:                ensureCapacity(2);
029:                add(string);
030:            }
031:
032:            public StringList(String[] strings) {
033:                ensureCapacity(strings.length);
034:                append(strings);
035:            }
036:
037:            public String stringAt(int i) {
038:                return (String) get(i);
039:            }
040:
041:            public boolean add(Object o) {
042:                if (o != null && !(o instanceof  String)) {
043:                    throw new UniversalRuntimeException("Object " + o + " of "
044:                            + o.getClass() + " added to StringList");
045:                }
046:                return super .add(o);
047:            }
048:
049:            /**
050:             * Appends the members of the supplied array to this list.
051:             * 
052:             * @param toappend The array of Strings to be appended, which may be
053:             *          <code>null</code>.
054:             */
055:
056:            public void append(String[] toappend) {
057:                if (toappend != null) {
058:                    for (int i = 0; i < toappend.length; ++i) {
059:                        add(toappend[i]);
060:                    }
061:                }
062:            }
063:
064:            /**
065:             * Appends the members of the supplied list to this list.
066:             * 
067:             * @param toappend The list of Strings to be appended, which may be
068:             *          <code>null</code>.
069:             */
070:            public void append(StringList toappend) {
071:                if (toappend != null) {
072:                    for (int i = 0; i < toappend.size(); ++i) {
073:                        add(toappend.get(i));
074:                    }
075:                }
076:            }
077:
078:            public void append(Collection toappend) {
079:                for (Iterator it = toappend.iterator(); it.hasNext();) {
080:                    String next = (String) it.next(); // ensure ClassCastException if wrong
081:                    // type
082:                    add(next);
083:                }
084:            }
085:
086:            public StringList copy() {
087:                StringList togo = new StringList();
088:                togo.addAll(this );
089:                return togo;
090:            }
091:
092:            public String pack() {
093:                CharWrap togo = new CharWrap();
094:                for (int i = 0; i < size(); ++i) {
095:                    togo.append(stringAt(i));
096:                    togo.append('\n');
097:                }
098:                return togo.toString();
099:            }
100:
101:            public String[] toStringArray() {
102:                String[] togo = (String[]) toArray(new String[size()]);
103:                return togo;
104:            }
105:
106:            public String toString() {
107:                CharWrap togo = new CharWrap();
108:                for (int i = 0; i < size(); ++i) {
109:                    togo.append(stringAt(i));
110:                    togo.append(", ");
111:                }
112:                return togo.toString();
113:            }
114:
115:            /**
116:             * Construct a StringList from a comma separated list of Strings, trimming
117:             * whitespace.
118:             * 
119:             * @param commasep
120:             * @return
121:             */
122:            public static StringList fromString(String commasep) {
123:                String[] strings = commasep.split(",");
124:                StringList togo = new StringList();
125:
126:                for (int i = 0; i < strings.length; ++i) {
127:                    String toadd = strings[i].trim();
128:                    // ensure that empty string produces empty list
129:                    if (toadd.length() != 0 || strings.length > 1) {
130:                        togo.add(toadd);
131:                    }
132:                }
133:                return togo;
134:            }
135:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.