ceki 2004/12/23 05:00:59
Modified: src/java/org/apache/log4j/pattern CachedDateFormat.java
CacheUtil.java
Added: tests/src/java/org/apache/log4j/pattern CacheUtilTest.java
Log:
CacheUtil debugged
Revision Changes Path
1.2 +0 -4
logging-log4j/src/java/org/apache/log4j/pattern/CachedDateFormat.java
Index: CachedDateFormat.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/pattern/CachedDateFormat.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CachedDateFormat.java 23 Dec 2004 12:16:22 -0000 1.1
+++ CachedDateFormat.java 23 Dec 2004 13:00:58 -0000 1.2
@@ -36,10 +36,6 @@
private NumberFormat numberFormat;
private static final int UNRECOGNIZED_MILLISECOND_PATTERN = -2;
private static final int NO_MILLISECOND_PATTERN = -1;
-
-
-
-
public CachedDateFormat(final DateFormat formatter) {
if (formatter == null) {
1.2 +9 -10
logging-log4j/src/java/org/apache/log4j/pattern/CacheUtil.java
Index: CacheUtil.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/pattern/CacheUtil.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CacheUtil.java 23 Dec 2004 12:16:22 -0000 1.1
+++ CacheUtil.java 23 Dec 2004 13:00:58 -0000 1.2
@@ -33,7 +33,7 @@
* @param pattern
* @return
*/
- static String removeLiterals(String pattern) {
+ public static String removeLiterals(String pattern) {
StringBuffer pbuf = new StringBuffer(pattern.length());
int state = REGULAR_STATE;
for(int i = 0; i < pattern.length(); i++) {
@@ -45,10 +45,12 @@
} else if( (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
pbuf.append(c);
}
+ break;
case IN_QUOTE_STATE:
if(c == '\'') {
state = REGULAR_STATE;
}
+ break;
}
}
return pbuf.toString();
@@ -62,7 +64,7 @@
* Another uncacheable pattern is that of disjoint Ss, e.g. "YYYY-MM SSE E
SSS"
* a non-sensical pattern, but unsafe nonetheless.
*/
- static boolean isPatternSafeForCaching(String pattern) {
+ public static boolean isPatternSafeForCaching(String pattern) {
// this code assumes that literals have been removed from the pattern
if(pattern.indexOf("EEEE") != -1 && pattern.indexOf("MMMM") != -1) {
return false;
@@ -73,15 +75,15 @@
return true;
}
- int computeSuccessiveS(String pattern) {
+ public static int computeSuccessiveS(String pattern) {
// this code assumes that literals have been removed from the pattern
int len = pattern.length();
int i = pattern.indexOf('S');
- if(i != -1)
+ if(i == -1)
return 0;
- int count = 1;
+ int count = 0;
while(i < len && pattern.charAt(i++) == 'S') {
count++;
}
@@ -100,16 +102,13 @@
int len = pattern.length();
int i = pattern.indexOf('S');
- if(i != -1)
+ if(i == -1)
return false;
// skip any ajoining S
- while(i < len && pattern.charAt(i++) == 'S') {
+ while( i < len && pattern.charAt(i++) == 'S') {
}
- // i now points to a character different than 'S'
- // the first possible occurence of S must come after i, hence the i++;
- i++;
if(i >= len )
return false;
else {
1.1
logging-log4j/tests/src/java/org/apache/log4j/pattern/CacheUtilTest.java
Index: CacheUtilTest.java
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.log4j.pattern;
import junit.framework.TestCase;
/**
* @author Ceki Gulcu
* */
public class CacheUtilTest extends TestCase {
public CacheUtilTest(String arg0) {
super(arg0);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testRemoveLiteral() {
String result;
result = CacheUtil.removeLiterals("a");
assertEquals("a", result);
result = CacheUtil.removeLiterals("a'a'");
assertEquals("a", result);
result = CacheUtil.removeLiterals("-+?.a124'a'");
assertEquals("a", result);
result = CacheUtil.removeLiterals("ZZZEEE");
assertEquals("ZZZEEE", result);
}
public void testIsPatternSafeForCachingRemoveLiteral() {
boolean result;
result = CacheUtil.isPatternSafeForCaching("a");
assertEquals(true, result);
result = CacheUtil.isPatternSafeForCaching("aS");
assertEquals(true, result);
result = CacheUtil.isPatternSafeForCaching("aSS");
assertEquals(true, result);
result = CacheUtil.isPatternSafeForCaching("aSSS");
assertEquals(true, result);
result = CacheUtil.isPatternSafeForCaching("aSSSS");
assertEquals(true, result);
result = CacheUtil.isPatternSafeForCaching("aSaS");
assertEquals(false, result);
result = CacheUtil.isPatternSafeForCaching("aSSSSSaSSS");
assertEquals(false, result);
result = CacheUtil.isPatternSafeForCaching("aSaSa");
assertEquals(false, result);
result = CacheUtil.isPatternSafeForCaching("aSSaSSa");
assertEquals(false, result);
result = CacheUtil.isPatternSafeForCaching("aSSSaSSSa");
assertEquals(false, result);
result = CacheUtil.isPatternSafeForCaching("aEEEE SSS");
assertEquals(true, result);
result = CacheUtil.isPatternSafeForCaching("aEEEEMMMMM SSS");
assertEquals(false, result);
}
public void testComputeSuccessiveS() {
int result;
result = CacheUtil.computeSuccessiveS("a");
assertEquals(0, result);
result = CacheUtil.computeSuccessiveS("aS");
assertEquals(1, result);
result = CacheUtil.computeSuccessiveS("aSS");
assertEquals(2, result);
result = CacheUtil.computeSuccessiveS("aSSS");
assertEquals(3, result);
result = CacheUtil.computeSuccessiveS("aSSSS");
assertEquals(4, result);
result = CacheUtil.computeSuccessiveS("aSxx");
assertEquals(1, result);
result = CacheUtil.computeSuccessiveS("aSSxx");
assertEquals(2, result);
result = CacheUtil.computeSuccessiveS("aSSSxx");
assertEquals(3, result);
result = CacheUtil.computeSuccessiveS("aSSSSxx");
assertEquals(4, result);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]