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
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>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
Expand Down
46 changes: 44 additions & 2 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Formatter;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by thook on 10/7/15.
Expand Down Expand Up @@ -36,4 +39,43 @@ public String getHamletData(){
return hamletData;
}

public boolean findHamlet() {
if (hamletData.contains("Hamlet")) {
return true;
}
return false;
}

public boolean findHoratio() {
if (hamletData.contains("Horatio")) {
return true;
}
return false;
}

public void changeHamletToLeon() {
Matcher matcher = matchHamlet();
hamletData = matcher.replaceAll("Leon");
}

public void changeHoratioToTariq() {
Matcher matcher = matchHoratio();
hamletData = matcher.replaceAll("Tariq");
}

public Matcher matchHamlet() {
return Pattern.compile("(?i)Hamlet").matcher(hamletData);
}

public Matcher matchHoratio() {
return Pattern.compile("(?i)Horatio").matcher(hamletData);
}

public void changeFile() throws IOException {
FileWriter fileWriter = new FileWriter("/Users/zach/dev/Maven.Regex-Hamlet-Parser/src/main/resources/hamlet.txt");
changeHoratioToTariq();
changeHamletToLeon();
fileWriter.write(hamletData);
fileWriter.close();
}
}
10 changes: 10 additions & 0 deletions src/main/java/MainApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import java.io.FileNotFoundException;
import java.io.IOException;

public class MainApplication {

public static void main(String[] args) throws IOException {
HamletParser parser = new HamletParser();
parser.changeFile();
}
}
Loading