BAEL-2144 remove duplicated anagram validator from old location
This commit is contained in:
parent
61de6251ec
commit
db0caea588
|
@ -1,29 +0,0 @@
|
|||
package com.baeldung.sorting.string.anagram;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AnagramValidator {
|
||||
|
||||
public static boolean isValid(String text, String anagram) {
|
||||
text = prepare(text);
|
||||
anagram = prepare(anagram);
|
||||
|
||||
String sortedText = sort(text);
|
||||
String sortedAnagram = sort(anagram);
|
||||
|
||||
return sortedText.equals(sortedAnagram);
|
||||
}
|
||||
|
||||
private static String sort(String text) {
|
||||
char[] chars = prepare(text).toCharArray();
|
||||
|
||||
Arrays.sort(chars);
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
private static String prepare(String text) {
|
||||
return text.toLowerCase()
|
||||
.trim()
|
||||
.replaceAll("\\s+", "");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue