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

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

Introduction

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

Prototype

public static boolean isAlpha(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode letters.

null will return false .

Usage

From source file:by.lang.StringUtilsTest.java

public static void main(String[] args) {
    System.out.println("?,....");
    System.out.println(StringUtils.abbreviate("The quick brown fox jumps over the lazy dog.", 10));

    System.out.println(".");
    System.out.println(StringUtils.chomp("1,2,3,", ","));

    System.out.println("???.");
    System.out.println(StringUtils.contains("defg", "ef"));
    System.out.println(StringUtils.contains("ef", "defg"));

    System.out.println("??nulltoString().");
    System.out.println(StringUtils.defaultString(null, "defaultIfEmpty"));
    System.out.println(".");
    System.out.println(StringUtils.deleteWhitespace("aa  bb  cc"));

    System.out.println("??.");
    System.out.println(StringUtils.isAlpha("ab"));
    System.out.println(StringUtils.isAlphanumeric("12"));
    System.out.println(StringUtils.isBlank(""));
    System.out.println(StringUtils.isNumeric("123"));

    System.out.println("?Null  \"\"");
    System.out.println(StringUtils.isEmpty(null));
    System.out.println(StringUtils.isNotEmpty(null));
    System.out.println("?null  \"\" ");
    System.out.println(StringUtils.isBlank("  "));
    System.out.println(StringUtils.isNotBlank(null));
    System.out.println(".Nullnull");
    System.out.println(StringUtils.trim(null));
    System.out.println("Null\"\" ?Null");
    System.out.println(StringUtils.trimToNull(""));
    // NULL  "" ?""
    // System.out.println(StringUtils.trimToEmpty(null));
    // ??//from  w ww .java2  s.  c o m
    // System.out.println(StringUtils.strip("  \t"));
    // ?""null?Null
    // System.out.println(StringUtils.stripToNull(" \t"));
    // ?""null?""
    // System.out.println(StringUtils.stripToEmpty(null));
    // ""Null ? ""
    // System.out.println(StringUtils.defaultString(null));
    // Null ?(?)
    // System.out.println(StringUtils.defaultString("", "df"));
    // null""?(?)
    // System.out.println(StringUtils.defaultIfEmpty(null, "sos"));
    // .~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?null(?2?)
    // System.out.println(StringUtils.strip("fsfsdf", "f"));
    // ?null???(????)
    // System.out.println(StringUtils.stripStart("ddsuuu ", "d"));
    // ?null???(????)
    // System.out.println(StringUtils.stripEnd("dabads", "das"));
    // 
    // ArrayToList(StringUtils.stripAll(new String[]{" ? ", "  ",
    // " "}));
    // ?null.?(??)
    // ArrayToList(StringUtils.stripAll(new String[]{" ? ", " ", ""},
    // ""));
    // ,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // 2?,Null
    // System.out.println(StringUtils.equals(null, null));
    // ??
    // System.out.println(StringUtils.equalsIgnoreCase("abc", "ABc"));
    // ????~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?null""-1
    // System.out.println(StringUtils.indexOf(null, "a"));
    // ?(?)2k
    // System.out.println(StringUtils.indexOf("akfekcd?", "k", 2));
    // ???
    // System.out.println(StringUtils.ordinalIndexOf("akfekcd?", "k", 2));
    // ,??
    // System.out.println(StringUtils.indexOfIgnoreCase("adfs", "D"));
    // ?(?),??
    // System.out.println(StringUtils.indexOfIgnoreCase("adfs", "a", 3));
    // ??
    // System.out.println(StringUtils.lastIndexOf("adfas", "a"));
    // ?,2
    // System.out.println(StringUtils.lastIndexOf("dabasdafs", "a", 3));
    // ,-1
    // System.out.println(StringUtils.lastOrdinalIndexOf("yksdfdht", "f",
    // 2));
    // ????
    // System.out.println(StringUtils.lastIndexOfIgnoreCase("sdffet", "E"));
    // ,1
    // System.out.println(StringUtils.lastIndexOfIgnoreCase("efefrfs", "F"
    // , 2));
    // ?boolean,null?
    // System.out.println(StringUtils.contains("sdf", "dg"));
    // ?boolean,null?,??
    // System.out.println(StringUtils.containsIgnoreCase("sdf", "D"));
    // ??,boolean
    // System.out.println(StringUtils.containsWhitespace(" d"));
    // ???
    // System.out.println(StringUtils.indexOfAny("absfekf", new
    // String[]{"f", "b"}));
    // (?)
    // System.out.println(StringUtils.indexOfAny("afefes", "e"));
    // ??boolean
    // System.out.println(StringUtils.containsAny("asfsd", new char[]{'k',
    // 'e', 's'}));
    // ?lastIndexOf???boolean
    // System.out.println(StringUtils.containsAny("f", ""));
    // 
    // System.out.println(StringUtils.indexOfAnyBut("seefaff", "af"));
    // ?
    // System.out.println(StringUtils.containsOnly("??", "?"));
    // ?
    // System.out.println(StringUtils.containsOnly("?", new char[]{'',
    // '?'}));
    // ??
    // System.out.println(StringUtils.containsNone("??", ""));
    // ??
    // System.out.println(StringUtils.containsNone("?", new char[]{'',
    // ''}));
    // ????4
    // System.out.println(StringUtils.lastIndexOfAny("", new
    // String[]{"", ""}));
    // ?indexOfAny?? (?)
    // System.out.println(StringUtils.countMatches("", ""));
    // ?CharSequence??Unicode?falseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAlpha("2"));
    // ???UnicodeCharSequence?''CharSequence?=
    // 0true
    // System.out.println(StringUtils.isAlphaSpace("NBA "));
    // ???UnicodeCharSequence?falseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAlphanumeric("NBA"));
    // Unicode
    // CharSequence???''falseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAlphanumericSpace("NBA"));
    // ???ASCII?CharSequencefalseCharSequence=
    // 0true
    // System.out.println(StringUtils.isAsciiPrintable("NBA"));
    // ???
    // System.out.println(StringUtils.isNumeric("NBA"));
    // ???
    // System.out.println(StringUtils.isNumericSpace("33 545"));
    // ??""
    // System.out.println(StringUtils.isWhitespace(" "));
    // ??
    // System.out.println(StringUtils.isAllLowerCase("kjk33"));
    // ?
    // System.out.println(StringUtils.isAllUpperCase("KJKJ"));
    // ?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?2?:
    // System.out.println(StringUtils.difference("", ""));
    // 2
    // System.out.println(StringUtils.indexOfDifference("ww.taobao",
    // "www.taobao.com"));
    // ?
    // System.out.println(StringUtils.indexOfDifference(new String[]
    // {"", "", ""}));
    // ???
    // System.out.println(StringUtils.getCommonPrefix(new String[] {"",
    // "", ""}));
    // ??????
    // System.out.println(StringUtils.getLevenshteinDistance("?",
    // ""));
    // ???
    // System.out.println(StringUtils.startsWith("", ""));
    // ?????
    // System.out.println(StringUtils.startsWithIgnoreCase("",
    // ""));
    // ???
    // System.out.println(StringUtils.startsWithAny("abef", new
    // String[]{"ge", "af", "ab"}));
    // ??
    // System.out.println(StringUtils.endsWith("abcdef", "def"));
    // ????
    // System.out.println(StringUtils.endsWithIgnoreCase("abcdef", "Def"));
    // ?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ??nullnull.""""
    // System.out.println(StringUtils.substring("", 2));
    // ?
    // System.out.println(StringUtils.substring("", 2, 4));
    // ?
    // System.out.println(StringUtils.left("", 3));
    // ??
    // System.out.println(StringUtils.right("", 3));
    // ???
    // System.out.println(StringUtils.mid("", 3, 2));
    // ??
    // System.out.println(StringUtils.substringBefore("", ""));
    // ?????
    // System.out.println(StringUtils.substringAfter("", ""));
    // ??.
    // System.out.println(StringUtils.substringBeforeLast("", ""));
    // ?????
    // System.out.println(StringUtils.substringAfterLast("", ""));
    // ???null:2010?
    // System.out.println(StringUtils.substringBetween("??2010?????",
    // "??"));
    // ???
    // ArrayToList(StringUtils.substringsBetween("[a][b][c]", "[", "]"));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?nullnull
    // ArrayToList(StringUtils.split("?  "));
    // ?
    // ArrayToList(StringUtils.split("? ,,", ","));
    // ???0
    // ArrayToList(StringUtils.split("? ", "", 2));
    // ???,?
    // ArrayToList(StringUtils.splitByWholeSeparator("ab-!-cd-!-ef",
    // "-!-"));
    // ???,???
    // ArrayToList(StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-",
    // 2));
    // " "?,?null
    // ArrayToList(StringUtils.splitByWholeSeparatorPreserveAllTokens(" ab
    // de fg ",
    // null));
    // ?," "??
    // ArrayToList(StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de
    // fg",
    // null, 3));
    // ???,
    // ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg "));
    // ???,?
    // ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg ",
    // null));
    // ???,???
    // ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg ", null,
    // 2));
    // ??
    // ArrayToList(StringUtils.splitByCharacterType("AEkjKr i39:"));
    // 
    // ArrayToList(StringUtils.splitByCharacterTypeCamelCase("ASFSRules234"));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ??
    // System.out.println(StringUtils.concat(getArrayData()));
    // ?.?null
    // System.out.println(StringUtils.concatWith(",", getArrayData()));
    // ?
    // System.out.println(StringUtils.join(getArrayData()));
    // ?
    // System.out.println(StringUtils.join(getArrayData(), ":"));
    // (?)?(?,??)
    // System.out.println(StringUtils.join(getArrayData(), ":", 1, 3));
    // ?.?
    // System.out.println(StringUtils.join(getListData(), ":"));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // 
    // System.out.println(StringUtils.deleteWhitespace(" s   4j"));
    // ?
    // System.out.println(StringUtils.removeStart("www.baidu.com", "www."));
    // ?,??
    // System.out.println(StringUtils.removeStartIgnoreCase("www.baidu.com",
    // "WWW"));
    // ???
    // System.out.println(StringUtils.removeEnd("www.baidu.com", ".com"));
    // ?????
    // System.out.println(StringUtils.removeEndIgnoreCase("www.baidu.com",
    // ".COM"));
    // ?
    // System.out.println(StringUtils.remove("www.baidu.com/baidu", "bai"));
    // "\n", "\r",  "\r\n".
    // System.out.println(StringUtils.chomp("abcrabc\r"));
    // ?
    // System.out.println(StringUtils.chomp("baidu.com", "com"));
    // ?."\n", "\r",  "\r\n"
    // System.out.println(StringUtils.chop("wwe.baidu"));
    // ?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ???
    // System.out.println(StringUtils.replaceOnce("www.baidu.com/baidu",
    // "baidu", "hao123"));
    // ?
    // System.out.println(StringUtils.replace("www.baidu.com/baidu",
    // "baidu", "hao123"));
    // ????
    // System.out.println(StringUtils.replace("www.baidu.com/baidu",
    // "baidu", "hao123", 1));
    // ?????:baidu?taobaocom?net
    // System.out.println(StringUtils.replaceEach("www.baidu.com/baidu", new
    // String[]{"baidu", "com"}, new String[]{"taobao", "net"}));
    // ????
    // System.out.println(StringUtils.replaceEachRepeatedly("www.baidu.com/baidu",
    // new String[]{"baidu", "com"}, new String[]{"taobao", "net"}));
    // ????.(????)
    // System.out.println(StringUtils.replaceChars("www.baidu.com", "bdm",
    // "qo"));
    // ?(?)?(?)
    // System.out.println(StringUtils.overlay("www.baidu.com", "hao123", 4,
    // 9));
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ????
    // System.out.println(StringUtils.repeat("ba", 3));
    // ??????
    // System.out.println(StringUtils.repeat("ab", "ou", 3));
    // ??(???)
    // System.out.println(StringUtils.rightPad("?", 4));
    // ????(?)
    // System.out.println(StringUtils.rightPad("?", 4, "?"));
    // ???
    // System.out.println(StringUtils.leftPad("?", 4));
    // ??????(?)
    // System.out.println(StringUtils.leftPad("?", 4, ""));
    // ?????
    // System.out.println(StringUtils.center("?", 3));
    // ??????
    // System.out.println(StringUtils.center("?", 5, "?"));
    // ??(?),??(??+=?)
    // System.out.println(StringUtils.abbreviate("?", 5));
    // 2: ...ijklmno
    // System.out.println(StringUtils.abbreviate("abcdefghijklmno", 12,
    // 10));
    // ???.: ab.f
    // System.out.println(StringUtils.abbreviateMiddle("abcdef", ".", 4));
    // ?,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ?.
    // System.out.println(StringUtils.capitalize("Ddf"));
    // ?.
    // System.out.println(StringUtils.uncapitalize("DTf"));
    // ????????
    // System.out.println(StringUtils.swapCase("I am Jiang, Hello"));
    // ?
    // System.out.println(StringUtils.reverse(""));
    // ?(?)??
    // System.out.println(StringUtils.reverseDelimited("::", ':'));
    // isEmpty
    System.out.println(StringUtils.isEmpty(null)); // true
    System.out.println(StringUtils.isEmpty("")); // true
    System.out.println(StringUtils.isEmpty(" ")); // false
    System.out.println(StringUtils.isEmpty("bob")); // false
    System.out.println(StringUtils.isEmpty("  bob  ")); // false

    // isBlank
    System.out.println(StringUtils.isBlank(null)); // true
    System.out.println(StringUtils.isBlank("")); // true
    System.out.println(StringUtils.isBlank(" ")); // true
    System.out.println(StringUtils.isBlank("bob")); // false
    System.out.println(StringUtils.isBlank("  bob  ")); // false

    // trim
    System.out.println(StringUtils.trim(null)); // null
    System.out.println(StringUtils.trim("")); // ""
    System.out.println(StringUtils.trim("     ")); // ""
    System.out.println(StringUtils.trim("abc")); // "abc"
    System.out.println(StringUtils.trim("    abc")); // "abc"
    System.out.println(StringUtils.trim("    abc  ")); // "abc"
    System.out.println(StringUtils.trim("    ab c  ")); // "ab c"

    // strip
    System.out.println(StringUtils.strip(null)); // null
    System.out.println(StringUtils.strip("")); // ""
    System.out.println(StringUtils.strip("   ")); // ""
    System.out.println(StringUtils.strip("abc")); // "abc"
    System.out.println(StringUtils.strip("  abc")); // "abc"
    System.out.println(StringUtils.strip("abc  ")); // "abc"
    System.out.println(StringUtils.strip(" abc ")); // "abc"
    System.out.println(StringUtils.strip(" ab c ")); // "ab c"
    System.out.println(StringUtils.strip("  abcyx", "xyz")); // " abc"
    System.out.println(StringUtils.stripStart("yxabcxyz  ", "xyz")); // "abcxyz
    // "
    System.out.println(StringUtils.stripEnd("  xyzabcyx", "xyz")); // "
    // xyzabc"
    // ?
    String str1 = "aaa bbb ccc";
    String[] dim1 = StringUtils.split(str1); // => ["aaa", "bbb", "ccc"]

    System.out.println(dim1.length);// 3
    System.out.println(dim1[0]);// "aaa"
    System.out.println(dim1[1]);// "bbb"
    System.out.println(dim1[2]);// "ccc"

    // 
    String str2 = "aaa,bbb,ccc";
    String[] dim2 = StringUtils.split(str2, ","); // => ["aaa", "bbb",
    // "ccc"]

    System.out.println(dim2.length);// 3
    System.out.println(dim2[0]);// "aaa"
    System.out.println(dim2[1]);// "bbb"
    System.out.println(dim2[2]);// "ccc"

    // 
    String str3 = "aaa,,bbb";
    String[] dim3 = StringUtils.split(str3, ","); // => ["aaa", "bbb"]

    System.out.println(dim3.length);// 2
    System.out.println(dim3[0]);// "aaa"
    System.out.println(dim3[1]);// "bbb"

    // ?
    String str4 = "aaa,,bbb";
    String[] dim4 = StringUtils.splitPreserveAllTokens(str4, ","); // =>
    // ["aaa",
    // "",
    // "bbb"]

    System.out.println(dim4.length);// 3
    System.out.println(dim4[0]);// "aaa"
    System.out.println(dim4[1]);// ""
    System.out.println(dim4[2]);// "bbb"

    // ??
    String str5 = "aaa,bbb,ccc";
    String[] dim5 = StringUtils.split(str5, ",", 2); // => ["aaa",
    // "bbb,ccc"]

    System.out.println(dim5.length);// 2
    System.out.println(dim5[0]);// "aaa"
    System.out.println(dim5[1]);// "bbb,ccc"

    // 
    String[] array = { "aaa", "bbb", "ccc" };
    String result1 = StringUtils.join(array, ",");

    System.out.println(result1);// "aaa,bbb,ccc"

    // ?
    List<String> list = new ArrayList<String>();
    list.add("aaa");
    list.add("bbb");
    list.add("ccc");
    String result2 = StringUtils.join(list, ",");
    System.out.println(result2);// "aaa,bbb,ccc"

}

From source file:net.link.eu.vat.client.util.VATUtil.java

/**
 * Tries to guess the country from the given VAT number.
 * Defaults to the given country code when this methods cannot guess it.
 *
 * @param vatNumber the number./*  w w  w.  jav  a2  s. c  om*/
 * @param defaultCountry the default country.
 *
 * @return the countrycode if found, or the default one.
 */
@NotNull
public static CountryCode guessCountryFromNumber(@NotNull String vatNumber,
        @NotNull CountryCode defaultCountry) {

    if (StringUtils.isBlank(vatNumber) || vatNumber.length() <= 2) {

        return defaultCountry;
    }

    try {

        String code = vatNumber.substring(0, 2).toUpperCase();

        if (StringUtils.isAlpha(code)) {

            return CountryCode.valueOf(code); //throws error when not found
        } else {

            return defaultCountry;
        }
    } catch (Exception e) {

        return defaultCountry;
    }
}

From source file:com.qq.tars.validate.SetAreaValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    return StringUtils.isNotBlank(value) && StringUtils.isAlpha(value) && StringUtils.isAllLowerCase(value);
}

