Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>com.zipcodewilmington</groupId>
<artifactId>regex</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by thook on 10/7/15.
Expand Down Expand Up @@ -36,4 +38,29 @@ public String getHamletData(){
return hamletData;
}


public boolean findHoratio(){
Pattern pattern = Pattern.compile("Horatio", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(hamletData);
return matcher.find();
}

public boolean findHamlet() {
Pattern pattern = Pattern.compile("Hamlet", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(hamletData);
return matcher.find();
}

public String ChangeHamletToLeon(){
Pattern pattern = Pattern.compile("Hamlet", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(hamletData);
return matcher.replaceAll("Leon");
}

public String ChangeHoatioToTariq(){
Pattern pattern = Pattern.compile("Hamlet", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(hamletData);
return matcher.replaceAll("Tariq");
}

}
9 changes: 9 additions & 0 deletions src/test/java/HamletParserTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -15,17 +16,25 @@ public void setUp() {

@Test
public void testChangeHamletToLeon() {
String actual = hamletParser.ChangeHamletToLeon();
Assert.assertTrue(actual.contains("Leon"));
}

@Test
public void testChangeHoratioToTariq() {
String actual = hamletParser.ChangeHoatioToTariq();
Assert.assertTrue(actual.contains("Tariq"));
}

@Test
public void testFindHoratio() {
boolean actual = hamletParser.findHoratio();
Assert.assertTrue(actual);
}

@Test
public void testFindHamlet() {
boolean actual = hamletParser.findHamlet();
Assert.assertTrue(actual);
}
}
Loading