Example usage for java.lang Character isDigit

List of usage examples for java.lang Character isDigit

Introduction

In this page you can find the example usage for java.lang Character isDigit.

Prototype

public static boolean isDigit(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a digit.

Usage

From source file:com.googlecode.jsonschema2pojo.rules.EnumRule.java

private String getConstantName(String nodeName) {
    List<String> enumNameGroups = new ArrayList<String>(asList(splitByCharacterTypeCamelCase(nodeName)));

    String enumName = "";
    for (Iterator<String> iter = enumNameGroups.iterator(); iter.hasNext();) {
        if (containsOnly(ruleFactory.getNameHelper().replaceIllegalCharacters(iter.next()), "_")) {
            iter.remove();//from ww  w.j  av a2 s.  c o m
        }
    }

    enumName = upperCase(join(enumNameGroups, "_"));

    if (isEmpty(enumName)) {
        enumName = "__EMPTY__";
    } else if (Character.isDigit(enumName.charAt(0))) {
        enumName = "_" + enumName;
    }

    return enumName;
}

From source file:com.allmycode.flags.MyActivity.java

boolean isHexDigit(char ch) {
    Log.i(CLASSNAME, "testing " + Character.toString(ch));
    switch (ch) {
    case 'A':
        return true;
    case 'B':
        return true;
    case 'C':
        return true;
    case 'D':
        return true;
    case 'E':
        return true;
    default:// w w w .j a  v  a2s  .c o  m
        return Character.isDigit(ch);
    }
}

From source file:de.innovationgate.wgpublisher.hdb.HDBModelListener.java

public static String createContentClassJsIdentifier(String contentClass) {

    // Remove chars not allowed in JS var names:
    StringBuffer extension = new StringBuffer();
    for (int idx = 0; idx < contentClass.length(); idx++) {
        Character c = contentClass.charAt(idx);
        if (idx == 0) {
            if (Character.isLetter(c)) {
                extension.append(c);/* w w  w  .  j  a  va 2s. c  om*/
            }
        } else {
            if (Character.isLetter(c) || Character.isDigit(c)) {
                extension.append(c);
            }
        }
    }

    // Capitalize
    return StringUtils.capitalize(extension.toString().toLowerCase());

}

From source file:gmgen.util.MiscUtilities.java

/**
 *  A more intelligent version of String.compareTo() that handles numbers
 *  specially. For example, it places "My file 2" before "My file 10".
 *
 *@param  str1        The first string/*from  w  ww .  ja va  2  s  . c om*/
 *@param  str2        The second string
 *@param  ignoreCase  If true, case will be ignored
 *@return             negative If str1 &lt; str2, 0 if both are the same,
 *                    positive if str1 &gt; str2
 */
public static int compareStrings(String str1, String str2, boolean ignoreCase) {
    char[] char1 = str1.toCharArray();
    char[] char2 = str2.toCharArray();

    int len = Math.min(char1.length, char2.length);

    for (int i = 0, j = 0; (i < len) && (j < len); i++, j++) {
        char ch1 = char1[i];
        char ch2 = char2[j];

        if (Character.isDigit(ch1) && Character.isDigit(ch2) && (ch1 != '0') && (ch2 != '0')) {
            int _i = i + 1;
            int _j = j + 1;

            for (; _i < char1.length; _i++) {
                if (!Character.isDigit(char1[_i])) {
                    break;
                }
            }

            for (; _j < char2.length; _j++) {
                if (!Character.isDigit(char2[_j])) {
                    break;
                }
            }

            int len1 = _i - i;
            int len2 = _j - j;

            if (len1 > len2) {
                return 1;
            } else if (len1 < len2) {
                return -1;
            } else {
                for (int k = 0; k < len1; k++) {
                    ch1 = char1[i + k];
                    ch2 = char2[j + k];

                    if (ch1 != ch2) {
                        return ch1 - ch2;
                    }
                }
            }

            i = _i - 1;
            j = _j - 1;
        } else {
            if (ignoreCase) {
                ch1 = Character.toLowerCase(ch1);
                ch2 = Character.toLowerCase(ch2);
            }

            if (ch1 != ch2) {
                return ch1 - ch2;
            }
        }
    }

    return char1.length - char2.length;
}

From source file:herudi.controller.microMarketController.java

@FXML
private void keyAreaWidth(KeyEvent event) {
    char[] data = txtAreaWidth.getText().toCharArray();
    boolean valid = true;
    for (char c : data) {
        if (!Character.isDigit(c)) {
            valid = false;// www.j a  v  a 2  s . co  m
            break;
        }
    }
    if (!valid) {
        config2.dialog(Alert.AlertType.ERROR, "Please, Fill With Number");
        txtAreaWidth.clear();
        txtAreaWidth.requestFocus();
    }
}

From source file:com.kcs.core.utilities.Utility.java

public static boolean checkNumbersOnly(String str) {
    if (str == null || str.length() == 0 || str == "null") {
        return false;
    }//from  w w w .  j  a va  2 s . co m

    for (int i = 0; i < str.length(); i++) {
        if (!Character.isDigit(str.charAt(i)) && str.charAt(i) != '.' && str.charAt(i) != '-') {
            return false;
        }
    }

    return true;
}

From source file:gobblin.source.extractor.extract.jdbc.SqlServerExtractor.java

private static int getLimitEndIndex(String inputQuery, int limitStartIndex) {
    int limitEndIndex = -1;
    if (limitStartIndex > 0) {
        limitEndIndex = limitStartIndex + 5;
        String remainingQuery = inputQuery.substring(limitEndIndex);
        boolean numFound = false;

        int pos = 0;
        while (pos < remainingQuery.length()) {
            char ch = remainingQuery.charAt(pos);
            if (ch == ' ' && !numFound) {
                pos++;// w  w w .ja va2s . co m
                continue;
            } else if (numFound && (!Character.isDigit(ch))) {
                break;
            } else {
                numFound = true;
            }
            pos++;
        }
        limitEndIndex = limitEndIndex + pos;
    }
    return limitEndIndex;
}

From source file:appmain.AppMain.java

private void init() {
    try {/*  w w w.ja  v  a  2  s  .com*/
        ElementConverter defaultConverter = e -> e.getText();

        ElementConverter partnerConverter = e -> {
            String text = e.getText();
            String[] partnerTypes = { "Fizet:", "Kedvezmnyezett:", "Bonyolt:" };
            for (String partnerType : partnerTypes) {
                if (text.contains(partnerType)) {
                    int idx = text.indexOf(partnerType);
                    String partner = text.substring(idx + partnerType.length(), text.indexOf(",")).trim();
                    return partner;
                }
            }
            return "";
        };

        ElementConverter commentConverter = e -> {
            String text = e.getText();
            String commentString = "Kzlemny:";
            if (text.contains(commentString)) {
                int idx = text.indexOf(commentString);
                String comment = text.substring(idx + commentString.length());
                return comment;
            }
            return "";
        };

        ElementConverter accNumConverter = e -> {
            String text = e.getText();
            String[] partnerTypes = { "Fizet:", "Kedvezmnyezett:", "Bonyolt:" };
            for (String partnerType : partnerTypes) {
                if (text.contains(partnerType)) {
                    int idx = text.indexOf(",");
                    String tmp = text.substring(idx + 1).trim();
                    StringBuilder accNum = new StringBuilder();
                    for (char ch : tmp.toCharArray()) {
                        if (Character.isDigit(ch) || ch == '-') {
                            accNum.append(ch);
                        } else {
                            break;
                        }
                    }
                    ;
                    if (!accNum.toString().contains("-")) {
                        return "";
                    }
                    return accNum.toString().trim();
                }
            }
            return "";
        };

        fields.add(new Field("Tranzakci azonost", "F_TRCODE", defaultConverter));
        fields.add(new Field("rtknap", "F_DAT1", e -> e.getAttributeValue("fv")));
        fields.add(new Field("sszeg", "F_TRAMOUNT", defaultConverter));
        fields.add(new Field("Devizanem", "F_CUR", defaultConverter));
        fields.add(new Field("Partner", "F_LINES", partnerConverter));
        fields.add(new Field("Kzlemny", "F_LINES", commentConverter));
        fields.add(new Field("Tranzakci neve", "F_NAME", defaultConverter));
        fields.add(new Field("Ellenszmla", "F_LINES", accNumConverter));
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null,
                "Hiba az inicializls kzben!\n" + ExceptionUtils.getStackTrace(ex), "Hiba",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.eclipse.ebr.maven.EclipseIpLogUtil.java

private String createCq(final CloseableHttpClient httpclient, final Artifact artifact, final Model artifactPom,
        final Map<String, Xpp3Dom> existingLicenses)
        throws URISyntaxException, MojoExecutionException, IOException {
    final URIBuilder postUri = new URIBuilder(DISPATCH_PHP);
    postUri.addParameter("id",
            "portal/contribution_questionnaire.contribution_questionnaire_reuse." + projectId + "!reuse");
    postUri.addParameter("action", "submit");

    final HttpPost httpPost = new HttpPost(postUri.build());
    httpPost.addHeader("Referer", PORTAL_PHP);
    final List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("name", getCqName(artifact, artifactPom)));
    nvps.add(new BasicNameValuePair("version", artifact.getVersion()));
    nvps.add(new BasicNameValuePair("description", getCqDescription(artifact, artifactPom)));
    nvps.add(new BasicNameValuePair("cryptography",
            Strings.nullToEmpty(getCqCryptography(artifact, artifactPom))));
    nvps.add(new BasicNameValuePair("projecturl", Strings.nullToEmpty(getCqProjectUrl(artifact, artifactPom))));
    nvps.add(new BasicNameValuePair("sourceurl", Strings.nullToEmpty(getCqSourceUrl(artifact, artifactPom))));
    nvps.add(new BasicNameValuePair("license", getCqLicense(artifact, artifactPom, existingLicenses)));
    nvps.add(new BasicNameValuePair("otherlicense", ""));
    nvps.add(new BasicNameValuePair("sourcebinary", "sourceandbinary"));
    nvps.add(new BasicNameValuePair("modifiedcode", "unmodified"));
    nvps.add(new BasicNameValuePair("apachehosted", getCqApacheHosted(artifact, artifactPom)));
    nvps.add(new BasicNameValuePair("codeagreement", getCqCodeAgreement(artifact, artifactPom)));
    nvps.add(new BasicNameValuePair("stateid", "not_existing"));
    httpPost.setEntity(new UrlEncodedFormEntity(nvps));

    if (getLog().isDebugEnabled()) {
        for (final NameValuePair pair : nvps) {
            getLog().debug("   " + pair.getName() + "=" + pair.getValue());
        }//from   ww  w. j  a v a 2  s.  c  om
    }

    final String responseHtml = executeRequest(httpclient, httpPost,
            StringUtils.removeEnd(artifact.getFile().getName(), ".jar") + "-ipzilla-response.html");

    final String cqUrl = "https://dev.eclipse.org/ipzilla/show_bug.cgi?id=";
    final int cqUrlIndex = responseHtml.indexOf(cqUrl);
    final StrBuilder cqId = new StrBuilder();
    for (int i = cqUrlIndex + cqUrl.length(); i < responseHtml.length(); i++) {
        final char c = responseHtml.charAt(i);
        if (Character.isDigit(c)) {
            cqId.append(c);
        } else {
            break;
        }
    }

    try {
        final int cqNumber = Integer.parseInt(cqId.toString());
        if (cqNumber > 0)
            return String.valueOf(cqNumber);
    } catch (final NumberFormatException e) {
        getLog().error(format("Error parsing extracted CQ number '%s'. %s", cqId, e.getMessage()), e);
    }

    // we can only fail at this point
    throw new MojoExecutionException(
            "Unable to extract CQ number from response. Please check response and IPzilla!");
}

From source file:com.myJava.file.driver.remote.ftp.SecuredSocketFactory.java

private void readReply(Socket socket) throws IOException {
    // Read response
    BufferedReader in = new BufferedReader(
            new InputStreamReader(socket.getInputStream(), client.getControlEncoding()));
    String line = in.readLine();//from w  w  w.  j  a  v a  2 s .  c  o m
    StringBuffer sb = new StringBuffer(line);
    int length = line.length();
    if (length > 3 && line.charAt(3) == '-') {
        do {
            line = in.readLine();
            sb.append(" / ").append(line);

            if (line == null) {
                throw new FTPConnectionClosedException("Connection closed without indication.");
            }
        } while (!(line.length() >= 4 && line.charAt(3) != '-' && Character.isDigit(line.charAt(0))));
    }
    Logger.defaultLogger().info("Received FTP server response : " + sb.toString());
}