Skip to content

something something fair is foul #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
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.
*/
public class HamletParser {

private String hamletData;
private String hamlet = "\\bHamlet\\b";
private String horatio = "\\bHoratio\\b";
private String leon = "Leon";
private String tariq = "Tariq";

public HamletParser(){
this.hamletData = loadFile();
Expand Down Expand Up @@ -36,4 +42,46 @@ public String getHamletData(){
return hamletData;
}

public boolean findLeon(){
if (getHamletData().contains(leon)){
return true;
}
return false;
}
public boolean findTariq(){
if (getHamletData().contains(tariq)) {
return true;
}
return false;
}
public boolean findHamlet(){
if (getHamletData().contains("HAMLET")){
return true;
}
return false;
}

public boolean findHoratio(){
if (getHamletData().contains("HORATIO")) {
return true;
}
return false;
}

public void changeHamletToLeon(){
Pattern hamleon = Pattern.compile(hamlet, Pattern.CASE_INSENSITIVE);
Matcher matcher = hamleon.matcher(hamletData);
while (matcher.find()){
this.hamletData = matcher.replaceAll("Leon");
}

}
public void changeHoratioToTariq(){
Pattern horatariq = Pattern.compile(horatio, Pattern.CASE_INSENSITIVE);
Matcher matcher = horatariq.matcher(hamletData);
while (matcher.find()){
this.hamletData = matcher.replaceAll("Tariq");
}
}

}
13 changes: 13 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,29 @@ public void setUp() {

@Test
public void testChangeHamletToLeon() {
HamletParser testlet = new HamletParser();
testlet.changeHamletToLeon();
Assert.assertTrue(testlet.findLeon());
Assert.assertFalse(testlet.findHamlet());
}

@Test
public void testChangeHoratioToTariq() {
HamletParser testlet = new HamletParser();
testlet.changeHoratioToTariq();
Assert.assertTrue(testlet.findTariq());
Assert.assertFalse(testlet.findHoratio());
}

@Test
public void testFindHoratio() {
Assert.assertTrue(hamletParser.findHoratio());
Assert.assertTrue(hamletParser.findHamlet());
}

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