Source Code Cross Referenced for RETest.java in  » Template-Engine » JDynamiTe » gnu » regexp » 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 » Template Engine » JDynamiTe » gnu.regexp.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  gnu/regexp/util/RETest.java
003:         *  Copyright (C) 1998 Wes Biggs
004:         *
005:         *  This file is in the public domain.  However, the gnu.regexp library
006:         *  proper is licensed under the terms of the GNU Library General Public
007:         *  License (see the file LICENSE for details).
008:         */
009:        package gnu.regexp.util;
010:
011:        import gnu.regexp.*;
012:
013:        /**
014:         *  RETest provides a simple way to test regular expressions.
015:         *  It runs from the command line using the Java interpreter.
016:         *  To use it, enter the following from a command prompt (provided
017:         *  that the Java system knows where to find the RETest bytecodes):
018:         *  <BR><CODE>java gnu.regexp.util.RETest [regExp] [inputString]</CODE><BR>
019:         *  where <i>regExp</i> is a regular expression (you'll probably have
020:         *  to escape shell meta-characters) and <i>inputString</i> is the string
021:         *  to match against (again, put it in quotes or escape any shell meta-
022:         *  characters).
023:         *  <P>
024:         *  The test function will report the package version number, whether
025:         *  the expression matches the input string, what the match it found was,
026:         *  and the contents of any subexpressions, if applicable.
027:         *  <P>
028:         *  You may optionally add a third integer argument which is the number of
029:         *  times to repeat the test.  When this option is used, RETest will report
030:         *  average compile and match times.
031:         *
032:         * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
033:         * @version 1.01
034:         */
035:        public class RETest {
036:            private RETest() {
037:            }
038:
039:            /**
040:             * Invokes the test function with the command line arguments specified.
041:             * See class description for usage notes.
042:             *
043:             * @param argv
044:             * The command line arguments.
045:             *
046:             * @exception REException
047:             * There was an error compiling or executing the regular expression.
048:             */
049:            public static void main(String argv[]) throws REException {
050:                System.out.println("gnu.regexp version " + RE.version());
051:
052:                int numRepeats = 1;
053:                if (argv.length == 3)
054:                    numRepeats = Integer.parseInt(argv[2]);
055:                if (argv.length < 2) {
056:                    System.out
057:                            .println("usage: java gnu.regexp.util.RETest regExp inputString [numRepeats]");
058:                    System.exit(1);
059:                }
060:
061:                // Construct the regular expression
062:
063:                RE expression = null;
064:                long begin = System.currentTimeMillis();
065:
066:                for (int rpt = 0; rpt < numRepeats; rpt++)
067:                    expression = new RE(argv[0]);
068:
069:                long end = System.currentTimeMillis();
070:
071:                if (numRepeats > 1) {
072:                    System.out.println("Compiling " + numRepeats
073:                            + " times took " + (end - begin) + " ms");
074:                    System.out.println("Average compile time: "
075:                            + ((end - begin) / numRepeats) + " ms");
076:                }
077:
078:                // Display regular expression
079:                System.out.println("        Input Text: " + argv[1]);
080:                System.out.println("Regular Expression: " + argv[0]);
081:                System.out.println("     Compiled Form: " + expression);
082:
083:                // Is the input in its entirety a match?
084:
085:                System.out.println(" isMatch() returns: "
086:                        + expression.isMatch(argv[1]));
087:
088:                REMatch[] matches = expression.getAllMatches(argv[1]);
089:                System.out.println("   getAllMatches(): " + matches.length
090:                        + " matches");
091:                for (int i = 0; i < matches.length; i++) {
092:                    System.out.println("Match " + i + " ("
093:                            + matches[i].getStartIndex() + ","
094:                            + matches[i].getEndIndex() + "): " + matches[i]);
095:                }
096:
097:                // Get the first match    
098:                REMatch match = null;
099:
100:                begin = System.currentTimeMillis();
101:
102:                for (int rpt = 0; rpt < numRepeats; rpt++)
103:                    match = expression.getMatch(argv[1]);
104:
105:                end = System.currentTimeMillis();
106:
107:                if (numRepeats > 1) {
108:                    System.out.println("Finding first match " + numRepeats
109:                            + " times took " + (end - begin) + " ms");
110:                    System.out.println("Average match time: "
111:                            + ((end - begin) / numRepeats) + " ms");
112:                }
113:
114:                if (match == null)
115:                    System.out.println("Expression did not find a match.");
116:                else {
117:                    // Report the full match indices
118:
119:                    System.out.println("Match found from position "
120:                            + match.getStartIndex() + " to position "
121:                            + match.getEndIndex());
122:
123:                    // Take advantage of REMatch.toString() to print match text
124:
125:                    System.out.println("Match was: '" + match + "'");
126:
127:                    // Report subexpression positions
128:
129:                    for (int i = 1; i <= expression.getNumSubs(); i++) {
130:                        if (match.getSubStartIndex(i) > -1) {
131:                            System.out
132:                                    .println("Subexpression #" + i
133:                                            + ": from position "
134:                                            + match.getSubStartIndex(i)
135:                                            + " to position "
136:                                            + match.getSubEndIndex(i));
137:
138:                            // Note how the $n is constructed for substituteInto
139:
140:                            System.out
141:                                    .println(match
142:                                            .substituteInto("The subexpression matched this text: '$"
143:                                                    + i + "'"));
144:                        }
145:                    }
146:                }
147:
148:                // Here's a substitute test.
149:                System.out.println("substitute(): "
150:                        + expression.substitute(argv[1], "<!--$0-->"));
151:                System.out.println("substituteAll(): "
152:                        + expression.substituteAll(argv[1], "<!--$0-->"));
153:            }
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.