BAEL-2144 move code to different module

This commit is contained in:
Denis 2018-08-30 21:58:38 +02:00
parent b2644c5cfc
commit 61de6251ec
3 changed files with 32 additions and 3 deletions

View File

@ -0,0 +1,29 @@
package com.baeldung.string.sorting;
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+", "");
}
}

View File

@ -1,4 +1,4 @@
package org.baeldung.java.sorting.string;
package com.baeldung.string.sorting;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -6,7 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import org.junit.jupiter.api.Test;
import com.baeldung.sorting.string.anagram.AnagramValidator;
import com.baeldung.string.sorting.AnagramValidator;
class AnagramValidatorUnitTest {

View File

@ -1,4 +1,4 @@
package org.baeldung.java.sorting.string;
package com.baeldung.string.sorting;
import java.util.Arrays;