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
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@
<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><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>8</source><target>8</target></configuration></plugin>
<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
32 changes: 32 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 All @@ -13,6 +15,7 @@ public HamletParser(){
this.hamletData = loadFile();
}


private String loadFile(){
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("hamlet.txt").getFile());
Expand All @@ -36,4 +39,33 @@ public String getHamletData(){
return hamletData;
}

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

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

public String changeHoratioToTariq(String str) {
Pattern pattern = Pattern.compile("Horatio", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(str);
return matcher.replaceAll("Tariq");
}

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

public String changeHamletText(String str) {
String changeHamlet = changeHamletToLeon(str);
String result = changeHoratioToTariq(changeHamlet);
return result;
}
}
Loading