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.microsoft.windowsazure.management.storage.StorageAccountOperationsImpl.java

/**
* The Begin Creating Storage Account operation creates a new storage
* account in Azure.  (see/*from   w w  w . ja va2 s  .c om*/
* http://msdn.microsoft.com/en-us/library/windowsazure/hh264518.aspx for
* more information)
*
* @param parameters Required. Parameters supplied to the Begin Creating
* Storage Account operation.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public OperationResponse beginCreating(StorageAccountCreateParameters parameters)
        throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
    // Validate
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getDescription() != null && parameters.getDescription().length() > 1024) {
        throw new IllegalArgumentException("parameters.Description");
    }
    if (parameters.getLabel() == null) {
        throw new NullPointerException("parameters.Label");
    }
    if (parameters.getLabel().length() > 100) {
        throw new IllegalArgumentException("parameters.Label");
    }
    if (parameters.getName() == null) {
        throw new NullPointerException("parameters.Name");
    }
    if (parameters.getName().length() < 3) {
        throw new IllegalArgumentException("parameters.Name");
    }
    if (parameters.getName().length() > 24) {
        throw new IllegalArgumentException("parameters.Name");
    }
    for (char nameChar : parameters.getName().toCharArray()) {
        if (Character.isLowerCase(nameChar) == false && Character.isDigit(nameChar) == false) {
            throw new IllegalArgumentException("parameters.Name");
        }
    }
    // TODO: Validate parameters.Name is a valid DNS name.

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "beginCreatingAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/storageservices";
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPost httpRequest = new HttpPost(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/xml");
    httpRequest.setHeader("x-ms-version", "2014-10-01");

    // Serialize Request
    String requestContent = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document requestDoc = documentBuilder.newDocument();

    Element createStorageServiceInputElement = requestDoc
            .createElementNS("http://schemas.microsoft.com/windowsazure", "CreateStorageServiceInput");
    requestDoc.appendChild(createStorageServiceInputElement);

    Element serviceNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "ServiceName");
    serviceNameElement.appendChild(requestDoc.createTextNode(parameters.getName()));
    createStorageServiceInputElement.appendChild(serviceNameElement);

    if (parameters.getDescription() != null) {
        Element descriptionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "Description");
        descriptionElement.appendChild(requestDoc.createTextNode(parameters.getDescription()));
        createStorageServiceInputElement.appendChild(descriptionElement);
    } else {
        Element emptyElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "Description");
        Attr nilAttribute = requestDoc.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
        nilAttribute.setValue("true");
        emptyElement.setAttributeNode(nilAttribute);
        createStorageServiceInputElement.appendChild(emptyElement);
    }

    Element labelElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Label");
    labelElement.appendChild(requestDoc.createTextNode(Base64.encode(parameters.getLabel().getBytes())));
    createStorageServiceInputElement.appendChild(labelElement);

    if (parameters.getAffinityGroup() != null) {
        Element affinityGroupElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "AffinityGroup");
        affinityGroupElement.appendChild(requestDoc.createTextNode(parameters.getAffinityGroup()));
        createStorageServiceInputElement.appendChild(affinityGroupElement);
    }

    if (parameters.getLocation() != null) {
        Element locationElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "Location");
        locationElement.appendChild(requestDoc.createTextNode(parameters.getLocation()));
        createStorageServiceInputElement.appendChild(locationElement);
    }

    if (parameters.getExtendedProperties() != null) {
        if (parameters.getExtendedProperties() instanceof LazyCollection == false
                || ((LazyCollection) parameters.getExtendedProperties()).isInitialized()) {
            Element extendedPropertiesDictionaryElement = requestDoc
                    .createElementNS("http://schemas.microsoft.com/windowsazure", "ExtendedProperties");
            for (Map.Entry<String, String> entry : parameters.getExtendedProperties().entrySet()) {
                String extendedPropertiesKey = entry.getKey();
                String extendedPropertiesValue = entry.getValue();
                Element extendedPropertiesElement = requestDoc
                        .createElementNS("http://schemas.microsoft.com/windowsazure", "ExtendedProperty");
                extendedPropertiesDictionaryElement.appendChild(extendedPropertiesElement);

                Element extendedPropertiesKeyElement = requestDoc
                        .createElementNS("http://schemas.microsoft.com/windowsazure", "Name");
                extendedPropertiesKeyElement.appendChild(requestDoc.createTextNode(extendedPropertiesKey));
                extendedPropertiesElement.appendChild(extendedPropertiesKeyElement);

                Element extendedPropertiesValueElement = requestDoc
                        .createElementNS("http://schemas.microsoft.com/windowsazure", "Value");
                extendedPropertiesValueElement.appendChild(requestDoc.createTextNode(extendedPropertiesValue));
                extendedPropertiesElement.appendChild(extendedPropertiesValueElement);
            }
            createStorageServiceInputElement.appendChild(extendedPropertiesDictionaryElement);
        }
    }

    if (parameters.getAccountType() != null) {
        Element accountTypeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "AccountType");
        accountTypeElement.appendChild(requestDoc.createTextNode(parameters.getAccountType()));
        createStorageServiceInputElement.appendChild(accountTypeElement);
    }

    DOMSource domSource = new DOMSource(requestDoc);
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(domSource, streamResult);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/xml");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_ACCEPTED) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        OperationResponse result = null;
        // Deserialize Response
        result = new OperationResponse();
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.mirth.connect.plugins.datatypes.delimited.DelimitedSerializationProperties.java

