Skip to content

Complete #31

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
67 changes: 67 additions & 0 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
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 Pattern pattern;
private Matcher matcher;

public HamletParser(){
this.hamletData = loadFile();

}

private String loadFile(){
Expand All @@ -36,4 +41,66 @@ public String getHamletData(){
return hamletData;
}


public void changeHoratioToTariq(){

String horatio = "(Horatio|HORATIO)";

pattern = Pattern.compile(horatio);

matcher = pattern.matcher(hamletData);
hamletData = matcher.replaceAll("Tariq");

}


public void changeHamletToLeon() {
String hamlet = "(Hamlet| HAMLET)";

pattern = Pattern.compile(hamlet);
matcher = pattern.matcher(hamletData);

hamletData = matcher.replaceAll("Leon");

}
public String printOut(){
System.out.println(this.hamletData);
return this.hamletData;
}


public static void main(String[] args) {
HamletParser hamletParser = new HamletParser();
hamletParser.changeHamletToLeon();
hamletParser.printOut();
}

public boolean findHoratio() {
String horatio = "(Horatio|HORATIO)";

pattern = Pattern.compile(horatio);

matcher = pattern.matcher(hamletData);

if(hamletData.contains("(Horatio|HORATIO)")){
return true;
}
return false;

}


public boolean findHamlet() {
String hamlet = "(Hamlet| HAMLET)";

pattern = Pattern.compile(hamlet);
matcher = pattern.matcher(hamletData);

if (hamletData.contains("(Hamlet| HAMLET)")) {
return true;
}
return false;

}

}
34 changes: 32 additions & 2 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 @@ -11,21 +12,50 @@ public class HamletParserTest {
public void setUp() {
this.hamletParser = new HamletParser();
this.hamletText = hamletParser.getHamletData();

}

@Test
public void testChangeHamletToLeon() {
hamletParser.changeHamletToLeon();

boolean expected = false;
boolean actual = hamletParser.findHamlet();

Assert.assertEquals(actual, expected);

}

@Test
public void testChangeHoratioToTariq() {
hamletParser.changeHoratioToTariq();

boolean expected = false;
boolean actual = hamletParser.findHoratio();

Assert.assertEquals(actual, expected);

}

@Test
public void testFindHoratio() {
public void testFindHamlet() {
hamletParser.changeHamletToLeon();

boolean expected = false;
boolean actual = hamletParser.findHamlet();

Assert.assertEquals(actual, expected);
}

@Test
public void testFindHamlet() {
public void testFindHoratio() {
hamletParser.changeHoratioToTariq();

boolean expected = false;
boolean actual = hamletParser.findHamlet();

Assert.assertEquals(actual, expected);
}


}
Loading