
io.lsn.java.common.helper.GreekStringHelper Maven / Gradle / Ivy
package io.lsn.java.common.helper;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Pattern;
import static io.lsn.java.common.helper.StringHelper.cleanString;
/**
* @author Patryk Szlagowski
*/
public class GreekStringHelper {
public static final String NO_STREET_ADDRESS = "ΚΑΜΙΑ ΕΠΙΛΟΓΗ";
public static final String ALL_AREAS = "ΟΛΕΣ ΟΙ ΠΕΡΙΟΧΕΣ";
public static final List STREETS_WITH_NO_NAME =
Collections.unmodifiableList(Arrays.asList(NO_STREET_ADDRESS, "ΑΛΛΗ ΟΔΟΣ"));
private static HashMap latin2GreekMap = new HashMap() {
{
put("A", "Α");
put("B", "Β");
put("E", "Ε");
put("Z", "Ζ");
put("H", "Η");
put("I", "Ι");
put("K", "Κ");
put("M", "Μ");
put("N", "Ν");
put("O", "Ο");
put("P", "Ρ");
put("T", "Τ");
put("Y", "Υ");
put("X", "Χ");
}
};
static HashMap latin2GreekExtendedMap = new HashMap() {
{
put("A", "Α");
put("B", "Β");
put("G", "Γ");
put("D", "Δ");
put("E", "Ε");
put("Z", "Ζ");
put("H", "Η");
put("U", "Θ");
put("I", "Ι");
put("K", "Κ");
put("L", "Λ");
put("M", "Μ");
put("N", "Ν");
put("J", "Ξ");
put("O", "Ο");
put("P", "Π");
put("R", "Ρ");
put("S", "Σ");
put("T", "Τ");
put("Y", "Υ");
put("F", "Φ");
put("X", "Χ");
put("C", "Ψ");
put("V", "Ω");
}
};
public static String uppercase(String value) {
String result;
if (value != null) {
result = value.toUpperCase(new Locale("el", "GR"));
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
result = pattern.matcher(result).replaceAll("");
return result;
}
return null;
}
public static BigDecimal aliceBigDecimal(String aliceDecimal) {
String stringValue = cleanString(aliceDecimal);
try {
return BigDecimal.valueOf(Double.valueOf(stringValue));
} catch (Exception e) {
return null;
}
}
public static BigDecimal aliceBigDecimalWtf(String aliceDecimal) {
if (aliceDecimal.contains("-")) {
BigDecimal d = aliceBigDecimal(aliceDecimal.replace("-", ""));
return d.multiply(BigDecimal.valueOf(-1));
}
return aliceBigDecimal(aliceDecimal);
}
/**
* convert alice variant indicator to index
*
* @param aliceVariantString
* @return
*/
public static long aliceVariantIndex(String aliceVariantString) {
return Long.valueOf(aliceVariantString.replace("S", "")).longValue();
}
/**
* format api token
*
* @param sessionId
* @return
*/
public static String getFormattedPBSessionId(String sessionId) {
return String.format("{%s}", sessionId);
}
/**
* replace latin character to greek ones
*
* @param message
* @return
*/
public static String toGreekLetters(String message) {
if (message == null) {
return null;
}
for (Object o : latin2GreekMap.entrySet()) {
HashMap.Entry pair = (HashMap.Entry) o;
message = message.replaceAll(pair.getKey().toString(), pair.getValue().toString());
}
return message;
}
/**
* replace latin character to greek ones (extended charset)
*
* @param message
* @return
*/
public static String toGreekLettersExtended(String message) {
if (message == null) {
return null;
}
for (Object o : latin2GreekExtendedMap.entrySet()) {
HashMap.Entry pair = (HashMap.Entry) o;
message = message.replaceAll(pair.getKey().toString(), pair.getValue().toString());
}
return message;
}
/**
* return true if streetName is on list of "empty" streets (signs that represent situation when the street has no name)
*
* @param streetName street name to be validated
* @return
*/
public static Boolean isStreetWithoutName(String streetName) {
return STREETS_WITH_NO_NAME.stream().anyMatch(streetName::equalsIgnoreCase);
}
/**
* format address
*
* @param postalCode
* @param city
* @param street
* @param houseNumber
*/
public static String formatAddress(String postalCode, String city, String street, String houseNumber) {
String streetAndNumber = StringHelper.notNullString(street).concat(" ").concat(StringHelper.notNullString(houseNumber)).trim();
String postalAndCity;
if (!StringUtils.isEmpty(postalCode) && !StringUtils.isEmpty(city)) {
postalAndCity = StringHelper.notNullString(postalCode).concat(", ").concat(StringHelper.notNullString(city)).trim();
} else {
postalAndCity = StringHelper.notNullString(postalCode).concat(" ").concat(StringHelper.notNullString(city)).trim();
}
if (!StringUtils.isEmpty(postalAndCity) && !StringUtils.isEmpty(streetAndNumber)) {
postalAndCity = ", ".concat(postalAndCity);
}
return streetAndNumber.concat(postalAndCity).trim();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy