Source Code Cross Referenced for Strings.java in  » Net » Terracotta » com » tc » aspectwerkz » util » 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 » Net » Terracotta » com.tc.aspectwerkz.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tc.aspectwerkz.util;
005:
006:        import java.util.List;
007:        import java.util.ArrayList;
008:
009:        /**
010:         * Utility methods for strings.
011:         *
012:         * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
013:         */
014:        public class Strings {
015:            /**
016:             * Private constructor to prevent instantiability.
017:             */
018:            private Strings() {
019:            }
020:
021:            /**
022:             * Removes newline, carriage return and tab characters from a string.
023:             *
024:             * @param toBeEscaped string to escape
025:             * @return the escaped string
026:             */
027:            public static String removeFormattingCharacters(
028:                    final String toBeEscaped) {
029:                StringBuffer escapedBuffer = new StringBuffer();
030:                for (int i = 0; i < toBeEscaped.length(); i++) {
031:                    if ((toBeEscaped.charAt(i) != '\n')
032:                            && (toBeEscaped.charAt(i) != '\r')
033:                            && (toBeEscaped.charAt(i) != '\t')) {
034:                        escapedBuffer.append(toBeEscaped.charAt(i));
035:                    }
036:                }
037:                String s = escapedBuffer.toString();
038:                return s;//
039:                // Strings.replaceSubString(s, "\"", "")
040:            }
041:
042:            /**
043:             * Replaces all occurences of a substring inside a string.
044:             *
045:             * @param str      the string to search and replace in
046:             * @param oldToken the string to search for
047:             * @param newToken the string to replace newToken
048:             * @return the new string
049:             */
050:            public static String replaceSubString(final String str,
051:                    final String oldToken, final String newToken) {
052:                return replaceSubString(str, oldToken, newToken, -1);
053:            }
054:
055:            /**
056:             * Replaces all occurences of a substring inside a string.
057:             *
058:             * @param str      the string to search and replace in
059:             * @param oldToken the string to search for
060:             * @param newToken the string to replace newToken
061:             * @param max      maximum number of values to replace (-1 => no maximum)
062:             * @return the new string
063:             */
064:            public static String replaceSubString(final String str,
065:                    final String oldToken, final String newToken, int max) {
066:                if ((str == null) || (oldToken == null) || (newToken == null)
067:                        || (oldToken.length() == 0)) {
068:                    return str;
069:                }
070:                StringBuffer buf = new StringBuffer(str.length());
071:                int start = 0;
072:                int end = 0;
073:                while ((end = str.indexOf(oldToken, start)) != -1) {
074:                    buf.append(str.substring(start, end)).append(newToken);
075:                    start = end + oldToken.length();
076:                    if (--max == 0) {
077:                        break;
078:                    }
079:                }
080:                buf.append(str.substring(start));
081:                return buf.toString();
082:            }
083:
084:            /**
085:             * String split on multicharacter delimiter. <p/>Written by Tim Quinn (tim.quinn@honeywell.com)
086:             *
087:             * @param stringToSplit
088:             * @param delimiter
089:             * @return
090:             */
091:            public static final String[] splitString(String stringToSplit,
092:                    String delimiter) {
093:                String[] aRet;
094:                int iLast;
095:                int iFrom;
096:                int iFound;
097:                int iRecords;
098:
099:                // return Blank Array if stringToSplit == "")
100:                if (stringToSplit.equals("")) {
101:                    return new String[0];
102:                }
103:
104:                // count Field Entries
105:                iFrom = 0;
106:                iRecords = 0;
107:                while (true) {
108:                    iFound = stringToSplit.indexOf(delimiter, iFrom);
109:                    if (iFound == -1) {
110:                        break;
111:                    }
112:                    iRecords++;
113:                    iFrom = iFound + delimiter.length();
114:                }
115:                iRecords = iRecords + 1;
116:
117:                // populate aRet[]
118:                aRet = new String[iRecords];
119:                if (iRecords == 1) {
120:                    aRet[0] = stringToSplit;
121:                } else {
122:                    iLast = 0;
123:                    iFrom = 0;
124:                    iFound = 0;
125:                    for (int i = 0; i < iRecords; i++) {
126:                        iFound = stringToSplit.indexOf(delimiter, iFrom);
127:                        if (iFound == -1) { // at End
128:                            aRet[i] = stringToSplit.substring(iLast
129:                                    + delimiter.length(), stringToSplit
130:                                    .length());
131:                        } else if (iFound == 0) { // at Beginning
132:                            aRet[i] = "";
133:                        } else { // somewhere in middle
134:                            aRet[i] = stringToSplit.substring(iFrom, iFound);
135:                        }
136:                        iLast = iFound;
137:                        iFrom = iFound + delimiter.length();
138:                    }
139:                }
140:                return aRet;
141:            }
142:
143:            /**
144:             * Parse a method signature or method call signature.
145:             * <br/>Given a call signature like "method(Type t)", extract the method name
146:             * and param type and parameter name: [method, Type, t]
147:             * <br/>Given a signature like "method(X x, Y)", extract the method name
148:             * and param name / param type - but leaving empty String if
149:             * the information is not available: [method, X, x, Y, ""]
150:             *
151:             * @param methodCallSignature
152:             * @return each element (2xp+1 sized) (see doc)
153:             */
154:            public static String[] extractMethodSignature(
155:                    String methodCallSignature) {
156:                List extracted = new ArrayList();
157:                String methodName = methodCallSignature;
158:                String methodCallDesc = null;
159:                if (methodCallSignature.indexOf("(") > 0) {
160:                    methodName = methodName.substring(0, methodCallSignature
161:                            .indexOf("("));
162:                    methodCallDesc = methodCallSignature.substring(
163:                            methodCallSignature.indexOf("(") + 1,
164:                            methodCallSignature.lastIndexOf(")"));
165:                }
166:                extracted.add(methodName);
167:                if (methodCallDesc != null) {
168:                    String[] parameters = Strings.splitString(methodCallDesc,
169:                            ",");
170:                    for (int i = 0; i < parameters.length; i++) {
171:                        String[] parameterInfo = Strings.splitString(Strings
172:                                .replaceSubString(parameters[i].trim(), "  ",
173:                                        " "), " ");
174:                        extracted.add(parameterInfo[0]);
175:                        extracted
176:                                .add((parameterInfo.length > 1) ? parameterInfo[1]
177:                                        : "");
178:                    }
179:                }
180:                return (String[]) extracted.toArray(new String[] {});
181:            }
182:
183:            public static boolean isNullOrEmpty(String s) {
184:                return (s == null) ? true : (s.length() <= 0);
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.