From source file:com.qq.tars.validate.ApplicationValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    return StringUtils.isNotBlank(value) && StringUtils.isAlpha(value);
}

From source file:com.gammalabs.wifianalyzer.wifi.band.Country.java

Country() {
    countries = new TreeMap<>();
    for (Locale locale : Locale.getAvailableLocales()) {
        String countryCode = locale.getCountry();
        if (StringUtils.isNotEmpty(countryCode) && StringUtils.isAlpha(countryCode)
                && countryCode.length() == 2) {
            countries.put(StringUtils.capitalize(countryCode), locale);
        }/*ww w .  j a  v a  2s  .  c o m*/
    }
}

From source file:com.github.britter.beanvalidators.strings.AlphabeticConstraintValidator.java

@Override
public boolean isValid(final String value, final ConstraintValidatorContext context) {
    // Don't validate null, empty and blank strings, since these are validated by @NotNull, @NotEmpty and @NotBlank
    return StringUtils.isBlank(value) || allowSpaces ? StringUtils.isAlphaSpace(value)
            : StringUtils.isAlpha(value);
}

From source file:com.ijuru.kwibuka.WordListWordifier.java

/**
 * Creates a wordifier from a word list//  w  w  w  .ja  v  a  2 s .c  o  m
 * @param reader the reader for the word list
 * @throws IOException if reader couldn't be read
 */