private boolean validXMLElementName(String s) {

    // Reference: http://www.w3.org/TR/REC-xml/#sec-well-formed
    ///* w  w w.  java2 s . c  o  m*/
    // Simplified requirements for a valid XML element name:
    //  o First character must be a letter, underscore or colon
    //  o Remaining characters must be letter, digit, period, dash, underscore or colon
    //
    // Note: this is not 100% complete, as it does not include tests for the so called
    //  "CombiningChar" nor "Extender".

    // Must not be null or empty string 
    if (s == null || s.length() == 0) {
        return false;
    }

    // First character must be a letter, underscore or colon
    char ch = s.charAt(0);
    if (!Character.isLetter(ch) && ch != '_' && ch != ':') {
        return false;
    }

    // Remaining characters must be letter, digit, period, dash, underscore or colon
    for (int i = 1; i < s.length(); i++) {
        ch = s.charAt(i);
        if (!Character.isLetter(ch) && !Character.isDigit(ch) && ch != '.' && ch != '-' && ch != '_'
                && ch != ':') {
            return false;
        }
    }
    return true;
}

From source file:org.dasein.cloud.openstack.nova.os.NovaOpenStack.java

public @Nonnegative int getMinorVersion() throws CloudException, InternalException {
    AuthenticationContext ctx = getAuthenticationContext();
    String endpoint = ctx.getComputeUrl();

    if (endpoint == null) {
        endpoint = ctx.getStorageUrl();//from  ww w . ja  v  a  2 s  . c  o  m
        if (endpoint == null) {
            return 1;
        }
    }
    while (endpoint.endsWith("/") && endpoint.length() > 1) {
        endpoint = endpoint.substring(0, endpoint.length() - 1);
    }
    String[] parts = endpoint.split("/");
    int idx = parts.length - 1;

    do {
        endpoint = parts[idx];
        while (!Character.isDigit(endpoint.charAt(0)) && endpoint.length() > 1) {
            endpoint = endpoint.substring(1);
        }
        if (Character.isDigit(endpoint.charAt(0))) {
            int i = endpoint.indexOf('.');

            try {
                if (i == -1) {
                    return Integer.parseInt(endpoint);
                }
                String[] d = endpoint.split("\\.");

                return Integer.parseInt(d[1]);
            } catch (NumberFormatException ignore) {
                // ignore
            }
        }
    } while ((idx--) > 0);
    return 1;
}

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

public static boolean checkFormatDateDDMMYYYY(String str) {
    if (str == null || str.length() == 0 || str == "null") {
        return false;
    }/*w w w .j  a  va2 s  . c o m*/

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

From source file:marytts.util.string.StringUtils.java

public static boolean isNumeric(String str) {
    for (int i = 0; i < str.length(); i++) {
        char ch = str.charAt(i);
        if (!Character.isDigit(ch) && ch != '.')
            return false;
    }/*from  ww  w  . ja v  a 2  s . c  o m*/

    return true;
}

From source file:com.apigee.sdk.apm.http.impl.client.cache.WarningValue.java

protected void consumeWarnCode() {
    if (offs + 4 > src.length() || !Character.isDigit(src.charAt(offs))
            || !Character.isDigit(src.charAt(offs + 1)) || !Character.isDigit(src.charAt(offs + 2))
            || src.charAt(offs + 3) != ' ') {
        parseError();/*w w w.j av a 2 s  .  c  o  m*/
    }
    warnCode = Integer.parseInt(src.substring(offs, offs + 3));
    offs += 4;
}

From source file:com.sun.faces.demotest.cardemo.TestCarDemo.java

protected int extractNumberFromText(String content) {
    char[] chars = null;
    chars = content.toCharArray();//from w  w w .  j a v a 2  s . co m
    String number = null;
    int i, j;
    for (i = 0; i < chars.length; i++) {
        if (Character.isDigit(chars[i])) {
            for (j = i; j < chars.length; j++) {
                if (Character.isWhitespace(chars[j])) {
                    break;
                }
            }
            number = content.substring(i, j);
            return Integer.valueOf(number).intValue();
        }
    }
    return Integer.MIN_VALUE;
}

From source file:com.att.aro.core.searching.impl.PatternSearchingHandler.java

/**
 * check if the input is a valid credit card candidate
 * @param start//from w  w  w  .ja  va2  s .  c o m
 * @param end
 * @param info
 * @param text
 * @return
 */
private boolean isValidCreditCardCandidate(int start, int end, String text) {
    // check one character before the pattern
    if (start - 1 >= 0 && Character.isDigit(text.charAt(start - 1))) {
        return false;
    }
    // check one character after the pattern
    if (end + 1 < text.length() && Character.isDigit(text.charAt(end + 1))) {
        return false;
    }
    return true;
}

From source file:com.sec.ose.osi.ui.dialog.setting.JPanProjectAnalysisSetting.java

/**
 * This method initializes jTextFieldUserHour
 *    //from   w ww .j a  v  a2s. c om
 * @return javax.swing.JTextField   
 */
private JTextField getJTextFieldUserHour() {
    if (jTextFieldUserHour == null) {
        jTextFieldUserHour = new JTextField();
        jTextFieldUserHour.setPreferredSize(new Dimension(80, 22));
        jTextFieldUserHour.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
                char c = e.getKeyChar();
                if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))) {
                    getToolkit().beep();
                    e.consume();
                }
            }
        });

    }
    return jTextFieldUserHour;
}

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

public static boolean checkFormatDateDDMMYYYYBackSlash(String str) {
    if (str == null || str.length() == 0 || str == "null") {
        return false;
    }// w  w w  . j av  a2 s  .c  o m

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