Skip to content

Commit 6b260cc

Browse files
committed
Merge pull request #6 from EmilS/master
Maven Repo + Minor Changes to Main File + Unit Tests
2 parents 0f40f5f + 846488b commit 6b260cc

File tree

7 files changed

+309
-15
lines changed

7 files changed

+309
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: java
2+
jdk:
3+
- openjdk7
4+
- oraclejdk7
5+
notifications:
6+
email: false

pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<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>
4+
5+
<groupId>VerbalExpressions</groupId>
6+
<artifactId>JavaVerbalExpressions</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>JavaVerbalExpressions</name>
11+
<url>https://github.com/VerbalExpressions/JavaVerbalExpressions</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
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>
43+
</project>

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
import java.util.regex.Pattern;
22

33
class VerbalExpression {
4-
private String prefixes, source, suffixes, pattern = "";
4+
private String prefixes = "", source = "", suffixes = "", pattern = "";
55
private int modifiers = Pattern.MULTILINE;
66

7+
public VerbalExpression () {
8+
this.updatePattern();
9+
}
10+
711
private String sanitize(String value) {
812
if(value == null)
913
return value;
1014
return Pattern.quote(value);
1115
}
1216

1317
public VerbalExpression add(String value) {
14-
this.source = this.source != null ? this.source + value : value;
15-
if (this.source != null) {
16-
Pattern p = Pattern.compile(this.prefixes + this.source + this.suffixes, this.modifiers);
17-
this.pattern = p.pattern();
18-
}
18+
this.source += value;
19+
return this.updatePattern();
20+
}
21+
22+
public VerbalExpression updatePattern() {
23+
Pattern p = Pattern.compile(this.prefixes + this.source + this.suffixes, this.modifiers);
24+
this.pattern = p.pattern();
1925
return this;
2026
}
2127

2228
public VerbalExpression startOfLine(boolean enable) {
2329
this.prefixes = enable ? "^" : "";
24-
this.add("");
30+
this.updatePattern();
2531
return this;
2632
}
2733

@@ -31,7 +37,7 @@ public VerbalExpression startOfLine() {
3137

3238
public VerbalExpression endOfLine(boolean enable) {
3339
this.suffixes = enable ? "$" : "";
34-
this.add("");
40+
this.updatePattern();
3541
return this;
3642
}
3743

@@ -79,7 +85,7 @@ public VerbalExpression somethingBut(String value) {
7985
}
8086

8187
public VerbalExpression replace(String source, String value) {
82-
this.add("");
88+
this.updatePattern();
8389
this.source.replaceAll(pattern,value);
8490
return this;
8591
}
@@ -159,7 +165,7 @@ public VerbalExpression addModifier(char modifier) {
159165
break;
160166
}
161167

162-
this.add("");
168+
this.updatePattern();
163169
return this;
164170
}
165171

@@ -190,14 +196,14 @@ public VerbalExpression removeModifier(char modifier) {
190196
break;
191197
}
192198

193-
this.add("");
199+
this.updatePattern();
194200
return this;
195201
}
196202

197203
public VerbalExpression withAnyCase(boolean enable) {
198204
if (enable) this.addModifier( 'i' );
199205
else this.removeModifier( 'i' );
200-
this.add("");
206+
this.updatePattern();
201207
return this;
202208
}
203209

@@ -208,7 +214,7 @@ public VerbalExpression withAnyCase() {
208214
public VerbalExpression searchOneLine(boolean enable) {
209215
if (enable) this.removeModifier( 'm' );
210216
else this.addModifier( 'm' );
211-
this.add("");
217+
this.updatePattern();
212218
return this;
213219
}
214220

@@ -235,12 +241,10 @@ public VerbalExpression or(String value) {
235241
}
236242

237243
public boolean test(String toTest) {
238-
this.add("");
239244
return Pattern.matches(this.pattern, toTest);
240245
}
241246

242247
public String toString() {
243-
this.add("");
244248
return this.pattern.toString();
245249
}
246250
}

src/test/java/TestRunner.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import org.junit.runner.JUnitCore;
2+
import org.junit.runner.Result;
3+
import org.junit.runner.notification.Failure;
4+
5+
public class TestRunner {
6+
public static void main(String[] args) {
7+
Result result = JUnitCore.runClasses(VerbalExpressionUnitTests.class);
8+
for (Failure failure : result.getFailures()) {
9+
System.out.println(failure.toString());
10+
}
11+
System.out.println(result.wasSuccessful());
12+
}
13+
}

src/test/java/TestSuite.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import org.junit.runner.RunWith;
2+
import org.junit.runners.Suite;
3+
4+
//JUnit Suite Test
5+
@RunWith(Suite.class)
6+
@Suite.SuiteClasses({
7+
VerbalExpressionUnitTests.class
8+
})
9+
public class TestSuite {
10+
11+
}

0 commit comments

Comments
 (0)