-
Notifications
You must be signed in to change notification settings - Fork 6
first commit with two updated files #10
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
mdbonner
wants to merge
12
commits into
main
Choose a base branch
from
Mark_Bonner_CodeReview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
824aad5
first commit with two updated files
8ed1695
removed import statements
62b0e27
added import statement
a8cff80
added import statements to test file
f08a6f6
changed some code
061c1ba
more import statement changes
be0aa0d
refactored test
9704ca0
attempt to pass Travis test
3cf0123
import changes
dc2311c
fixing Travis issues
d5d61bd
more revisions to pass Travis
56ccfeb
added new test case
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,154 @@ | ||
| public class StringManipulation implements StringManipulationInterface { | ||
| import java.util.ArrayList; | ||
|
|
||
| public class StringManipulation implements StringManipulationInterface { | ||
|
|
||
| private String string; | ||
| private int count; | ||
|
|
||
| @Override | ||
| public String getString() { | ||
| return null; | ||
| return string; | ||
| } | ||
|
|
||
| @Override | ||
| public void setString(String string) { | ||
| this.string = string; | ||
| } | ||
|
|
||
| @Override | ||
| public int count() { | ||
| return 0; | ||
| // initialize word count to 0 | ||
| count = 0; | ||
|
|
||
| // if statement to check if string is null or empty | ||
| if (string == null || string.length() == 0) { | ||
| return count; | ||
| } | ||
|
|
||
| // split the string into a string array, delimiting by one or more spaces | ||
| String[] wordArray = this.string.split("\\s+"); | ||
|
|
||
| count = wordArray.length; | ||
|
|
||
| return count; | ||
| } | ||
|
|
||
| @Override | ||
| public String removeNthCharacter(int n, boolean maintainSpacing) { | ||
| return null; | ||
| public String removeNthCharacter(int n, boolean maintainSpacing) { | ||
| if (n > string.length()) { | ||
| throw new IndexOutOfBoundsException(); | ||
| } else if (n <= 0) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| // initialize an ArrayList of Characters | ||
| ArrayList<Character> charArray = new ArrayList<Character>(); | ||
|
|
||
| // iterate through string and insert each Character in the ArrayList | ||
| for (int i = 0; i < string.length();i ++) { | ||
| charArray.add(string.charAt(i)); | ||
| } | ||
|
|
||
| // determine the highest Nth index less than or equal to the length of this.string | ||
| int limit = string.length() / n; | ||
|
|
||
| // initialize an int array to hold all the indexes to replace | ||
| int[] indexesToReplace = new int[limit]; | ||
|
|
||
| // assign each Nth index to an element in the int array | ||
| for (int i = 1, j = 0; i <= limit; i++, j++) { | ||
| indexesToReplace[j] = n * i; | ||
| } | ||
|
|
||
| //System.out.println("indexes to replace: " + Arrays.toString(indexesToReplace)); | ||
|
|
||
| // iterate through the ArrayList and replace the Character with space or delete | ||
| for (int i = indexesToReplace.length - 1; i >= 0; i--) { | ||
| int index = indexesToReplace[i] - 1; | ||
|
|
||
| if (maintainSpacing == true) { | ||
| charArray.set(index, ' '); | ||
| } | ||
|
|
||
| if (maintainSpacing == false) { | ||
| charArray.remove(index); | ||
| } | ||
| } | ||
|
|
||
| // build the string from the ArrayList and return to main | ||
| StringBuilder stringBuilder = new StringBuilder(); | ||
| for (char c : charArray) { | ||
| stringBuilder.append(c); | ||
| } | ||
|
|
||
| return stringBuilder.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public String[] getSubStrings(int startWord, int endWord) { | ||
| return null; | ||
| public String[] getSubStrings(int startWord, int endWord){ | ||
| // exception: If either "startWord" or "endWord" are invalid | ||
| if (startWord <= 0 || endWord <= 0 || startWord > endWord) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| // exception: If the string has less than "endWord" words in it | ||
| if (count() < endWord) { | ||
| throw new IndexOutOfBoundsException(); | ||
| } | ||
|
|
||
| // split the words into a String array, delimited by one or more spaces | ||
| String[] arr = this.string.split("\\s+"); | ||
|
|
||
| // intialize the return array with size of the number of words to keep | ||
| String[] finalArray = new String[endWord - startWord + 1]; | ||
|
|
||
| // iterate through the array of all words, if the index falls inside the | ||
| // range passed in, then put that word in the new array | ||
| for (int i = 0, j = 0; i <= arr.length; i++) { | ||
| if (i >= startWord && i <= endWord) { | ||
| finalArray[j] = arr[i - 1]; | ||
| j++; | ||
| } | ||
| } | ||
|
|
||
| return finalArray; | ||
| } | ||
|
|
||
| @Override | ||
| public String restoreString(int[] indices) { | ||
| return null; | ||
| public String restoreString(int[] indices){ | ||
| // exception: if not s.length == indices.length == n | ||
| if (string.length() != indices.length) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| // exception: if indices[i] < 0 or indices[i] > string length | ||
| for (int i = 0 ; i < indices.length; i++) { | ||
| if (indices[i] < 0 || indices[i] >= string.length()) { | ||
| throw new IndexOutOfBoundsException(); | ||
| } | ||
| } | ||
|
|
||
| // initialize an ArrayList for the final string to be returned | ||
| ArrayList<Character> finalWord = new ArrayList<>(); | ||
|
|
||
| // fill the ArrayList with characters from the original string | ||
| for (char c : string.toCharArray()) { | ||
| finalWord.add(c); | ||
| } | ||
|
|
||
| // iterate through both the indices parameter and the string characters | ||
| // to load the final array with shuffled characters | ||
| for (int i = 0; i < string.length(); i++) { | ||
| finalWord.set(indices[i], string.charAt(i)); | ||
| } | ||
|
|
||
| // build the string from the ArrayList and return to main | ||
| StringBuilder stringBuilder = new StringBuilder(); | ||
| for (char c : finalWord) { | ||
| stringBuilder.append(c); | ||
| } | ||
|
|
||
| return stringBuilder.toString(); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very weird that I encountered this too but only after the build was semi-successful.
I did not get the same error until I could actually build and have found that some of my test cases failed as well.
Good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alvin, so I seemed to have misunderstood my own solution to the Travis build fail issue. The fundamental problem was my mishandling of the commit & add commands while commenting in/out the import statements. So, if I'm not mistaken again, StringManipulation() does in fact need the import statement for ArrayList and StringManipulationTest() should only have the original import statements from the skeleton, no others.
After making sure this was the case, my build passed without issues (and without my panic), thank goodness.
In your case, I agree that your build had failed because, like you said, some of your test cases did not pass, and not because of import statement issues like me.