Example usage for org.apache.commons.lang StringUtils isAlpha

List of usage examples for org.apache.commons.lang StringUtils isAlpha

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils isAlpha.

Prototype

public static boolean isAlpha(String str) 

Source Link

Document

Checks if the String contains only unicode letters.

Usage

From source file:org.apdplat.superword.tools.JavaCodeAnalyzer.java

/**
 * ????//from   w ww .j a v  a 2  s . co m
 * @param zipFile
 * @param dicPath
 */
public static void toDic(String zipFile, String dicPath) {
    Map<String, AtomicInteger> data = parseZip(zipFile);
    List<String> words = data.entrySet().stream()
            .filter(w -> StringUtils.isAlpha(w.getKey()) && w.getKey().length() < 12)
            .sorted((a, b) -> b.getValue().get() - a.getValue().get())
            .map(e -> e.getValue() + "\t" + e.getKey()).collect(Collectors.toList());
    try {
        Files.write(Paths.get(dicPath), words);
    } catch (IOException e) {
        LOGGER.error("??", e);
    }
}

From source file:org.apdplat.superword.tools.PrefixSuffixOptimizer.java

/**
 * ?????//w  w  w  .  j  a  va 2 s .c  om
 *
 * @param element
 */
public static void replace(Element element) {
    String oldText = element.text();
    StringBuilder newText = new StringBuilder();
    System.out.println("oldText: " + oldText);
    String[] items = oldText.trim().replace(".", ",").split(",");
    for (String item : items) {
        item = item.trim();
        if (!StringUtils.isAlpha(item)) {
            newText.append(item).append(", ");
            continue;
        }
        if (StringUtils.isAllUpperCase(item)) {
            newText.append("<strong><a target=\"_blank\" href=\"http://www.iciba.com/").append(item)
                    .append("\">").append(item).append("</a></strong>").append(", ");
        } else {
            newText.append("<a target=\"_blank\" href=\"http://www.iciba.com/").append(item).append("\">")
                    .append(item).append("</a>").append(", ");
        }
        WORDS.add(item.toLowerCase());
    }
    if (newText.length() > 2) {
        String text = newText.substring(0, newText.length() - 2);
        System.out.println("newText: " + text);
        element.html(text);
    }
}

From source file:org.apdplat.superword.tools.TextAnalyzer.java

/**
 * ??//from   w w w . j  a v  a  2  s .c  om
 * @param textPath
 * @param dicPath
 */
public static void toDic(String textPath, String dicPath) {
    Map<String, AtomicInteger> data = frequency(getFileNames(textPath));
    List<String> words = data.entrySet().stream()
            .filter(w -> StringUtils.isAlpha(w.getKey()) && w.getKey().length() < 12)
            .sorted((a, b) -> b.getValue().get() - a.getValue().get())
            .map(e -> e.getValue() + "\t" + e.getKey()).collect(Collectors.toList());
    try {
        Files.write(Paths.get(dicPath), words);
    } catch (IOException e) {
        LOGGER.error("??", e);
    }
}

From source file:org.medici.bia.common.util.ValidationUtils.java

/**
 * Reject the given field with the given error code, error arguments
 * and default message if the value is empty or not contains alphabetic charactes.
 * <p>An 'empty' value in this context means either <code>null</code>,
 * the empty string "", or consisting wholly of whitespace.
 * <p>The object whose field is being validated does not need to be passed
 * in because the {@link Errors} instance can resolve field values by itself
 * (it will usually hold an internal reference to the target object).
 * @param errors the <code>Errors</code> instance to register errors on
 * @param field the field name to check/*  www .  j a  v  a  2 s. c  om*/
 * @param errorCode the error code, interpretable as message key
 * @param errorArgs the error arguments, for argument binding via MessageFormat
 * (can be <code>null</code>)
 * @param defaultMessage fallback default message
 */
public static void rejectIfEmptyOrNotAlphaCharactes(Errors errors, String field, String errorCode,
        Object[] errorArgs, String defaultMessage) {

    Assert.notNull(errors, "Errors object must not be null");
    Object value = errors.getFieldValue(field);
    if (value == null || !StringUtils.isAlpha(value.toString())) {
        errors.rejectValue(field, errorCode, errorArgs, defaultMessage);
    }
}

From source file:org.medici.bia.common.util.VolumeUtils.java

/**
 * This method check if a string is in volume Format
 * /*from   w w  w  . j a  v a2 s. com*/
 * @param text
 * @return
 */
public static Boolean isVolumeFormat(String text) {
    if (StringUtils.isEmpty(text)) {
        return Boolean.FALSE;
    }

    String trimmedText = text.trim();

    /**We put this control here because often a word for search is not a volume
     * E.g. Michele (it's not a volume)
     * E.g. a  (word with a single letter cannot be consider as volume Letter Extension),
     * 
     * Previously we have two check :
     * if (StringUtils.isAlpha(text) && text.length() > 1)
     * if (StringUtils.isAlpha(trimmedText) && trimmedText.length() == 1)
     **/
    if (StringUtils.isAlpha(trimmedText)) {
        return Boolean.FALSE;
    }

    // E.g. 23
    if (StringUtils.isNumeric(trimmedText)) {
        return Boolean.TRUE;
    }

    // E.g. 23a
    if (StringUtils.isAlphanumeric(trimmedText)) {
        // A correct volumeNumber E.g. 23a
        if (NumberUtils.isNumber(trimmedText.substring(0, trimmedText.length() - 1))) {
            return Boolean.TRUE;
        } else {
            // A correct volumeNumber E.g. 23da, volume Letter must be a single letter 
            return Boolean.FALSE;
        }
    }

    // It 's not a volume format string
    return Boolean.FALSE;
}

From source file:org.medici.bia.service.admin.AdminServiceImpl.java

/**
 * This method will generate the user inital. The format of the returned string is :
 * - First Letter of field First Name;//www . ja v  a 2 s . c om
 * - First or more Letters of field Last Name;
 * 
 * The generation code is based on calculate user initial making a previous
 * search. 
 * If the initial are not present, we return it, otherwise we increment the initial 
 * with another letter get from last name and so on until we find one initial that 
 * is not present on database.
 * 
 * @param user The user  
 * @return A string rapresenting user inital.
 */
private String generateInitials(User user) throws ApplicationThrowable {
    try {
        // We extract name and surname from user object and we clean eventually wrong chars, it's necessary to calculate user initial 
        String name = user.getFirstName().trim().toUpperCase();
        String surname = user.getLastName().trim().toUpperCase();
        if (!StringUtils.isAlpha(name)) {
            name = RegExUtils.trimNonAlphaChars(name);
        }
        if (!StringUtils.isAlpha(surname)) {
            surname = RegExUtils.trimNonAlphaChars(surname);
        }

        String initialLetterOfName = name.substring(0, 1).toUpperCase();

        //In this case we edit a user
        if (getUserDAO().findUser(user.getAccount()) != null)
            return getUserDAO().findUser(user.getAccount()).getInitials();

        // We try to search user with these inital, if we find one, we increment letters in initial  
        for (int i = 1; i < surname.length(); i++) {
            String initialChoiced = initialLetterOfName + surname.substring(i - 1, i);
            User userToSearch = new User();
            userToSearch.setInitials(initialChoiced);
            if (getUserDAO().findUser(userToSearch) == null)
                return initialChoiced;
        }

        // unreachable statement, we always find unused initial, but we need to insert this code beacuse the method must always return a value.
        return null;
    } catch (Throwable th) {
        throw new ApplicationThrowable(th);
    }
}

From source file:org.medici.bia.service.user.UserServiceImpl.java

/**
 * This method will generate the userAccount. The format of the returned string is :
 * - First Letter of field First Name;/*from  w w  w . ja va2 s. c o  m*/
 * - field Last Name cleaned of not unicode letters
 * 
 * @param user The user to 
 * @return A string rapresenting the account.
 */
private String generateAccount(User user) throws ApplicationThrowable {
    try {
        String initialLetterOfName = user.getFirstName().trim().substring(0, 1).toLowerCase();
        String surname = user.getLastName().trim().toLowerCase();
        String account = initialLetterOfName;

        if (!StringUtils.isAlpha(surname)) {
            surname = RegExUtils.trimNonAlphaChars(surname);
        }

        account += surname;

        if (getUserDAO().findUser(account) == null)
            return account;

        for (int i = 1; i < 30; i++) {
            if (getUserDAO().findUser(account + i) == null)
                return account + i;
        }
        return null;
    } catch (Throwable th) {
        throw new ApplicationThrowable(th);
    }
}

From source file:org.medici.bia.service.user.UserServiceImpl.java

