Source Code Cross Referenced for AternativeApproach.java in  » Development » SLF4J » org » slf4j » migrator » 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 » Development » SLF4J » org.slf4j.migrator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.slf4j.migrator;
002:
003:        import java.util.regex.Matcher;
004:        import java.util.regex.Pattern;
005:
006:        import org.slf4j.migrator.line.MultiGroupConversionRule;
007:
008:        import junit.framework.TestCase;
009:
010:        public class AternativeApproach extends TestCase {
011:
012:            /**
013:             * In this test we see that we cans use more simple Pattern to do the
014:             * conversion
015:             * 
016:             */
017:            public void test() {
018:                MultiGroupConversionRule cr2 = new MultiGroupConversionRule(
019:                        Pattern.compile("(.*)(Log)"));
020:                cr2.addReplacement(2, "LOGGER");
021:
022:                String s = "abcd Log";
023:                Pattern pat = cr2.getPattern();
024:                Matcher m = pat.matcher(s);
025:
026:                assertTrue(m.matches());
027:                String r = cr2.replace(m);
028:                assertEquals("abcd LOGGER", r);
029:
030:                System.out.println(r);
031:            }
032:
033:            /**
034:             * In this test we replace, using the simple Pattern (Log), the full Log
035:             * declaration and instanciation. This is not convenient because we will also
036:             * replace all String containing "Log".
037:             */
038:            public void test2() {
039:                Pattern pat = Pattern.compile("(Log)");
040:                String s = "abcd Log =";
041:                Matcher m = pat.matcher(s);
042:                assertTrue(m.find());
043:                String r = m.replaceAll("Logger");
044:                assertEquals("abcd Logger =", r);
045:
046:                String s1 = "Log l = LogFactory.getLog(MyClass.class);";
047:                m = pat.matcher(s1);
048:                assertTrue(m.find());
049:                r = m.replaceAll("Logger");
050:                assertEquals(
051:                        "Logger l = LoggerFactory.getLogger(MyClass.class);", r);
052:
053:                String s2 = "Logabc ";
054:                m = pat.matcher(s2);
055:                assertTrue(m.find());
056:
057:                String s3 = "abcLog";
058:                m = pat.matcher(s3);
059:                assertTrue(m.find());
060:            }
061:
062:            /**
063:             * In this test we use a simple Pattern to replace the log instanciation
064:             * without influence on Log declaration.
065:             * 
066:             */
067:            public void test3() {
068:                Pattern pat = Pattern
069:                        .compile("LogFactory.getFactory\\(\\).getInstance\\(");
070:                String s = "Log log =  LogFactory.getFactory().getInstance(\"x\");";
071:                Matcher m = pat.matcher(s);
072:                assertTrue(m.find());
073:                String r = m.replaceAll("LoggerFactory.getLogger(");
074:                assertEquals("Log log =  LoggerFactory.getLogger(\"x\");", r);
075:
076:                String nonMatching = "Log log = xxx;";
077:                pat.matcher(nonMatching);
078:                assertFalse(m.find());
079:            }
080:
081:            /**
082:             * In this test we try to replace keyword Log without influence on String
083:             * containg Log We see that we have to use two differents Patterns
084:             */
085:            public void test4() {
086:                Pattern pat = Pattern.compile("(\\sLog\\b)");
087:                String s = "abcd Log =";
088:                Matcher m = pat.matcher(s);
089:                assertTrue(m.find());
090:                String r = m.replaceAll(" Logger");
091:                assertEquals("abcd Logger =", r);
092:
093:                String s2 = "Logabcd ";
094:                m = pat.matcher(s2);
095:                assertFalse(m.find());
096:
097:                String s3 = "abcdLogabcd ";
098:                m = pat.matcher(s3);
099:                assertFalse(m.find());
100:
101:                String s4 = "abcdLog";
102:                m = pat.matcher(s4);
103:                assertFalse(m.find());
104:
105:                String s5 = "Log myLog";
106:                m = pat.matcher(s5);
107:                assertFalse(m.find());
108:
109:                Pattern pat2 = Pattern.compile("^Log\\b");
110:                Matcher m2 = pat2.matcher(s5);
111:                assertTrue(m2.find());
112:                r = m2.replaceAll("Logger");
113:                assertEquals("Logger myLog", r);
114:            }
115:
116:            /**
117:             * In this test we combine two Pattern to achieve the intended conversion
118:             */
119:            public void test5() {
120:                Pattern pat = Pattern.compile("(\\sLog\\b)");
121:                String s = "public Log myLog =LogFactory.getFactory().getInstance(myClass.class);";
122:                Matcher m = pat.matcher(s);
123:                assertTrue(m.find());
124:                String r = m.replaceAll(" Logger");
125:                assertEquals(
126:                        "public Logger myLog =LogFactory.getFactory().getInstance(myClass.class);",
127:                        r);
128:
129:                Pattern pat2 = Pattern
130:                        .compile("LogFactory.getFactory\\(\\).getInstance\\(");
131:                m = pat2.matcher(r);
132:                assertTrue(m.find());
133:                r = m.replaceAll("LoggerFactory.getLogger(");
134:                assertEquals(
135:                        "public Logger myLog =LoggerFactory.getLogger(myClass.class);",
136:                        r);
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.