Skip to content

[Emily_Su_CodeReview] Implement StringManipulation Class and Corresponding Unit Tests#26

Open
meelybug123 wants to merge 2 commits intomainfrom
Emily_Su_CodeReview
Open

[Emily_Su_CodeReview] Implement StringManipulation Class and Corresponding Unit Tests#26
meelybug123 wants to merge 2 commits intomainfrom
Emily_Su_CodeReview

Conversation

@meelybug123
Copy link

@sarafarag sarafarag requested a review from BensGitHub2022 June 16, 2023 19:29

public class StringManipulation implements StringManipulationInterface {

private String[] wordArray;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more my opinion but after reviewing all of your code I think you might have done yourself a slight disservice by using an array of Strings as your private field. Throughout your code you are converting between the array to the String quite often and the state of your variable changes depending on the requirements of the method. Several of the methods have to call one another to achieve basic output. For example, your return removeNthCharacter method has to convert the string to an array and then perform manipulations on it. The only method which really saved you time by using the array of Strings field was the get substrings method but depending on the final implementation this time savings may or may not be worth it. Given the generic nature of the assignment and the number of methods we had to implement it might have been easier to work with a simple string and convert it to an array when necessary.

}
if (maintainSpacing) {
for (int i = n - 1; i < retVal.length(); i += n) {
retVal = retVal.substring(0, i) + " " + retVal.substring(i + 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is clever use of .substring(x,y)

}
else {
for (int i = n - 1; i < retVal.length(); i += n) {
retVal = retVal.substring(0, i) + retVal.substring(i + 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever use of this method

@Override
public String removeNthCharacter(int n, boolean maintainSpacing) {
return null;
String retVal = getString();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to convert to string here to do your manipulations which means code is somewhat coupled and dependent on itself.

throw new IndexOutOfBoundsException("Passed " + n + " as first argument. " + n + " is greater than length of current StringManipulation object: " + retVal.length());
}
if (n == 1) {
return maintainSpacing ? generateSpaces(retVal.length()) : "";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice helper method

@Override
public String restoreString(int[] indices) {
return null;
String currentString = getString();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You had to perform conversion here again to make manipulations

@@ -2,148 +2,177 @@
import org.junit.jupiter.api.BeforeEach;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests look good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants