List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:gov.vha.isaac.ucum.UCUMParser.java
private static ArrayList<String> tokenize(String string) { ArrayList<String> tokens = new ArrayList<>(); if (string != null && string.length() > 0) { Iterator<String> whitespaceSplit = Arrays.asList(string.split("\\s")).iterator(); while (whitespaceSplit.hasNext()) { String temp = whitespaceSplit.next().trim(); if (temp.length() == 0) { continue; }// www. j av a2s. co m //subsplit on digits? - aka 'ab5.0mg' into 'ab' 5.0' 'mg' Boolean readingDigits = null; int digitStart = -1; int textStart = -1; for (int i = 0; i < temp.length(); i++) { if (Character.isDigit(temp.charAt(i)) || temp.charAt(i) == '.') { if (readingDigits == null) { readingDigits = true; digitStart = i; } else if (readingDigits) { continue; } else { readingDigits = true; digitStart = i; if (textStart != -1 && i > textStart) { tokens.add(temp.substring(textStart, digitStart)); } textStart = -1; } } else { if (readingDigits == null) { readingDigits = false; textStart = i; } else if (readingDigits) { readingDigits = false; textStart = i; if (digitStart != -1 && i > digitStart) { tokens.add(temp.substring(digitStart, textStart)); } digitStart = -1; } else { continue; } } } if (textStart != -1) { tokens.add(temp.substring(textStart)); } if (digitStart != -1) { tokens.add(temp.substring(digitStart)); } } } return tokens; }
From source file:com.zimbra.cs.security.sasl.GssAuthenticator.java
@Override public boolean initialize() throws IOException { Krb5Keytab keytab = getKeytab(LC.krb5_keytab.value()); if (keytab == null) { sendFailed("mechanism not supported"); return false; }/*from w w w . j av a2 s .c om*/ debug("keytab file = %s", keytab.getFile()); final String host; if (LC.krb5_service_principal_from_interface_address.booleanValue()) { String localSocketHostname = localAddress.getCanonicalHostName().toLowerCase(); if (localSocketHostname.length() == 0 || Character.isDigit(localSocketHostname.charAt(0))) localSocketHostname = LC.zimbra_server_hostname.value(); host = localSocketHostname; } else { host = LC.zimbra_server_hostname.value(); } KerberosPrincipal kp = new KerberosPrincipal(getProtocol() + '/' + host); debug("kerberos principal = %s", kp); Subject subject = getSubject(keytab, kp); if (subject == null) { sendFailed(); return false; } debug("subject = %s", subject); final Map<String, String> props = getSaslProperties(); if (DEBUG && props != null) { String qop = props.get(Sasl.QOP); debug("Sent QOP = " + (qop != null ? qop : "auth")); } try { mSaslServer = (SaslServer) Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { @Override public Object run() throws SaslException { return Sasl.createSaslServer(getMechanism(), getProtocol(), host, props, new GssCallbackHandler()); } }); } catch (PrivilegedActionException e) { sendFailed(); getLog().warn("Could not create SaslServer", e.getCause()); return false; } return true; }
From source file:io.github.jeddict.jcode.util.StringHelper.java
/** * * @param input/*from www . ja v a2s .c o m*/ * @return * @example * * BankAccount => Bank Account Bank_Account => Bank_Account */ public static String toNatural(String input) { String natural = EMPTY; Character lastChar = null; for (Character curChar : input.toCharArray()) { if (lastChar == null) { // First character lastChar = Character.toUpperCase(curChar); natural = natural + lastChar; } else { if (Character.isLowerCase(lastChar) && (Character.isUpperCase(curChar)) || Character.isDigit(curChar)) { natural = natural + " " + curChar; } else { natural = natural + curChar; } lastChar = curChar; } } return natural; }
From source file:com.aw.swing.mvp.validation.support.AWDefaultRulesSource.java
private static Character findNonDigit(String str) { for (int i = 0; i < str.length(); i++) { if (!Character.isDigit(str.charAt(i))) return new Character(str.charAt(i)); }/*from w ww . j a v a 2s . com*/ return null; }
From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java
static String getDigits(String s) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < s.length(); i++) { if (Character.isDigit(s.charAt(i))) { buffer.append(s.charAt(i));// ww w . ja va 2 s.c o m } } return buffer.toString(); }
From source file:com.dbschools.quickquiz.client.giver.MainWindow.java
private void addListeners() { takerTableDisplay.addTableKeyListener(new KeyAdapter() { @Override//from ww w . j a v a2 s. c om public void keyPressed(KeyEvent e) { char keyChar = e.getKeyChar(); if (Character.isDigit(keyChar) && e.isControlDown()) { awardPoints(Integer.parseInt(Character.toString(keyChar))); } } }); final ListSelectionModel takerTableSelectionModel = takerTableDisplay.getSelectionModel(); takerTableSelectionModel.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { btnAwardPoints.setEnabled(!takerTableSelectionModel.isSelectionEmpty()); } }); countdownMeter.addCountdownFinishListener(new CountdownFinishListener() { public void countdownFinished() { SwingUtilities.invokeLater(new Runnable() { public void run() { btnSendQuestion.setEnabled(true); } }); } }); }
From source file:com.microsoft.tfs.jni.internal.platformmisc.UnixExecPlatformMisc.java
@Override public String getEnvironmentVariable(final String name) { Check.notNullOrEmpty(name, "name"); //$NON-NLS-1$ /*/*from ww w . j a va 2 s . com*/ * Unix doesn't support environment variables that begin with numbers. */ if (Character.isDigit(name.charAt(0))) { return null; } final String[] args = new String[] { "/bin/sh", //$NON-NLS-1$ "-c", //$NON-NLS-1$ "echo \"$" + name + "\"" //$NON-NLS-1$ //$NON-NLS-2$ }; final StringBuffer output = new StringBuffer(); final int ret = ExecHelpers.exec(args, output); if (ret != 0) { log.error(MessageFormat.format("External command returned non-zero exit status {0}: {1}", //$NON-NLS-1$ Integer.toString(ret), ExecHelpers.buildCommandForError(args))); } final String value = output.toString().trim(); /* * If we got an empty string, the variable was not set, or was set to an * empty string. */ if (value.length() == 0) { return null; } return value; }
From source file:au.org.ala.delta.util.Utils.java
/** * A slightly more tolerant version of the BigDecimal constructor - we allow * the valid number to be followed by non-numeric characters at the end of * the string.//from w w w.j a v a 2s . c o m * * @param src * the String to parse into a BigDecimal. * @return the length of the portion of the string containing a parsable * number. */ public static BigDecimal stringToBigDecimal(String src, int[] endPos) { int endIndex = src.length(); while (!Character.isDigit(src.charAt(endIndex - 1))) { endIndex--; } BigDecimal value = new BigDecimal(src.substring(0, endIndex)); endPos[0] = endIndex; return value; }
From source file:gool.generator.common.CommonCodeGenerator.java
/** * <pre>// www.ja v a 2 s . com * Produce indented code in a manner similar to printf but with custom conversions. * %% a single "%" * %s Print an argument as a string, without indentation or newlines added. * Similar to the corresponding flag of <i>String.format</i>. * %<i>n</i> (where <i>n</i> is a digit) * Print an argument as a bloc indented <i>n</i> times from the current indentation level. * Newlines are inserted before and after the bloc. * %-<i>n</i> (where <i>n</i> is a digit) * <i>n</i> times the indentation string, does not consumes a argument. * %-0 becomes a empty string (it does nothing but is still parsed) * * @param format * the format string * @param arguments * the objects to format, each one corresponding to a % code * @return the formated string */ protected String formatIndented(String format, Object... arguments) { StringBuilder sb = new StringBuilder(format); int pos = sb.indexOf("%"); int arg = 0; while (pos != -1) { if (sb.charAt(pos + 1) == '%') { sb = sb.replace(pos, pos + 2, "%"); } else if (sb.charAt(pos + 1) == 's') { sb = sb.replace(pos, pos + 2, arguments[arg].toString()); pos += arguments[arg].toString().length() - 1; arg++; } else if (Character.isDigit(sb.charAt(pos + 1))) { String replacement = ("\n" + arguments[arg].toString().replaceFirst("\\s*\\z", "")).replace("\n", "\n" + StringUtils.repeat(indentation, Character.digit(sb.charAt(pos + 1), 10))) + "\n"; sb = sb.replace(pos, pos + 2, replacement); pos += replacement.length() - 1; arg++; } else if (sb.charAt(pos + 1) == '-' && Character.isDigit(sb.charAt(pos + 2))) { String replacement = StringUtils.repeat(indentation, Character.digit(sb.charAt(pos + 2), 10)); sb = sb.replace(pos, pos + 3, replacement); pos += replacement.length(); } pos = sb.indexOf("%", pos); } return sb.toString(); }
From source file:com.prowidesoftware.swift.model.BIC.java
/** * Validates a BIC structure./*from w w w . ja v a 2 s .c o m*/ * It only checks that length is 8 or 11 and that the country code is valid. * This method does not validate against any BIC directory. * * @return <code>true</code> if the BIC is found to be valid and <code>false</code> in other case * @throws IllegalStateException if BIC is <code>null</code> */ public boolean isValid() { if (this.bic8 == null) { this.invalidCause = "BIC is null"; return false; } if (this.bic8.length() != 8) { this.invalidCause = "Expected 8 characters for the institution and country code and found " + this.bic8.length() + " in " + this.bic8; return false; } if (this.branch != null && this.branch.length() != 3) { this.invalidCause = "Expected 3 characters for branch and found " + this.branch.length() + " in " + this.branch; return false; } final String country = this.bic8.substring(4, 6); if (!ISOCountries.getInstance().isValidCode(country.toUpperCase())) { this.invalidCause = "Invalid country code " + country; return false; } final String b11 = getBic11(); for (int i = 0; i < b11.length(); i++) { final char c = b11.charAt(i); final boolean digit = Character.isDigit(c); final boolean uppercase = Character.isUpperCase(c); if (!digit && !uppercase) { this.invalidCause = "BIC characters must be alphanumeric uppercase"; return false; } } return true; }