/**
 * This method will generate the user inital. The format of the returned string is :
 * - First Letter of field First Name;//w  ww.j av a  2s  .  co  m
 * - First or more Letters of field Last Name;
 * 
 * The generation code is based on calculate user initial making a previous
 * search. 
 * If the initial are not present, we return it, otherwise we increment the initial 
 * with another letter get from last name and so on until we find one initial that 
 * is not present on database.
 * 
 * @param user The user  
 * @return A string rapresenting user inital.
 */
private String generateInitials(User user) throws ApplicationThrowable {
    try {
        // We extract name and surname from user object and we clean eventually wrong chars, it's necessary to calculate user initial 
        String name = user.getFirstName().trim().toUpperCase();
        String surname = user.getLastName().trim().toUpperCase();
        if (!StringUtils.isAlpha(name)) {
            name = RegExUtils.trimNonAlphaChars(name);
        }
        if (!StringUtils.isAlpha(surname)) {
            surname = RegExUtils.trimNonAlphaChars(surname);
        }

        String initialLetterOfName = name.substring(0, 1).toUpperCase();

        // We try to search user with these inital, if we find one, we increment letters in initial  
        for (int i = 1; i < surname.length(); i++) {
            String initialChoiced = initialLetterOfName + surname.substring(i - 1, i);
            User userToSearch = new User();
            userToSearch.setInitials(initialChoiced);
            if (getUserDAO().findUser(userToSearch) == null)
                return initialChoiced;
        }

        //In this case all the letters of the surname are busy
        //We try to insert the first letter of the second name if it is present
        if (name.contains(" ")) {
            String middleName = name.substring(name.indexOf(" "), name.length());
            if (middleName.length() > 1 && middleName.charAt(1) != ' ') {
                User userToSearch = new User();
                String initialChoiced = initialLetterOfName + middleName.charAt(1) + surname.charAt(0);
                userToSearch.setInitials(initialChoiced);
                if (getUserDAO().findUser(userToSearch) == null)
                    return initialChoiced;
            }
        }
        //In this case we add another letter from the surname
        for (int i = 2; i < surname.length(); i++) {
            String initialChoiced = initialLetterOfName + surname.charAt(0) + surname.substring(i - 1, i);
            User userToSearch = new User();
            userToSearch.setInitials(initialChoiced);
            if (getUserDAO().findUser(userToSearch) == null)
                return initialChoiced;
        }

        //In this case we add another letter from the surname
        for (int i = 3; i < surname.length(); i++) {
            String initialChoiced = initialLetterOfName + surname.charAt(0) + surname.charAt(1)
                    + surname.substring(i - 1, i);
            User userToSearch = new User();
            userToSearch.setInitials(initialChoiced);
            if (getUserDAO().findUser(userToSearch) == null)
                return initialChoiced;
        }

        //In this case we add another letter from the surname
        for (int i = 4; i < surname.length(); i++) {
            String initialChoiced = initialLetterOfName + surname.charAt(0) + surname.charAt(1)
                    + surname.charAt(2) + surname.substring(i - 1, i);
            User userToSearch = new User();
            userToSearch.setInitials(initialChoiced);
            if (getUserDAO().findUser(userToSearch) == null)
                return initialChoiced;
        }

        // unreachable statement, we always find unused initial, but we need to insert this code beacuse the method must always return a value.
        return null;
    } catch (Throwable th) {
        throw new ApplicationThrowable(th);
    }
}

From source file:org.medici.bia.service.user.UserServiceImpl.java

/**
 * {@inheritDoc}//from   ww w  .j ava 2  s  .c o m
 */
@Override
public Integer ratePassword(String password) {
    if ((password == null) || password.equals(""))
        return 0;

    if (password.length() < 8)
        return 1;

    if (StringUtils.isAlpha(password))
        return 2;

    if (StringUtils.isAlphanumeric(password))
        return 3;

    if (StringUtils.isAsciiPrintable(password))
        return 4;

    return 0;
}

From source file:org.oscarehr.integration.mchcv.SimpleHCValidator.java

private boolean isValid(String hcNumber, String versionCode) {
    if (hcNumber == null) {
        return false;
    }//  ww w  .j  a v  a2  s . c om
    if (hcNumber.length() != 10) {
        return false;
    }
    if (!StringUtils.isNumeric(hcNumber)) {
        return false;
    }
    if (versionCode != null) {
        if (versionCode.length() > 2 || !StringUtils.isAlpha(versionCode)) {
            return false;
        }
    }
    return true;
}