-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restoring MustUseStringCharAtOrCodePointAt analyzer functionality Deleting unused usesConditional variable Removing tests/hamming/.meta/src/reference/java/Hamming.java and tests/hamming/.meta/tests.toml
- Loading branch information
1 parent
bce48a6
commit 5f7c0b9
Showing
8 changed files
with
63 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
18 changes: 18 additions & 0 deletions
18
src/main/java/analyzer/exercises/hamming/MustUseStringCharAtOrCodePointAt.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package analyzer.exercises.hamming; | ||
|
||
import analyzer.Comment; | ||
|
||
/** | ||
* @see <a href="https://github.com/exercism/website-copy/blob/main/analyzer-comments/java/hamming/must_use_string_char_at_or_code_point_at.md">Markdown Template</a> | ||
*/ | ||
class MustUseStringCharAtOrCodePointAt extends Comment { | ||
@Override | ||
public String getKey() { | ||
return "java.hamming.must_use_string_char_at_or_code_point_at"; | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.ACTIONABLE; | ||
} | ||
} |
This file contains 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
This file contains 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
35 changes: 35 additions & 0 deletions
35
src/test/resources/analyzer/exercises/hamming/MustUseCharAtOrCodePointAt.java.txt
This file contains 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import java.util.stream.IntStream; | ||
|
||
/** Optimal solution, but uses String.toCharArray. */ | ||
class Hamming { | ||
private final int hammingDistance; | ||
|
||
Hamming(String leftStrand, String rightStrand) { | ||
validateStrandsHaveEqualLength(leftStrand, rightStrand); | ||
|
||
char[] left = leftStrand.toCharArray(); | ||
char[] right = rightStrand.toCharArray(); | ||
|
||
hammingDistance = (int) IntStream.range(0, leftStrand.length()) | ||
.filter(index -> left[index] != right[index]) | ||
.count(); | ||
} | ||
|
||
private void validateStrandsHaveEqualLength() { | ||
if (leftStrand.length() == rightStrand.length()) { | ||
return; | ||
} | ||
if (leftStrand.isEmpty()) { | ||
throw new IllegalArgumentException("left strand must not be empty."); | ||
} | ||
if (rightStrand.isEmpty()) { | ||
throw new IllegalArgumentException("right strand must not be empty."); | ||
} | ||
throw new IllegalArgumentException( | ||
"leftStrand and rightStrand must be of equal length."); | ||
} | ||
|
||
int getHammingDistance() { | ||
return hammingDistance; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.