Skip to content

Finished #20

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 2 commits 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
71 changes: 70 additions & 1 deletion src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;

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 HamletParser hamletParser;
private String hamletData;
private String inputText;

public HamletParser(){
this.hamletData = loadFile();
Expand All @@ -32,8 +38,71 @@ private String loadFile(){
return result.toString();
}

public boolean findHoratio(String inputText){
if (inputText.contains("HORATIO") || inputText.contains("Horatio"));
return true;
}

public boolean findHamlet(String inputText){
if (inputText.contains("HAMLET") || inputText.contains("Hamlet"));
return true;
}

public String changeHoratioToTariq(String inputText){

String str = inputText;
Pattern p = Pattern.compile("\\bHoratio\\b");
Matcher m = p.matcher(str);
String capital = m.replaceAll("Tariq");

String lower = capital;
Pattern p2 = Pattern.compile("\\bHORATIO\\b");
Matcher m2 = p2.matcher(lower);
String result = m2.replaceAll("TARIQ");
return result;
}

public String changeHamletToLeon(String inputText){

String str = inputText;
Pattern p = Pattern.compile("\\bHamlet\\b");
Matcher m = p.matcher(str);
String capital = m.replaceAll("Leon");

String lower = capital;
Pattern p2 = Pattern.compile("\\bHAMLET\\b");
Matcher m2 = p2.matcher(lower);
String result = m2.replaceAll("LEON");
return result;
}

public String changeBothNames(String inputText){
String str = inputText;
Pattern p = Pattern.compile("\\bHoratio\\b");
Matcher m = p.matcher(str);
String capital = m.replaceAll("Tariq");

String lower = capital;
Pattern p2 = Pattern.compile("\\bHORATIO\\b");
Matcher m2 = p2.matcher(lower);
String resultOne = m2.replaceAll("TARIQ");

String hamBoy = resultOne;
Pattern p3 = Pattern.compile("\\bHamlet\\b");
Matcher m3 = p3.matcher(hamBoy);
String ham1 = m3.replaceAll("Leon");

String ham2 = ham1;
Pattern p4 = Pattern.compile("\\bHAMLET\\b");
Matcher m4 = p4.matcher(ham2);
String result = m4.replaceAll("LEON");
return result;

}

public String getHamletData(){
return hamletData;
}

}

}
25 changes: 25 additions & 0 deletions src/test/java/HamletParserTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;
import org.junit.Before;
import org.junit.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.junit.Assert.*;

public class HamletParserTest {
Expand All @@ -15,17 +19,38 @@ public void setUp() {

@Test
public void testChangeHamletToLeon() {
String expected = "Leon";
String actual = hamletParser.changeHamletToLeon("Hamlet");
assertEquals(expected, actual);
}


@Test
public void testChangeHoratioToTariq() {
String expected = "Tariq";
String actual = hamletParser.changeHoratioToTariq("Horatio");
assertEquals(expected, actual);
}

@Test
public void testFindHoratio() {
boolean expected = true;
boolean actual = hamletParser.findHoratio("This is a string with the name Horatio in it");
assertEquals(expected, actual);
}

@Test
public void testFindHamlet() {
boolean expected = true;
boolean actual = hamletParser.findHamlet("This is a string with the name Hamlet in it");
assertEquals(expected, actual);
}

@Test
public void testChangedBothNames(){
String expected = "Tariq and Leon are friends";
String actual = hamletParser.changeBothNames("Horatio and Hamlet are friends");
assertEquals(expected, actual);

}
}
Loading