Skip to content

Instantly share code, notes, and snippets.

@ramizdemiurge
Last active July 2, 2018 09:46
Show Gist options
  • Save ramizdemiurge/546416e5c1c9439f174a002f4e5776ee to your computer and use it in GitHub Desktop.
Save ramizdemiurge/546416e5c1c9439f174a002f4e5776ee to your computer and use it in GitHub Desktop.
toLowerCase and toUpperCase methods for Azerbaijanian chars
import java.util.HashMap;
import java.util.Map;
/**
* toLowerCase and toUpperCase methods for
* Azerbaijanian chars
*
* 2 iyul, 2018
*
* * @author ramiz.demiurge
*/
public class AzerbaijanianAlphabetProcessor {
private static final Map<String, String> values;
static {
values = new HashMap<>();
values.put("Ü", "ü");
values.put("Ə", "ə");
values.put("Ö", "ö");
values.put("İ", "i");
values.put("Ğ", "ğ");
values.put("I", "ı");
values.put("Ş", "ş");
values.put("Ç", "ç");
}
public String toLowerCase(String content) {
String words[] = content.split("");
for (int i = 0; i < words.length; i++) {
String temp = values.get(words[i]);
if (temp != null) {
words[i] = temp;
} else {
boolean lower = false;
for (Map.Entry<String, String> entry : values.entrySet()) {
if (words[i].equals(entry.getValue())) {
lower = true;
break;
}
}
if (!lower) {
words[i] = words[i].toLowerCase();
}
}
}
StringBuilder builder = new StringBuilder();
for (String s : words) {
builder.append(s);
}
return builder.toString();
}
public String toUpperCase(String content) {
String words[] = content.split("");
for (int i = 0; i < words.length; i++) {
boolean found = false;
for (Map.Entry<String, String> entry : values.entrySet()) {
if(entry.getValue().equals(words[i])){
words[i] = entry.getKey();
found = true;
break;
}
}
if(found) continue;
if (values.get(words[i]) == null){
words[i] = words[i].toUpperCase();
}
}
StringBuilder builder = new StringBuilder();
for (String s : words) {
builder.append(s);
}
return builder.toString();
}
}
import org.junit.Assert;
import org.junit.Test;
public class AzerbaijanianAlphabetProcessorTest {
@Test
public void toLowerCase() {
AzerbaijanianAlphabetProcessor azerbaijanianAlphabeteProcessor = new AzerbaijanianAlphabetProcessor();
String actual = azerbaijanianAlphabeteProcessor.toLowerCase("MƏHSULUN TƏTBİQ EDİLİB ÜZƏ GƏTİRİLMƏSİ.");
String expected = "məhsulun tətbiq edilib üzə gətirilməsi.";
System.out.println(actual);
Assert.assertEquals(expected,actual);
}
@Test
public void toUpperCase() {
AzerbaijanianAlphabetProcessor azerbaijanianAlphabeteProcessor = new AzerbaijanianAlphabetProcessor();
String actual = azerbaijanianAlphabeteProcessor.toUpperCase("məhsulun tətbiq edilib üzə gətirilməsi.");
String expected = "MƏHSULUN TƏTBİQ EDİLİB ÜZƏ GƏTİRİLMƏSİ.";
System.out.println(actual);
Assert.assertEquals(expected,actual);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment