Source Code Cross Referenced for AbstractStringList.java in  » J2EE » wicket » wicket » util » string » 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 » J2EE » wicket » wicket.util.string 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: AbstractStringList.java 458818 2006-01-25 16:18:39Z jcompagner $
003:         * $Revision: 458818 $ $Date: 2006-01-25 17:18:39 +0100 (Wed, 25 Jan 2006) $
004:         * 
005:         * ==============================================================================
006:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007:         * use this file except in compliance with the License. You may obtain a copy of
008:         * the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015:         * License for the specific language governing permissions and limitations under
016:         * the License.
017:         */
018:        package wicket.util.string;
019:
020:        import java.io.Serializable;
021:        import java.util.ArrayList;
022:        import java.util.List;
023:
024:        /**
025:         * An abstract base class for string list implementations. Besides having an
026:         * implementation for IStringSequence (iterator(), get(int index) and size()),
027:         * an AbstractStringList can be converted to a String array or a List of
028:         * Strings.
029:         * <p>
030:         * The total length of all Strings in the list can be determined by calling
031:         * totalLength().
032:         * <p>
033:         * Strings or a subset of Strings in the list can be formatted using three
034:         * join() methods:
035:         * <p>
036:         * <ul>
037:         * <li>join(String) Joins strings together using a given separator
038:         * <li>join() Joins Strings using comma as a separator
039:         * <li>join(int first, int last, String) Joins a sublist of strings using a
040:         * given separator
041:         * </ul>
042:         * 
043:         * @author Jonathan Locke
044:         */
045:        public abstract class AbstractStringList implements  IStringSequence,
046:                Serializable {
047:            /**
048:             * @return String iterator
049:             * @see wicket.util.string.IStringSequence#iterator()
050:             */
051:            public abstract IStringIterator iterator();
052:
053:            /**
054:             * @return Number of strings in this string list
055:             * @see wicket.util.string.IStringSequence#size()
056:             */
057:            public abstract int size();
058:
059:            /**
060:             * @param index
061:             *            The index into this string list
062:             * @return The string at the given index
063:             * @see wicket.util.string.IStringSequence#get(int)
064:             */
065:            public abstract String get(int index);
066:
067:            /**
068:             * Returns this String sequence as an array of Strings. Subclasses may
069:             * provide a more efficient implementation than the one provided here.
070:             * 
071:             * @return An array containing exactly this sequence of Strings
072:             */
073:            public String[] toArray() {
074:                // Get number of Strings
075:                final int size = size();
076:
077:                // Allocate array
078:                final String[] strings = new String[size];
079:
080:                // Copy string references
081:                for (int i = 0; i < size; i++) {
082:                    strings[i] = get(i);
083:                }
084:
085:                return strings;
086:            }
087:
088:            /**
089:             * Returns this String sequence as an array of Strings. Subclasses may
090:             * provide a more efficient implementation than the one provided here.
091:             * 
092:             * @return An array containing exactly this sequence of Strings
093:             */
094:            public final List toList() {
095:                // Get number of Strings
096:                final int size = size();
097:
098:                // Allocate list of exactly the right size
099:                final List strings = new ArrayList(size);
100:
101:                // Add strings to list
102:                for (int i = 0; i < size; i++) {
103:                    strings.add(get(i));
104:                }
105:
106:                return strings;
107:            }
108:
109:            /**
110:             * @return The total length of all Strings in this sequence.
111:             */
112:            public int totalLength() {
113:                // Get number of Strings
114:                final int size = size();
115:
116:                // Add strings to list
117:                int totalLength = 0;
118:
119:                for (int i = 0; i < size; i++) {
120:                    totalLength += get(i).length();
121:                }
122:
123:                return totalLength;
124:            }
125:
126:            /**
127:             * Joins this sequence of strings using a comma separator. For example, if
128:             * this sequence contains [1 2 3], the result of calling this method will be
129:             * "1, 2, 3".
130:             * 
131:             * @return The joined String
132:             */
133:            public final String join() {
134:                return join(", ");
135:            }
136:
137:            /**
138:             * Joins this sequence of strings using a separator
139:             * 
140:             * @param separator
141:             *            The separator to use
142:             * @return The joined String
143:             */
144:            public final String join(final String separator) {
145:                return join(0, size(), separator);
146:            }
147:
148:            /**
149:             * Joins this sequence of strings from first index to last using a separator
150:             * 
151:             * @param first
152:             *            The first index to use, inclusive
153:             * @param last
154:             *            The last index to use, exclusive
155:             * @param separator
156:             *            The separator to use
157:             * @return The joined String
158:             */
159:            public final String join(final int first, final int last,
160:                    final String separator) {
161:                // Allocate buffer of exactly the right length
162:                final int length = totalLength()
163:                        + (separator.length() * (Math.max(0, last - first - 1)));
164:                final AppendingStringBuffer buf = new AppendingStringBuffer(
165:                        length);
166:
167:                // Loop through indexes requested
168:                for (int i = first; i < last; i++) {
169:                    // Add next string
170:                    buf.append(get(i));
171:
172:                    // Add separator?
173:                    if (i != (last - 1)) {
174:                        buf.append(separator);
175:                    }
176:                }
177:
178:                return buf.toString();
179:            }
180:
181:            /**
182:             * Converts this object to a string representation
183:             * 
184:             * @return String version of this object
185:             */
186:            public String toString() {
187:                return "[" + join() + "]";
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.