Skip to content

ok but need test #26

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
24 changes: 22 additions & 2 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
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.
* @TODO
* @1. Go through the hamlet file , use Regular expressions (Regex)
* Replace all instances of the string "Hamlet" with "Leon"
* Replace all instances of the string "Horatio" with "Tariq"
* Breakdown all the logic to complete this process
* Must use Pattern && Matcher to replace the words ^Hint: replaceAll();^
*/
// LOGIC
// ==============
// Iterate through the file
// Use regular expressions/ Pattern & Matcher to target specific strings or matches of characters
// in this case "Hamlet" & "Horatio"
// After I've locked on to all targeted strings/characters then replace them,
// Maybe replace them using the replaceAll(); function
public class HamletParser {

private String hamletData;
Expand Down Expand Up @@ -32,8 +46,14 @@ private String loadFile(){
return result.toString();
}

public String nameSwapper(String match, String newMatch, String nameInput){
Pattern namePattern = Pattern.compile(match); //instance class of pattern compressed version of Regex
Matcher nameMatch = namePattern.matcher(nameInput); //use my pattern object to make an instance of matcher, which will then parse my nameinput
return nameMatch.replaceAll(newMatch);
}

public String getHamletData(){
return hamletData;
}

}
}
5 changes: 5 additions & 0 deletions src/test/java/HamletParserTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import jdk.nashorn.internal.runtime.regexp.joni.Regex;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.regex.Pattern;

import static org.junit.Assert.*;

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

@Test
public void testChangeHamletToLeon() {

}

@Test
Expand Down
Loading