Source Code Cross Referenced for StringUtil.java in  » Inversion-of-Control » carbon » org » sape » carbon » core » 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 » Inversion of Control » carbon » org.sape.carbon.core.util.string 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the Sapient Public License
003:         * Version 1.0 (the "License"); you may not use this file except in compliance
004:         * with the License. You may obtain a copy of the License at
005:         * http://carbon.sf.net/License.html.
006:         *
007:         * Software distributed under the License is distributed on an "AS IS" basis,
008:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009:         * the specific language governing rights and limitations under the License.
010:         *
011:         * The Original Code is The Carbon Component Framework.
012:         *
013:         * The Initial Developer of the Original Code is Sapient Corporation
014:         *
015:         * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016:         */
017:
018:        package org.sape.carbon.core.util.string;
019:
020:        import java.util.ArrayList;
021:        import java.util.HashSet;
022:        import java.util.List;
023:        import java.util.Set;
024:        import java.util.StringTokenizer;
025:
026:        /**
027:         * <p>Utilities for strings.</p>
028:         *
029:         *
030:         * Copyright 2002 Sapient
031:         * @since carbon 1.0
032:         * @author Greg Hinkle, May 2002
033:         * @version $Revision: 1.5 $($Author: dvoet $ / $Date: 2003/05/05 21:21:24 $)
034:         */
035:        public class StringUtil {
036:
037:            /**
038:             * Capitalizes the first character of the given string.
039:             * @param s the String to capitalize
040:             * @return the capitalized result
041:             */
042:            public static String capitalize(String s) {
043:                if (s.length() == 0)
044:                    return s;
045:                char c = Character.toUpperCase(s.charAt(0));
046:                return c + s.substring(1, s.length());
047:            }
048:
049:            /**
050:             * Parses a comma-separated list into an array of Strings
051:             * Values can contain whitespace, but whitespace at the beginning and
052:             * end of each value is trimmed.
053:             * @return array of Strings
054:             * @param csvList a string of comma seperated values
055:             */
056:            public static String[] parseCommaDelimitedList(String csvList) {
057:                String[] result = parseList(csvList, ",");
058:                for (int i = 0; i < result.length; i++) {
059:                    result[i] = result[i].trim();
060:                }
061:                return result;
062:            }
063:
064:            /**
065:             * Parses a whitepsace-separated list into an array of Strings
066:             * @return array of Strings
067:             * @param wsvList a string of white space seperated values
068:             */
069:            public static String[] parseWhitespaceDelimitedList(String wsvList) {
070:                return parseList(wsvList, "\t ");
071:            }
072:
073:            /**
074:             * Parses a list according to the specified delimiter into an
075:             * array of Strings.
076:             * @see java.util.StringTokenizer
077:             * @param list a string of token seperated values
078:             * @param delim the delimiter character(s).  Each character in the string is a
079:             * single delimeter.
080:             * @return an array of strings
081:             */
082:            public static String[] parseList(String list, String delim) {
083:                List result = new ArrayList();
084:                StringTokenizer tokenizer = new StringTokenizer(list, delim);
085:                while (tokenizer.hasMoreTokens()) {
086:                    result.add(tokenizer.nextToken());
087:                }
088:                return (String[]) result.toArray(new String[0]);
089:            }
090:
091:            /**
092:             * <p>Removes specified chars from a string.</p>
093:             *
094:             * @param aString the string that will be examined to remove chars
095:             * @param unWantedCharArray the char array containing the chars
096:             * that should be removed from a string
097:             * @return the string after removing the specified chars
098:             */
099:            public static String removeCharsFromString(String aString,
100:                    char[] unWantedCharArray) {
101:
102:                Character character = null;
103:
104:                // Store unwanted chars in a hashset
105:                Set unWantedCharSet = new HashSet();
106:
107:                for (int i = 0; i < unWantedCharArray.length; i++) {
108:                    character = new Character(unWantedCharArray[i]);
109:                    unWantedCharSet.add(character);
110:                }
111:
112:                // Create result String buffer
113:                StringBuffer result = new StringBuffer(aString.length());
114:
115:                // For each character in aString, append it to the result string buffer
116:                // if it is not in unWantedCharSet
117:                for (int i = 0; i < aString.length(); i++) {
118:                    character = new Character(aString.charAt(i));
119:                    if (!unWantedCharSet.contains(character)) {
120:                        result.append(aString.charAt(i));
121:                    }
122:                }
123:
124:                // Return result
125:                return result.toString();
126:            }
127:
128:            /**
129:             * <p> Converts a string to a Set. Breaks the string to characters and store
130:             * each character in a Set.
131:             *
132:             * @param string the string to convert
133:             * @return a <code>Set</code> containing all characters in the text string parameter
134:             */
135:            public static Set convertToSet(String string) {
136:
137:                // Result hashset
138:                Set resultSet = new HashSet();
139:
140:                for (int i = 0; i < string.length(); i++) {
141:                    resultSet.add(new Character(string.charAt(i)));
142:                }
143:
144:                // Return result
145:                return resultSet;
146:            }
147:
148:            /**
149:             * <p> Converts a char array to a Set. Puts all characters in the array to a Set.
150:             *
151:             * @param charArray an array of <CODE>char</CODE>s
152:             * @return a <code>set</code> containing all characters in the char array
153:             */
154:            public static Set convertToSet(char[] charArray) {
155:
156:                // Result hashset
157:                Set resultSet = new HashSet();
158:
159:                for (int i = 0; i < charArray.length; i++) {
160:                    resultSet.add(new Character(charArray[i]));
161:                }
162:
163:                // Return result
164:                return resultSet;
165:            }
166:
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.