Skip to content

Commit 33b5046

Browse files
committed
cleaning up a little code, adding some reporting plugins.
1 parent 1739d58 commit 33b5046

File tree

6 files changed

+130
-63
lines changed

6 files changed

+130
-63
lines changed

pom.xml

Lines changed: 108 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,114 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
44

5-
<groupId>VerbalExpressions</groupId>
6-
<artifactId>JavaVerbalExpressions</artifactId>
7-
<version>1.0-SNAPSHOT</version>
8-
<packaging>jar</packaging>
5+
<groupId>VerbalExpressions</groupId>
6+
<artifactId>JavaVerbalExpressions</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
99

10-
<name>JavaVerbalExpressions</name>
11-
<url>https://github.com/VerbalExpressions/JavaVerbalExpressions</url>
10+
<name>JavaVerbalExpressions</name>
11+
<url>https://github.com/VerbalExpressions/JavaVerbalExpressions</url>
1212

13-
<properties>
14-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
</properties>
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
1616

17-
18-
<scm>
19-
<connection>[email protected]:VerbalExpressions/JavaVerbalExpressions.git</connection>
20-
</scm>
21-
<dependencies>
22-
<dependency>
23-
<groupId>junit</groupId>
24-
<artifactId>junit</artifactId>
25-
<version>4.11</version>
26-
<scope>test</scope>
27-
</dependency>
28-
</dependencies>
29-
<build>
30-
<plugins>
31-
<plugin>
32-
<artifactId>maven-compiler-plugin</artifactId>
33-
<version>3.1</version>
34-
<inherited>true</inherited>
35-
<configuration>
36-
<source>1.6</source>
37-
<target>1.6</target>
38-
<encoding>utf-8</encoding>
39-
</configuration>
40-
</plugin>
41-
</plugins>
42-
</build>
17+
18+
<scm>
19+
<connection>scm:[email protected]:VerbalExpressions/JavaVerbalExpressions.git</connection>
20+
</scm>
21+
<dependencies>
22+
<dependency>
23+
<groupId>junit</groupId>
24+
<artifactId>junit</artifactId>
25+
<version>4.11</version>
26+
<scope>test</scope>
27+
</dependency>
28+
</dependencies>
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<version>3.1</version>
34+
<inherited>true</inherited>
35+
<configuration>
36+
<source>1.6</source>
37+
<target>1.6</target>
38+
<encoding>utf-8</encoding>
39+
</configuration>
40+
</plugin>
41+
<plugin>
42+
<groupId>org.codehaus.mojo</groupId>
43+
<artifactId>cobertura-maven-plugin</artifactId>
44+
<version>2.6</version>
45+
<executions>
46+
<execution>
47+
<!-- <phase>site</phase> -->
48+
<goals>
49+
<goal>clean</goal>
50+
</goals>
51+
</execution>
52+
</executions>
53+
<!-- <configuration> -->
54+
<!-- <instrumentation> -->
55+
<!-- <ignores> -->
56+
<!-- <ignore>com.example.boringcode.*</ignore> -->
57+
<!-- </ignores> -->
58+
<!-- <excludes> -->
59+
<!-- <exclude>com/example/dullcode/**/*.class</exclude> -->
60+
<!-- <exclude>com/example/**/*Test.class</exclude> -->
61+
<!-- </excludes> -->
62+
<!-- </instrumentation> -->
63+
<!-- </configuration> -->
64+
</plugin>
65+
</plugins>
66+
</build>
67+
68+
<reporting>
69+
<plugins>
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-pmd-plugin</artifactId>
73+
<version>3.0.1</version>
74+
<configuration>
75+
<linkXref>true</linkXref>
76+
<sourceEncoding>utf-8</sourceEncoding>
77+
<minimumTokens>100</minimumTokens>
78+
<targetJdk>1.5</targetJdk>
79+
<excludes>
80+
<exclude>**/*Bean.java</exclude>
81+
<exclude>**/generated/*.java</exclude>
82+
</excludes>
83+
<excludeRoots>
84+
<excludeRoot>target/generated-sources/stubs</excludeRoot>
85+
</excludeRoots>
86+
</configuration>
87+
</plugin>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-pmd-plugin</artifactId>
91+
<version>3.0.1</version>
92+
<configuration>
93+
<linkXref>true</linkXref>
94+
<sourceEncoding>utf-8</sourceEncoding>
95+
<minimumTokens>100</minimumTokens>
96+
<targetJdk>1.7</targetJdk>
97+
<!-- <excludes> -->
98+
<!-- <exclude>**/*Bean.java</exclude> -->
99+
<!-- <exclude>**/generated/*.java</exclude> -->
100+
<!-- </excludes> -->
101+
<!-- <excludeRoots> -->
102+
<!-- <excludeRoot>target/generated-sources/stubs</excludeRoot> -->
103+
<!-- </excludeRoots> -->
104+
</configuration>
105+
</plugin>
106+
107+
<plugin>
108+
<groupId>org.codehaus.mojo</groupId>
109+
<artifactId>cobertura-maven-plugin</artifactId>
110+
<version>2.6</version>
111+
</plugin>
112+
</plugins>
113+
</reporting>
43114
</project>

src/main/java/VerbalExpression.java renamed to src/main/java/verbal/expressions/VerbalExpression.java

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,36 @@
1+
package verbal.expressions;
12

23
import java.util.regex.Matcher;
34
import java.util.regex.Pattern;
45

56
public class VerbalExpression {
67

7-
private Pattern pattern;
8-
8+
private final Pattern pattern;
9+
910
public static class Builder {
1011

11-
private String prefixes = "", source = "", suffixes = "";
12+
private StringBuilder prefixes = new StringBuilder();
13+
private StringBuilder source = new StringBuilder();
14+
private StringBuilder suffixes = new StringBuilder();
1215
private Pattern pattern;
1316
private int modifiers = Pattern.MULTILINE;
1417

1518
private String sanitize(final String pValue) {
16-
Matcher matcher = Pattern.compile("").matcher("").usePattern(Pattern.compile("[^\\w]"));
17-
int lastEnd = 0;
18-
String result = "";
19-
matcher.reset(pValue);
20-
boolean matcherCalled = false;
21-
while (matcher.find()) {
22-
matcherCalled = true;
23-
if (matcher.start() != lastEnd) {
24-
result += pValue.substring(lastEnd, matcher.start());
25-
}
26-
result += "\\" + pValue.substring(matcher.start(), matcher.end());
27-
lastEnd = matcher.end();
28-
}
29-
if (!matcherCalled) {
30-
return pValue;
31-
}
32-
return result;
19+
return pValue.replaceAll("[\\W]", "\\\\$0");
3320
}
3421

3522
public Builder add(String pValue) {
36-
this.source += pValue;
23+
this.source.append(pValue);
3724
return this;
3825
}
3926

4027
public VerbalExpression build() {
41-
pattern = Pattern.compile(this.prefixes + this.source + this.suffixes, this.modifiers);
28+
pattern = Pattern.compile(this.prefixes.toString() + this.source.toString() + this.suffixes, this.modifiers);
4229
return new VerbalExpression(this);
4330
}
4431

4532
public Builder startOfLine(boolean pEnable) {
46-
this.prefixes = pEnable ? "^" : "";
33+
this.prefixes.append(pEnable ? "^" : "");
4734
return this;
4835
}
4936

@@ -52,7 +39,7 @@ public Builder startOfLine() {
5239
}
5340

5441
public Builder endOfLine(final boolean pEnable) {
55-
this.suffixes = pEnable ? "$" : "";
42+
this.suffixes.append(pEnable ? "$" : "");
5643
return this;
5744
}
5845

@@ -236,10 +223,10 @@ public Builder multiple(final String pValue) {
236223

237224
public Builder or(final String pValue) {
238225
if (this.prefixes.indexOf("(") == -1) {
239-
this.prefixes += "(";
226+
this.prefixes.append("(");
240227
}
241228
if (this.suffixes.indexOf(")") == -1) {
242-
this.suffixes = ")" + this.suffixes;
229+
this.suffixes.append(")" + this.suffixes.toString());
243230
}
244231

245232
this.add(")|(");

src/test/java/BasicFunctionalityUnitTests.java renamed to src/test/java/verbal/expressions/BasicFunctionalityUnitTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
package verbal.expressions;
12
import org.junit.Test;
23
import org.junit.Before;
34
import org.junit.Ignore;
5+
6+
import verbal.expressions.VerbalExpression;
47
import static org.junit.Assert.*;
58

69
public class BasicFunctionalityUnitTests {

src/test/java/RealWorldUnitTests.java renamed to src/test/java/verbal/expressions/RealWorldUnitTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
package verbal.expressions;
12

23
import static org.junit.Assert.*;
4+
35
import org.junit.Test;
46

7+
import verbal.expressions.VerbalExpression;
8+
59
public class RealWorldUnitTests {
610

711
@Test

src/test/java/TestRunner.java renamed to src/test/java/verbal/expressions/TestRunner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package verbal.expressions;
12
import org.junit.runner.JUnitCore;
23
import org.junit.runner.Result;
34
import org.junit.runner.notification.Failure;

src/test/java/TestSuite.java renamed to src/test/java/verbal/expressions/TestSuite.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package verbal.expressions;
12
import org.junit.runner.RunWith;
23
import org.junit.runners.Suite;
34

0 commit comments

Comments
 (0)