Skip to content

Finished #22

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
51 changes: 51 additions & 0 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import jdk.nashorn.internal.runtime.regexp.RegExp;

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 hamletDataTemp = hamletData;

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

public boolean findHoratio(String hamletDataTemp){
return hamletDataTemp.contains("Horatio");


// int hamletCount =regexChecker("[Hh][Oo][Ra][Aa][Tt][Ii][Oo]",hamletDataTemp);
//
// if(hamletCount>0){
// return true;
// }
// return false;
}
public boolean findHamlet(String hamletDataTemp){
return hamletDataTemp.contains("Horatio");
}
public String changeHoratioToTariq(String hamletDataTemp){

Pattern replaceHoratio1 = Pattern.compile("[H|h][O|o][R|r][A|a][T|t][I|i][O|o]");
Matcher regexMatcher1 = replaceHoratio1.matcher(hamletDataTemp);
String replaced1 = regexMatcher1.replaceAll("Tariq");

return replaced1;
}

public String changeHamletToLeon(String hamletDataTemp){


Pattern replaceHamlet1 = Pattern.compile("[H|h][A|a][M|m][L|l][E|e][T|t]");
Matcher regexMatcher1 = replaceHamlet1.matcher(hamletDataTemp);
String replaced1 = regexMatcher1.replaceAll("Leon");

return replaced1;
}

public int regexChecker(String input, String hamletDataTemp){

Pattern checkRegex = Pattern.compile(input);
Matcher regexMatcher = checkRegex.matcher(hamletDataTemp);

int count = 0;
while(regexMatcher.find()){
count++;
}
return count;
}


}
34 changes: 33 additions & 1 deletion 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,48 @@ public void setUp() {

@Test
public void testChangeHamletToLeon() {
String testHamletText = "HaMlet, HAMLET will be replaced by Hamlet.";
System.out.println(testHamletText);
testHamletText=hamletParser.changeHamletToLeon(testHamletText);

boolean actual = hamletParser.findHamlet(testHamletText);
Assert.assertFalse(actual);

System.out.println(testHamletText);

}

@Test
public void testChangeHoratioToTariq() {
String testHoratioText = "Horatio will be replaced by Tariq, HoRaTIo HORATIO to Tariq";
testHoratioText=hamletParser.changeHoratioToTariq(testHoratioText);

boolean actual = hamletParser.findHoratio(testHoratioText);
Assert.assertFalse(actual);

System.out.println(testHoratioText);
}

@Test
public void testFindHoratio() {
public void testFindHoratio1() {
String test = "Hor, will go Horatio, life is beautiful and HORATIO enjoys it.";
boolean actual = hamletParser.findHoratio(test);
Assert.assertTrue(actual);
}
@Test
public void testFindHoratio2(){

boolean actual = hamletParser.findHoratio(hamletText);
Assert.assertTrue(actual);

}

@Test
public void testFindHamlet() {

boolean actual = hamletParser.findHamlet(hamletText);
System.out.println(hamletParser.regexChecker("[Hh][Aa][Mm][Ll][Ee][Tt]",hamletText));
Assert.assertTrue(actual);
}

}
Loading