Source Code Cross Referenced for TextUtil.java in  » Test-Coverage » NoUnit » net » firstpartners » nounit » utility » 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 » Test Coverage » NoUnit » net.firstpartners.nounit.utility 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.firstpartners.nounit.utility;
002:
003:        /**
004:         * Title:        NoUnit - Identify Classes that are not being unit Tested
005:         *
006:         * Copyright (C) 2001  Paul Browne , FirstPartners.net
007:         *
008:         *
009:         * This program is free software; you can redistribute it and/or 
010:         * modify it under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; either version 2
012:         * of the License, or (at your option) any later version.
013:         *
014:         * This program is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017:         * GNU General Public License for more details.
018:         *
019:         * You should have received a copy of the GNU General Public License
020:         * along with this program; if not, write to the Free Software
021:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
022:         *
023:         * @author Paul Browne
024:         * @version 0.7
025:         */
026:
027:        /**
028:         * Performs common , but tricky tasks.
029:         * e.g. Stripping of spaces from Files
030:         */
031:        public class TextUtil {
032:
033:            /**
034:             * Replace the first occurrence of <code>oldSubstring</code> in
035:             * <code>string</code>, if there is one, with <code>newSubstring</code>.
036:             *
037:             * @param string - Replace a substring of this String
038:             * @param oldSubstring - The substring of <code>string</code> to be replaced
039:             * @param newSubstring - The string to put into <code> string</code>
040:             * @return A new String which is a copy of <code>string</code> with the first
041:             *         occurrence of <code>oldSubstring</code> in <code>string</code>, if
042:             *         there is one, with <code>newSubstring</code>.
043:             *         Returns null if <code>string</code> is null.
044:             *         Returns <code>string</code> if either substring is null or
045:             *         <code>oldSubstring</code> is empty
046:             */
047:            public static String replace(String string, String oldSubstring,
048:                    String newSubstring) {
049:                String result = string;
050:
051:                if ((string != null) && (string.length() > 0)
052:                        && (oldSubstring != null)
053:                        && (oldSubstring.length() > 0)
054:                        && (newSubstring != null)) {
055:                    int pos = string.indexOf(oldSubstring);
056:                    result = string.substring(0, pos) + newSubstring
057:                            + string.substring(pos + oldSubstring.length());
058:                }
059:
060:                return result;
061:            }
062:
063:            /**
064:             * Replaces all occurrences of <code>oldSubstring</code> in
065:             * <code>string</code>, if there are any, with <code>newSubstring</code>.
066:             *
067:             * @param string - Replace substrings of this String
068:             * @param oldSubstring - The substring of <code>string</code> to be replaced
069:             * @param newSubstring - The string to put into <code> string</code>
070:             * @return A new String which is a copy of <code>string</code> with all
071:             *         occurrences of <code>oldSubstring</code> in <code>string</code>,
072:             *         if there are any, with <code>newSubstring</code>.
073:             *         Returns null if <code>string</code> is null.
074:             *         Returns <code>string</code> if either substring is null or
075:             *         <code>oldSubstring</code> is empty
076:             */
077:            public static String replaceAll(String string, String oldSubstring,
078:                    String newSubstring) {
079:                //Local Variables
080:                String result = string;
081:
082:                if ((result != null) && (result.length() > 0)
083:                        && (result.indexOf(oldSubstring) > -1)
084:                        && (oldSubstring.length() > 0)
085:                        && (!oldSubstring.equals(newSubstring))) {
086:
087:                    while (result.indexOf(oldSubstring) > -1) {
088:                        result = replace(result, oldSubstring, newSubstring);
089:                    }
090:                }
091:
092:                return result;
093:            }
094:
095:            /**
096:             * Finds (start and end) markers in piece of text
097:             * extracts text (note including markers) in between
098:             * @param fullText to search in
099:             * @param startIndex ignore text before this point
100:             * @param startMarker start marker for the piece of text to extract
101:             * @param endMarker end marker
102:             * @return foundText , empty String if nothing found
103:             */
104:            public static String find(String fullText, int startIndex,
105:                    String startMarker, String endMarker) {
106:
107:                //Local Variables
108:                int startPlace = 0;
109:                int endPlace = 0;
110:                String foundText = "";
111:
112:                //Find the first instance of text
113:                startPlace = fullText.indexOf(startMarker, startIndex)
114:                        + startMarker.length();
115:
116:                //Find the first instance of end marker after this
117:                if (startPlace > startIndex) {
118:                    startIndex = startPlace;
119:                }
120:                endPlace = fullText.indexOf(endMarker, startIndex);
121:
122:                //Copy and return
123:                try {
124:                    if ((startPlace > -1) || (endPlace > -1)) {
125:                        foundText = fullText.substring(startPlace, endPlace);
126:                    }
127:                } catch (java.lang.StringIndexOutOfBoundsException sioobe) {
128:                    // do nothing - will return default of empty string
129:                }
130:
131:                //Ensure that there are no dodgy strings..
132:                if (startPlace < startIndex) {
133:                    foundText = "";
134:                }
135:
136:                return foundText;
137:            }
138:
139:            /**
140:             * Remove all instances of input string from Output
141:             * @param inputString
142:             * @param removeString
143:             * @return updateString
144:             */
145:            public static String removeAll(String inputString,
146:                    String removeString) {
147:
148:                //Internal Variables
149:                StringBuffer updateString = new StringBuffer();
150:                String tmpString;
151:
152:                for (int a = 0; a < inputString.length(); a++) {
153:
154:                    tmpString = inputString.substring(a, a + 1);
155:                    if (!tmpString.equals(removeString)) {
156:                        updateString.append(tmpString);
157:                    }
158:
159:                }
160:
161:                return updateString.toString();
162:
163:            }
164:
165:            /**
166:             * Strip out any trailing characters
167:             * @param inString to be operated on
168:             * @param toRemove string to remove at end if found
169:             * @return inString with end removed
170:             */
171:            public static String removeTrailing(String inString, String toRemove) {
172:                while (inString.endsWith(toRemove)) {
173:                    inString = inString.substring(0, inString.length()
174:                            - toRemove.length());
175:                }
176:
177:                return inString;
178:
179:            }
180:
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.