public static WordListWordifier fromWordlist(Locale locale, Reader reader) throws IOException {
    WordListWordifier wordifier = new WordListWordifier(locale);
    BufferedReader buffered = new BufferedReader(reader);

    String line;
    while ((line = buffered.readLine()) != null) {
        String word = line.toLowerCase();

        if (word.length() == 0 || !StringUtils.isAlpha(word)) {
            continue;
        }
        wordifier.addWord(word);
    }

    buffered.close();

    return wordifier;
}

From source file:com.look.ChangeAccountServlet.java

/**
 * Processes post request for changing user account data
 * @param request//from w  ww  .j  av a2s  .c om
 * @param response
 * @throws IOException
 * @throws ServletException 
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String newFirstName = request.getParameter("firstName");
    String newLastName = request.getParameter("lastName");

    if (!StringUtils.isAlpha(newFirstName)) {
        request.setAttribute("message", "First name cannot contain numbers or special characters");
        request.getRequestDispatcher("/account.jsp").forward(request, response);
    } else if (!StringUtils.isAlpha(newLastName)) {
        request.setAttribute("message", "Last name cannot contain numbers or special characters");
        request.getRequestDispatcher("/account.jsp").forward(request, response);
    }

    String username = request.getSession().getAttribute("user").toString();
    String oldFirstName = DatabaseUserUtils.getFirstNameFromUsername(username);
    String oldLastName = DatabaseUserUtils.getLastNameFromUsername(username);

    if (newFirstName.equals(oldFirstName) || newLastName.equals(oldLastName)) {
        response.sendRedirect("account.jsp");
    }

    //change the name
    Connection conn;
    try {
        conn = LookDatabaseUtils.getNewConnection();
        PreparedStatement updateStatement = conn
                .prepareStatement("UPDATE users " + "SET first_name=?, " + "last_name=? " + "WHERE username=?");
        updateStatement.setString(1, newFirstName);
        updateStatement.setString(2, newLastName);
        updateStatement.setString(3, username);
        updateStatement.executeUpdate();
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(ChangeAccountServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.autentia.bcbp.items.Item.java

public String getEncoded() {
    if (padding == PaddingType.Number && StringUtils.isBlank(original)) {
        return StringUtils.leftPad("", size).substring(0, size);
    }/* w ww  .  j a v  a  2 s .  c o m*/

    if (padding == PaddingType.Number) {
        return StringUtils.leftPad(original, size, "0").substring(0, size);
    }

    if (padding == PaddingType.NumberFollowedByAlpha && StringUtils.isBlank(original))
        return StringUtils.leftPad(original, size - 1, "0").substring(0, size - 1) + " ";

    if (padding == PaddingType.NumberFollowedByAlpha) {
        int lastPosition = original.length() - 1;
        if (StringUtils.isAlpha(original.substring(lastPosition))) {
            String number = original.substring(0, lastPosition);
            return StringUtils.leftPad(number, size - 1, "0").substring(0, size - 1)
                    + original.substring(lastPosition);
        } else {
            return StringUtils.leftPad(original, size - 1, "0").substring(0, size - 1) + " ";
        }
    }
    if (padding == PaddingType.String) {
        return StringUtils.rightPad(original, size).substring(0, size);
    }

    return "";
}

