Skip to content

Commit

Permalink
fix first word in name
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor authored and Victor committed Jan 20, 2023
1 parent 0b19d5b commit dfdd712
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ private String convertSymbol(final Character symbol) {
* @return custom format string
*/
public String convert(final String name, final String lastname) {
if (masLinks == null) {
readFile();
}
readFile();

String lowerLastName = lastname.toLowerCase();
String prepareLastName = lowerLastName.replace(masLinks[0][0], masLinks[0][1]);
Expand All @@ -81,7 +79,7 @@ public String convert(final String name, final String lastname) {

firstSymbol = true;

resultLine.append(convertSymbol(name.charAt(0)));
resultLine.append(convertSymbol(name.charAt(0)).charAt(0));
resultLine.append(convertSymbol(prepareLastName.charAt(0)));

firstSymbol = false;
Expand All @@ -94,7 +92,10 @@ public String convert(final String name, final String lastname) {
return resultLine.toString();
}

private static void readFile() {
private synchronized static void readFile() {
if (masLinks != null) {
return;
}

List<String> list = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ void convertTest() {
assertEquals("GGorgany", tr.convert("Ґ", "Ґорґани"));
assertEquals("DDonetsk", tr.convert("Дмитро", "Донецьк"));
assertEquals("ORivne", tr.convert("Олег", "Рівне"));
assertEquals("YeYenakiieve", tr.convert("Є", "Єнакієве"));
assertEquals("ZhZhytomyr", tr.convert("Жанна", "Житомир"));
assertEquals("ZhZhezheliv", tr.convert("Жежелів", "Жежелів"));
assertEquals("YYenakiieve", tr.convert("Є", "Єнакієве"));
assertEquals("ZZhytomyr", tr.convert("Жанна", "Житомир"));
assertEquals("ZZhezheliv", tr.convert("Жежелів", "Жежелів"));
assertEquals("ZZakarpattia", tr.convert("З", "Закарпаття"));
assertEquals("KKazymyrchuk", tr.convert("К", "Казимирчук"));
assertEquals("MMedvyn", tr.convert("М", "Медвин"));
Expand Down

0 comments on commit dfdd712

Please sign in to comment.