List of usage examples for java.lang Character isLetter
public static boolean isLetter(int codePoint)
From source file:bfile.util.StringUtils.java
/** * <p>Checks if the CharSequence contains only Unicode letters.</p> * * <p>{@code null} will return {@code false}. * An empty CharSequence (length()=0) will return {@code false}.</p> * * <pre>/* w w w . ja v a 2 s. co m*/ * StringUtils.isAlpha(null) = false * StringUtils.isAlpha("") = false * StringUtils.isAlpha(" ") = false * StringUtils.isAlpha("abc") = true * StringUtils.isAlpha("ab2c") = false * StringUtils.isAlpha("ab-c") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if only contains letters, and is non-null * @since 3.0 Changed signature from isAlpha(String) to isAlpha(CharSequence) * @since 3.0 Changed "" to return false and not true */ public static boolean isAlpha(final CharSequence cs) { if (isEmpty(cs)) { return false; } final int sz = cs.length(); for (int i = 0; i < sz; i++) { if (Character.isLetter(cs.charAt(i)) == false) { return false; } } return true; }
From source file:bfile.util.StringUtils.java
/** * <p>Checks if the CharSequence contains only Unicode letters and * space (' ').</p>// ww w . j ava 2 s . c o m * * <p>{@code null} will return {@code false} * An empty CharSequence (length()=0) will return {@code true}.</p> * * <pre> * StringUtils.isAlphaSpace(null) = false * StringUtils.isAlphaSpace("") = true * StringUtils.isAlphaSpace(" ") = true * StringUtils.isAlphaSpace("abc") = true * StringUtils.isAlphaSpace("ab c") = true * StringUtils.isAlphaSpace("ab2c") = false * StringUtils.isAlphaSpace("ab-c") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if only contains letters and space, * and is non-null * @since 3.0 Changed signature from isAlphaSpace(String) to isAlphaSpace(CharSequence) */ public static boolean isAlphaSpace(final CharSequence cs) { if (cs == null) { return false; } final int sz = cs.length(); for (int i = 0; i < sz; i++) { if (Character.isLetter(cs.charAt(i)) == false && cs.charAt(i) != ' ') { return false; } } return true; }
From source file:com.clark.func.Functions.java
/** * <p>/*from w ww . ja v a 2 s .c o m*/ * Creates a random string based on a variety of options, using supplied * source of randomness. * </p> * * <p> * If start and end are both <code>0</code>, start and end are set to * <code>' '</code> and <code>'z'</code>, the ASCII printable characters, * will be used, unless letters and numbers are both <code>false</code>, in * which case, start and end are set to <code>0</code> and * <code>Integer.MAX_VALUE</code>. * * <p> * If set is not <code>null</code>, characters between start and end are * chosen. * </p> * * <p> * This method accepts a user-supplied {@link Random} instance to use as a * source of randomness. By seeding a single {@link Random} instance with a * fixed seed and using it for each call, the same random sequence of * strings can be generated repeatedly and predictably. * </p> * * @param count * the length of random string to create * @param start * the position in set of chars to start at * @param end * the position in set of chars to end before * @param letters * only allow letters? * @param numbers * only allow numbers? * @param chars * the set of chars to choose randoms from. If <code>null</code>, * then it will use the set of all chars. * @param random * a source of randomness. * @return the random string * @throws ArrayIndexOutOfBoundsException * if there are not <code>(end - start) + 1</code> characters in * the set array. * @throws IllegalArgumentException * if <code>count</code> < 0. * @since 2.0 */ public static String random(int count, int start, int end, boolean letters, boolean numbers, char[] chars, Random random) { if (count == 0) { return ""; } else if (count < 0) { throw new IllegalArgumentException("Requested random string length " + count + " is less than 0."); } if ((start == 0) && (end == 0)) { end = 'z' + 1; start = ' '; if (!letters && !numbers) { start = 0; end = Integer.MAX_VALUE; } } char[] buffer = new char[count]; int gap = end - start; while (count-- != 0) { char ch; if (chars == null) { ch = (char) (random.nextInt(gap) + start); } else { ch = chars[random.nextInt(gap) + start]; } if ((letters && Character.isLetter(ch)) || (numbers && Character.isDigit(ch)) || (!letters && !numbers)) { if (ch >= 56320 && ch <= 57343) { if (count == 0) { count++; } else { // low surrogate, insert high surrogate after putting it // in buffer[count] = ch; count--; buffer[count] = (char) (55296 + random.nextInt(128)); } } else if (ch >= 55296 && ch <= 56191) { if (count == 0) { count++; } else { // high surrogate, insert low surrogate before putting // it in buffer[count] = (char) (56320 + random.nextInt(128)); count--; buffer[count] = ch; } } else if (ch >= 56192 && ch <= 56319) { // private high surrogate, no effing clue, so skip it count++; } else { buffer[count] = ch; } } else { count++; } } return new String(buffer); }