From source file:com.nokia.ci.integration.sqlImport.SqlSplitter.java

/**
 * Check if the given sql line contains a delimiter representing the end of the command.
 * Please note that we do <em>not</em> fully parse the SQL,
 * so if we get a malformed statement, we cannot detect it.
 *
 * @param line          to parse/* www. j  a v  a  2 s. c  om*/
 * @param delimiter     which should be used to split SQL commands
 * @param overflowValue 0=none, {@link com.nokia.ci.integration.sqlImport.SqlSplitter#OVERFLOW_COMMENT},
 *                      {@link com.nokia.ci.integration.sqlImport.SqlSplitter#OVERFLOW_SINGLE_QUOTE} or
 *                      {@link com.nokia.ci.integration.sqlImport.SqlSplitter#OVERFLOW_DOUBLE_QUOTE}
 * @return position after the end character if the given line contains the end of a SQL script,
 *         {@link com.nokia.ci.integration.sqlImport.SqlSplitter#NO_END} if it doesn't contain an end char. {@link com.nokia.ci.integration.sqlImport.SqlSplitter#OVERFLOW_SINGLE_QUOTE}
 *         will be returned if a single quote didn't get closed, {@link com.nokia.ci.integration.sqlImport.SqlSplitter#OVERFLOW_DOUBLE_QUOTE} likewise
 *         for not closed double quotes.
 */
public static int containsSqlEnd(String line, String delimiter, final int overflowValue) {
    int ret = overflowValue >= 0 ? NO_END : overflowValue;

    // / * * / comments
    boolean isComment = (overflowValue == OVERFLOW_COMMENT);

    String quoteChar = null;
    if (overflowValue == OVERFLOW_SINGLE_QUOTE) {
        quoteChar = "'";
    } else if (overflowValue == OVERFLOW_DOUBLE_QUOTE) {
        quoteChar = "\"";
    }

    boolean isAlphaDelimiter = StringUtils.isAlpha(delimiter);

    if (line == null || line.length() == 0) {
        return ret;
    }

    int pos = 0;
    int maxpos = line.length() - 1;

    char c1;
    char c2 = line.charAt(0);
    statement: do {
        if (isComment) {
            do {
                // keep c2 in line
                if (pos < maxpos) {
                    c2 = line.charAt(pos + 1);
                }

                if (startsWith(line, '*', pos) && startsWith(line, '/', pos + 1)) {
                    ret = NO_END;
                    isComment = false;

                    continue statement;
                }
            } while (pos++ < maxpos);

            //reached EOL
            break statement;
        }

        // if in quote-mode, search for end quote, respecting escaped characters
        if (quoteChar != null) {
            String doubleQuote = quoteChar + quoteChar;
            do {
                // keep c2 in line
                if (pos < maxpos) {
                    c2 = line.charAt(pos + 1);
                }

                if (startsWith(line, "\\", pos) || startsWith(line, doubleQuote, pos)) {
                    //skip next character, but stay in quote-mode
                    pos++;
                } else if (startsWith(line, quoteChar, pos)) {
                    ret = NO_END;
                    quoteChar = null;

                    continue statement;
                }
            } while (pos++ < maxpos);

            // reach EOL
            break statement;
        }

        // use the nextchar from the previous iteration
        c1 = c2;
        if (pos < maxpos) {
            // and set the following char
            c2 = line.charAt(pos + 1);
        } else {
            // or reset to blank if the line has ended
            c2 = ' ';
        }

        // verify if current char indicates start  of new quoted block 
        if (c1 == '\'' || c1 == '"') {
            quoteChar = String.valueOf(c1);
            ret = quoteChar.equals("'") ? OVERFLOW_SINGLE_QUOTE : OVERFLOW_DOUBLE_QUOTE;
            continue statement;
        }

        // parse for a / * start of comment
        if (c1 == '/' && c2 == '*') {
            isComment = true;
            pos++;
            ret = OVERFLOW_COMMENT;
            continue statement;
        }

        if (c1 == '-' && c2 == '-') {
            return ret;
        }

        if (startsWith(line, delimiter, pos)) {
            if (isAlphaDelimiter) {
                // check if delimiter is at start or end of line, surrounded
                // by non-alpha character
                if ((pos == 0 || !isAlpha(line.charAt(pos - 1))) && (line.length() == pos + delimiter.length()
                        || !isAlpha(line.charAt(pos + delimiter.length())))) {
                    return pos + delimiter.length();
                }
            } else {
                return pos + delimiter.length();
            }
        }

    } while (maxpos > pos++);

    return ret;
}