Skip to content

Commit

Permalink
return to one convert
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor authored and Victor committed Jan 23, 2023
1 parent 6a7491b commit 39a6c25
Showing 1 changed file with 2 additions and 37 deletions.
39 changes: 2 additions & 37 deletions transliteration/src/main/java/transliteration/Transliteration.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,51 +70,17 @@ private String convertSymbol(final Character symbol) {
* @return custom format string
*/
public String convert(final String name, final String lastname) {
return convert(name, lastname, 1);
}

/**
* Convert name and last name to custom format. <br>
* Last argument need for get custom symbols from name, min 1 element.
*
* @param name name
* @param lastname last name
* @param count count symbols from name
* @return custom format string
*/
public String convert(String name, String lastname, int count) {
readFile();

StringBuilder resultLine = new StringBuilder();

//region create name
String loverName = name.toLowerCase();
String prepareName = loverName.replace(masLinks[0][0], masLinks[0][1]);

firstSymbol = true;

String transLitName = convertSymbol(name.charAt(0));
resultLine.append(convertSymbol(name.charAt(0)).charAt(0));

firstSymbol = false;

if (count <= transLitName.length()) {
resultLine.append(transLitName, 0, count);
} else {
resultLine.append(transLitName);

int n = Math.min(count, prepareName.length());
for (int i = 1; i < n; i++) {
resultLine.append(convertSymbol(prepareName.charAt(i)));
}
}
//endregion

//region create last name
String lowerLastName = lastname.toLowerCase();
String prepareLastName = lowerLastName.replace(masLinks[0][0], masLinks[0][1]);

firstSymbol = true;

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

firstSymbol = false;
Expand All @@ -123,8 +89,7 @@ public String convert(String name, String lastname, int count) {
for (int i = 1; i < n; i++) {
resultLine.append(convertSymbol(prepareLastName.charAt(i)));
}
//endregion


return resultLine.toString();
}

Expand Down

0 comments on commit 39a6c25

Please sign in to comment.