[logback-dev] svn commit: r2042 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/joran/spi test/java/ch/qos/logback/core/joran/spi
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Mon Dec 1 12:30:02 CET 2008
Author: ceki
Date: Mon Dec 1 12:30:02 2008
New Revision: 2042
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Pattern.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PatternTest.java
Log:
- cosmetic changes only
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Pattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Pattern.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Pattern.java Mon Dec 1 12:30:02 2008
@@ -1,7 +1,7 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 2000-2008, QOS.ch
*
* This library is free software, you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -12,20 +12,12 @@
import java.util.ArrayList;
-
public class Pattern {
-
+
// contains String instances
- ArrayList<String> components;
+ ArrayList<String> partList = new ArrayList<String>();
public Pattern() {
- components = new ArrayList<String>();
- }
-
- public Object clone() {
- Pattern p = new Pattern();
- p.components.addAll(this.components);
- return p;
}
/**
@@ -50,48 +42,54 @@
// System.out.println("k is "+ k);
if (k == -1) {
String lastPart = p.substring(lastIndex);
- if(lastPart != null && lastPart.length() > 0) {
- components.add(p.substring(lastIndex));
+ if (lastPart != null && lastPart.length() > 0) {
+ partList.add(p.substring(lastIndex));
}
break;
} else {
String c = p.substring(lastIndex, k);
if (c.length() > 0) {
- components.add(c);
+ partList.add(c);
}
lastIndex = k + 1;
}
}
- //System.out.println(components);
+ // System.out.println(components);
+ }
+
+ public Object clone() {
+ Pattern p = new Pattern();
+ p.partList.addAll(this.partList);
+ return p;
}
public void push(String s) {
- components.add(s);
+ partList.add(s);
}
public int size() {
- return components.size();
+ return partList.size();
}
public String get(int i) {
- return (String) components.get(i);
+ return (String) partList.get(i);
}
public void pop() {
- if (!components.isEmpty()) {
- components.remove(components.size() - 1);
+ if (!partList.isEmpty()) {
+ partList.remove(partList.size() - 1);
}
}
-
+
public String peekLast() {
- if (!components.isEmpty()) {
- int size = components.size();
- return (String) components.get(size - 1);
+ if (!partList.isEmpty()) {
+ int size = partList.size();
+ return (String) partList.get(size - 1);
} else {
- return null;
+ return null;
}
}
@@ -105,8 +103,8 @@
return 0;
}
- int lSize = this.components.size();
- int rSize = p.components.size();
+ int lSize = this.partList.size();
+ int rSize = p.partList.size();
// no match possible for empty sets
if ((lSize == 0) || (rSize == 0)) {
@@ -118,8 +116,8 @@
// loop from the end to the front
for (int i = 1; i <= minLen; i++) {
- String l = (String) this.components.get(lSize - i);
- String r = (String) p.components.get(rSize - i);
+ String l = (String) this.partList.get(lSize - i);
+ String r = (String) p.partList.get(rSize - i);
if (l.equals(r)) {
match++;
@@ -141,8 +139,8 @@
return 0;
}
- int lSize = this.components.size();
- int rSize = p.components.size();
+ int lSize = this.partList.size();
+ int rSize = p.partList.size();
// no match possible for empty sets
if ((lSize == 0) || (rSize == 0)) {
@@ -153,10 +151,10 @@
int match = 0;
for (int i = 0; i < minLen; i++) {
- String l = (String) this.components.get(i);
- String r = (String) p.components.get(i);
+ String l = (String) this.partList.get(i);
+ String r = (String) p.partList.get(i);
- //if (l.equals(r) || "*".equals(l) || "*".equals(r)) {
+ // if (l.equals(r) || "*".equals(l) || "*".equals(r)) {
if (l.equals(r)) {
match++;
} else {
@@ -167,23 +165,21 @@
return match;
}
-
-
@Override
public boolean equals(Object o) {
- //System.out.println("in equals:" +this+ " vs. " + o);
+ // System.out.println("in equals:" +this+ " vs. " + o);
if ((o == null) || !(o instanceof Pattern)) {
return false;
}
- //System.out.println("both are Patterns");
+ // System.out.println("both are Patterns");
Pattern r = (Pattern) o;
if (r.size() != size()) {
return false;
}
- //System.out.println("both are size compatible");
+ // System.out.println("both are size compatible");
int len = size();
for (int i = 0; i < len; i++) {
@@ -204,7 +200,7 @@
for (int i = 0; i < len; i++) {
hc ^= get(i).hashCode();
- //System.out.println("i = "+i+", hc="+hc);
+ // System.out.println("i = "+i+", hc="+hc);
}
return hc;
@@ -212,10 +208,10 @@
@Override
public String toString() {
- int size = components.size();
+ int size = partList.size();
String result = "";
- for(int i = 0; i < size; i++) {
- result += "[" + components.get(i) + "]";
+ for (int i = 0; i < size; i++) {
+ result += "[" + partList.get(i) + "]";
}
return result;
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java Mon Dec 1 12:30:02 2008
@@ -1,7 +1,7 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 2000-2008, QOS.ch
*
* This library is free software, you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -9,6 +9,7 @@
*/
package ch.qos.logback.core.joran.spi;
+import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -17,7 +18,7 @@
public static Test suite() {
TestSuite suite = new TestSuite();
- suite.addTestSuite(PatternTest.class);
+ suite.addTest(new JUnit4TestAdapter(PatternTest.class));
suite.addTestSuite(SimpleStoreTest.class);
suite.addTestSuite(PropertySetterTest.class);
return suite;
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PatternTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PatternTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PatternTest.java Mon Dec 1 12:30:02 2008
@@ -1,7 +1,7 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 2000-2008, QOS.ch
*
* This library is free software, you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -10,38 +10,18 @@
package ch.qos.logback.core.joran.spi;
-import ch.qos.logback.core.joran.spi.Pattern;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Test pattern manipulation code.
*
* @author Ceki Gulcu
*/
-public class PatternTest extends TestCase {
- /**
- * Constructor for PatternTestCase.
- *
- * @param name
- */
- public PatternTest(String name) {
- super(name);
- }
-
- /*
- * @see TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- /*
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+public class PatternTest {
+ @Test
public void test1() {
Pattern p = new Pattern("a");
assertEquals(1, p.size());
@@ -49,6 +29,7 @@
assertEquals("a", p.get(0));
}
+ @Test
public void testSuffix() {
Pattern p = new Pattern("a/");
assertEquals(1, p.size());
@@ -56,6 +37,7 @@
assertEquals("a", p.get(0));
}
+ @Test
public void test2() {
Pattern p = new Pattern("a/b");
assertEquals(2, p.size());
@@ -64,6 +46,7 @@
assertEquals("b", p.get(1));
}
+ @Test
public void test3() {
Pattern p = new Pattern("a123/b1234/cvvsdf");
assertEquals(3, p.size());
@@ -72,6 +55,7 @@
assertEquals("cvvsdf", p.get(2));
}
+ @Test
public void test4() {
Pattern p = new Pattern("/a123/b1234/cvvsdf");
assertEquals(3, p.size());
@@ -80,12 +64,14 @@
assertEquals("cvvsdf", p.get(2));
}
+ @Test
public void test5() {
Pattern p = new Pattern("//a");
assertEquals(1, p.size());
assertEquals("a", p.get(0));
}
+ @Test
public void test6() {
Pattern p = new Pattern("//a//b");
assertEquals(2, p.size());
@@ -95,6 +81,7 @@
// test tail matching
+ @Test
public void testTailMatch() {
{
Pattern p = new Pattern("/a/b");
@@ -123,6 +110,7 @@
}
// test prefix matching
+ @Test
public void testPrefixMatch() {
{
Pattern p = new Pattern("/a/b");
More information about the logback-dev
mailing list