List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:NonNumericDocument.java
@Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (str == null) { return;/* w w w . ja v a 2 s. c o m*/ } char[] arr = str.toCharArray(); for (int i = 0; i < arr.length; i++) { if (Character.isDigit(arr[i]) || !Character.isLetter(arr[i])) { return; } } super.insertString(offs, new String(str), a); }
From source file:StringUtils.java
private static int getCharKind(int c) { if (c == -1) { return EOI; }// w w w .j a v a 2s. c o m char ch = (char) c; if (Character.isLowerCase(ch)) return LOWER; else if (Character.isUpperCase(ch)) return UPPER; else if (Character.isDigit(ch)) return DIGIT; else return OTHER; }
From source file:Main.java
/** * Look at the peer ID and just grab as many readable characters to form the version * substring as possible./*from w w w. ja va 2 s.com*/ */ public static String extractReadableVersionSubstringFromPeerID(String peer_id) { for (int i = 0; i < peer_id.length(); i++) { char c = peer_id.charAt(i); // This is based on All Peers peer ID at the time of writing, e.g: // AP0.70rc30->>... if (Character.isLetter(c)) continue; if (Character.isDigit(c)) continue; if (c == '.') continue; // Must be delimiter character. return peer_id.substring(0, i); } return peer_id; }
From source file:Main.java
public static double getJavaVersion() { if (javaVersion == null) { try {// ww w .j av a2s .co m String ver = System.getProperties().getProperty("java.version"); String version = ""; boolean firstPoint = true; for (int i = 0; i < ver.length(); i++) { if (ver.charAt(i) == '.') { if (firstPoint) { version += ver.charAt(i); } firstPoint = false; } else if (Character.isDigit(ver.charAt(i))) { version += ver.charAt(i); } } javaVersion = new Double(version); } catch (Exception ex) { javaVersion = 1.3; } } return javaVersion; }
From source file:Main.java
/** * Convert a packed LCCN String to MARC display format. * @param packedLCCN an LCCN String in packed storage format (e.g. 'n 2001050268'). * @return an LCCN String in MARC display format (e.g. 'n2001-50268'). */// w ww .j a v a 2 s .co m public static String toLCCNDisplay(String packedLCCN) { StringBuffer sb = new StringBuffer(); if (Character.isDigit(packedLCCN.charAt(2))) { sb.append(packedLCCN.substring(0, 2).trim()); sb.append(packedLCCN.substring(2, 6)); sb.append("-"); int i = Integer.parseInt(packedLCCN.substring(6).trim()); sb.append(Integer.toString(i)); } else { sb.append(packedLCCN.substring(0, 3).trim()); sb.append(packedLCCN.substring(3, 5)); sb.append("-"); int i = Integer.parseInt(packedLCCN.substring(5).trim()); sb.append(Integer.toString(i)); } return sb.toString(); }
From source file:com.docd.purefm.commandline.CommandDu.java
public static long du_s(@NonNull final GenericFile file) { final List<String> result = CommandLine.executeForResult(new CommandDu(file)); if (result == null || result.isEmpty()) { return 0L; }//from w w w.ja v a2 s . c o m final String res = result.get(0); final int resLength = res.length(); final StringBuilder lengthString = new StringBuilder(resLength); for (int i = 0; i < resLength; i++) { final char character = res.charAt(i); if (Character.isDigit(character)) { lengthString.append(character); } else { break; } } try { return Long.parseLong(lengthString.toString()) * FileUtils.ONE_KB; } catch (NumberFormatException e) { return 0L; } }
From source file:StringUtils.java
/** * Returns true, if the argument contains a number, otherwise false. * In a quick test this is roughly the same speed as Integer.parseInt() * if the argument is a number, and roughly ten times the speed, if * the argument is NOT a number./* www. j a va 2 s. c o m*/ * * @since 2.4 * @param s String to check * @return True, if s represents a number. False otherwise. */ public static boolean isNumber(String s) { if (s == null) return false; if (s.length() > 1 && s.charAt(0) == '-') s = s.substring(1); for (int i = 0; i < s.length(); i++) { if (!Character.isDigit(s.charAt(i))) return false; } return true; }
From source file:Main.java
/** * Checks the password against a set of rules to determine whether it is * considered weak. The rules are:/* w w w . j a v a 2 s . c om*/ * </p><p> * <ul> * <li>It is at least <code>MIN_PASSWORD_LEN</code> characters long. * <li>At least one lowercase character. * <li>At least one uppercase character. * <li>At least one digit or symbol character. * </ul> * * @param password the password to check. * * @return <code>true</code> if the password is considered to be weak, * <code>false</code> otherwise. */ public static boolean isWeakPassword(String password) { boolean hasUC = false; boolean hasLC = false; boolean hasDigit = false; boolean hasSymbol = false; if (password.length() < MIN_PASSWORD_LEN) { return true; } for (int ii = 0; ii < password.length(); ++ii) { char c; c = password.charAt(ii); if (Character.isDigit(c)) hasDigit = true; else if (Character.isUpperCase(c)) hasUC = true; else if (Character.isLowerCase(c)) hasLC = true; else hasSymbol = true; } return !(hasUC && hasLC && (hasDigit || hasSymbol)); }
From source file:biblivre3.administration.reports.ReportUtils.java
public static String formatDeweyString(final String dewey, final int digits) { if (StringUtils.isBlank(dewey)) { return ""; }// ww w.j a va2 s. c o m if (digits == -1) { return dewey; } int i = digits; StringBuilder format = new StringBuilder(); for (char c : dewey.toCharArray()) { if (i == 0) { break; } if (Character.isDigit(c)) { i--; } format.append(c); } if (digits < 3) { while (format.length() < 3) { format.append("0"); } } return format.toString(); }
From source file:Main.java
/** * Make sure an element/attribute name is a valid NCname. Note that the name is assumed non-qualified, i.e. no * namespaces (hence the Non Colon Name). * //from w w w. j a v a 2 s . co m * @param name Proposed non-qualified name for an element/attribute. * @return Same string, with any invalid characters replaced by the underscore '_' character. */ public static String makeValidNCName(String name) { if (name == null || name.length() <= 0) throw new IllegalArgumentException("Invalid NCName: null or empty not allowed!"); if (name.equalsIgnoreCase("XML")) throw new IllegalArgumentException("Invalid NCName: 'XML' name is reserved!"); StringBuffer s = new StringBuffer(name); char c = name.charAt(0); if (!Character.isLetter(c) && c != '_') s.setCharAt(0, '_'); for (int i = 1; i < name.length(); i++) { c = name.charAt(i); if (!Character.isLetter(c) && !Character.isDigit(c) && c != '_' && c != '.' && c != '-') s.setCharAt(i, '_'); } return s.toString(); }