Example usage for java.lang Character isLetter

List of usage examples for java.lang Character isLetter

Introduction

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

Prototype

public static boolean isLetter(int codePoint) 

Source Link

Document

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

Usage

From source file:io.manasobi.utils.StringUtils.java

/**
 *  String? '?' ?  ?.<br>/*from w ww . ja  v  a  2  s  . c o  m*/
 * ??? ?? Java?  ? ? .<br>
 *  String? null? , false return.<br><br>
 *
 * StringUtils.isLetter("test") = true<br>
 * StringUtils.isLetter("test")= true<br>
 * StringUtils.isLetter("test#$%") = false<br>
 * StringUtils.isLetter("test123") = false
 *
 * @param str
 *            the String to check, may be null
 * @return true if String contains only letters, false if not or null string
 *         input
 */
public static boolean isLetter(String str) {
    if (str == null) {
        return false;
    }
    char[] chars = str.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (!Character.isLetter(chars[i])) {
            return false;
        }
    }
    return true;
}

From source file:com.ecyrd.jspwiki.parser.JSPWikiMarkupParser.java

/**
 *  Handles constructs of type %%(style) and %%class
 * @param newLine//  www.  j a  v a  2 s .  c  o m
 * @return An Element containing the div or span, depending on the situation.
 * @throws IOException
 */
private Element handleDiv(boolean newLine) throws IOException {
    int ch = nextToken();
    Element el = null;

    if (ch == '%') {
        String style = null;
        String clazz = null;

        ch = nextToken();

        //
        //  Style or class?
        //
        if (ch == '(') {
            style = readBraceContent('(', ')');
        } else if (Character.isLetter((char) ch)) {
            pushBack(ch);
            clazz = readUntil(" \t\n\r");
            ch = nextToken();

            //
            //  Pop out only spaces, so that the upcoming EOL check does not check the
            //  next line.
            //
            if (ch == '\n' || ch == '\r') {
                pushBack(ch);
            }
        } else {
            //
            // Anything else stops.
            //

            pushBack(ch);

            try {
                Boolean isSpan = m_styleStack.pop();

                if (isSpan == null) {
                    // Fail quietly
                } else if (isSpan.booleanValue()) {
                    el = popElement("span");
                } else {
                    el = popElement("div");
                }
            } catch (EmptyStackException e) {
                log.debug("Page '" + m_context.getName() + "' closes a %%-block that has not been opened.");
                return m_currentElement;
            }

            return el;
        }

        //
        //  Check if there is an attempt to do something nasty
        //

        try {
            style = StringEscapeUtils.unescapeHtml(style);
            if (style != null && style.indexOf("javascript:") != -1) {
                log.debug("Attempt to output javascript within CSS:" + style);
                ResourceBundle rb = m_context.getBundle(InternationalizationManager.CORE_BUNDLE);
                return addElement(makeError(rb.getString("markupparser.error.javascriptattempt")));
            }
        } catch (NumberFormatException e) {
            //
            //  If there are unknown entities, we don't want the parser to stop.
            //
            ResourceBundle rb = m_context.getBundle(InternationalizationManager.CORE_BUNDLE);
            Object[] args = { e.getMessage() };
            String msg = MessageFormat.format(rb.getString("markupparser.error.parserfailure"), args);
            return addElement(makeError(msg));
        }

        //
        //  Decide if we should open a div or a span?
        //
        String eol = peekAheadLine();

        if (eol.trim().length() > 0) {
            // There is stuff after the class

            el = new Element("span");

            m_styleStack.push(Boolean.TRUE);
        } else {
            startBlockLevel();
            el = new Element("div");
            m_styleStack.push(Boolean.FALSE);
        }

        if (style != null)
            el.setAttribute("style", style);
        if (clazz != null)
            el.setAttribute("class", clazz);
        el = pushElement(el);

        return el;
    }

    pushBack(ch);

    return el;
}

From source file:org.apache.wiki.parser.JSPWikiMarkupParser.java

/**
 *  Handles constructs of type %%(style) and %%class
 * @param newLine//  www .j  av a  2  s  .com
 * @return An Element containing the div or span, depending on the situation.
 * @throws IOException
 */
private Element handleDiv(boolean newLine) throws IOException {
    int ch = nextToken();
    Element el = null;

    if (ch == '%') {
        String style = null;
        String clazz = null;

        ch = nextToken();

        //
        //  Style or class?
        //
        if (ch == '(') {
            style = readBraceContent('(', ')');
        } else if (Character.isLetter((char) ch)) {
            pushBack(ch);
            clazz = readUntil(" \t\n\r");
            ch = nextToken();

            //
            //  Pop out only spaces, so that the upcoming EOL check does not check the
            //  next line.
            //
            if (ch == '\n' || ch == '\r') {
                pushBack(ch);
            }
        } else {
            //
            // Anything else stops.
            //

            pushBack(ch);

            try {
                Boolean isSpan = m_styleStack.pop();

                if (isSpan == null) {
                    // Fail quietly
                } else if (isSpan.booleanValue()) {
                    el = popElement("span");
                } else {
                    el = popElement("div");
                }
            } catch (EmptyStackException e) {
                log.debug("Page '" + m_context.getName() + "' closes a %%-block that has not been opened.");
                return m_currentElement;
            }

            return el;
        }

        //
        //  Check if there is an attempt to do something nasty
        //

        try {
            style = StringEscapeUtils.unescapeHtml(style);
            if (style != null && style.indexOf("javascript:") != -1) {
                log.debug("Attempt to output javascript within CSS:" + style);
                ResourceBundle rb = Preferences.getBundle(m_context, InternationalizationManager.CORE_BUNDLE);
                return addElement(makeError(rb.getString("markupparser.error.javascriptattempt")));
            }
        } catch (NumberFormatException e) {
            //
            //  If there are unknown entities, we don't want the parser to stop.
            //
            ResourceBundle rb = Preferences.getBundle(m_context, InternationalizationManager.CORE_BUNDLE);
            String msg = MessageFormat.format(rb.getString("markupparser.error.parserfailure"), e.getMessage());
            return addElement(makeError(msg));
        }

        //
        //  Decide if we should open a div or a span?
        //
        String eol = peekAheadLine();

        if (eol.trim().length() > 0) {
            // There is stuff after the class

            el = new Element("span");

            m_styleStack.push(Boolean.TRUE);
        } else {
            startBlockLevel();
            el = new Element("div");
            m_styleStack.push(Boolean.FALSE);
        }

        if (style != null)
            el.setAttribute("style", style);
        if (clazz != null)
            el.setAttribute("class", clazz);
        el = pushElement(el);

        return el;
    }

    pushBack(ch);

    return el;
}

From source file:com.atlassian.jira.util.BugzillaImportBean.java

/**
 * Return an integer prefix of a string, if any.
 *
 * @param s String containing id/*from  www . j av a2 s  . c o  m*/
 * @return id
 */
public Integer getIdFromStartOfString(final String s) {
    if ((s.length() == 0) || !Character.isDigit(s.charAt(0))) {
        return null;
    }

    final StringBuffer buf = new StringBuffer(5);
    for (int i = 0; i < Math.min(6, s.length()); i++) {
        final char c = s.charAt(i);
        if (Character.isDigit(c)) {
            buf.append(c);
        } else if (Character.isLetter(c)) {
            return null;
        } else {
            break;
        }
    }
    return new Integer(Integer.parseInt(buf.toString()));
}

From source file:org.eclipse.swt.examples.imageanalyzer.ImageAnalyzer.java

void displayImage(ImageData newImageData) {
    resetScaleCombos();/*from   w  w w . java2 s  .  c  o  m*/
    if (incremental && incrementalThread != null) {
        // Tell the incremental thread to stop drawing.
        synchronized (this) {
            incrementalEvents = null;
        }

        // Wait until the incremental thread is done.
        while (incrementalThread.isAlive()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }

    // Dispose of the old image, if there was one.
    if (image != null)
        image.dispose();

    try {
        // Cache the new image and imageData.
        image = new Image(display, newImageData);
        imageData = newImageData;

    } catch (SWTException e) {
        showErrorDialog(bundle.getString("Creating_from") + " ", currentName, e);
        image = null;
        return;
    }

    // Update the widgets with the new image info.
    String string = createMsg(bundle.getString("Analyzer_on"), currentName);
    shell.setText(string);

    if (imageDataArray.length > 1) {
        string = createMsg(bundle.getString("Type_index"), new Object[] { fileTypeString(imageData.type),
                Integer.valueOf(imageDataIndex + 1), Integer.valueOf(imageDataArray.length) });
    } else {
        string = createMsg(bundle.getString("Type_string"), fileTypeString(imageData.type));
    }
    typeLabel.setText(string);

    string = createMsg(bundle.getString("Size_value"),
            new Object[] { Integer.valueOf(imageData.width), Integer.valueOf(imageData.height) });
    sizeLabel.setText(string);

    string = createMsg(bundle.getString("Depth_value"),
            new Object[] { Integer.valueOf(imageData.depth), Integer.valueOf(display.getDepth()) });
    depthLabel.setText(string);

    string = createMsg(bundle.getString("Transparent_pixel_value"), pixelInfo(imageData.transparentPixel));
    transparentPixelLabel.setText(string);

    string = createMsg(bundle.getString("Time_to_load_value"), Long.valueOf(loadTime));
    timeToLoadLabel.setText(string);

    string = createMsg(bundle.getString("Animation_size_value"), new Object[] {
            Integer.valueOf(loader.logicalScreenWidth), Integer.valueOf(loader.logicalScreenHeight) });
    screenSizeLabel.setText(string);

    string = createMsg(bundle.getString("Background_pixel_value"), pixelInfo(loader.backgroundPixel));
    backgroundPixelLabel.setText(string);

    string = createMsg(bundle.getString("Image_location_value"),
            new Object[] { Integer.valueOf(imageData.x), Integer.valueOf(imageData.y) });
    locationLabel.setText(string);

    string = createMsg(bundle.getString("Disposal_value"), new Object[] {
            Integer.valueOf(imageData.disposalMethod), disposalString(imageData.disposalMethod) });
    disposalMethodLabel.setText(string);

    int delay = imageData.delayTime * 10;
    int delayUsed = visibleDelay(delay);
    if (delay != delayUsed) {
        string = createMsg(bundle.getString("Delay_value"),
                new Object[] { Integer.valueOf(delay), Integer.valueOf(delayUsed) });
    } else {
        string = createMsg(bundle.getString("Delay_used"), Integer.valueOf(delay));
    }
    delayTimeLabel.setText(string);

    if (loader.repeatCount == 0) {
        string = createMsg(bundle.getString("Repeats_forever"), Integer.valueOf(loader.repeatCount));
    } else {
        string = createMsg(bundle.getString("Repeats_value"), Integer.valueOf(loader.repeatCount));
    }
    repeatCountLabel.setText(string);

    if (imageData.palette.isDirect) {
        string = bundle.getString("Palette_direct");
    } else {
        string = createMsg(bundle.getString("Palette_value"),
                Integer.valueOf(imageData.palette.getRGBs().length));
    }
    paletteLabel.setText(string);

    string = createMsg(bundle.getString("Pixel_data_value"),
            new Object[] { Integer.valueOf(imageData.bytesPerLine), Integer.valueOf(imageData.scanlinePad),
                    depthInfo(imageData.depth),
                    (imageData.alphaData != null && imageData.alphaData.length > 0)
                            ? bundle.getString("Scroll_for_alpha")
                            : "" });
    dataLabel.setText(string);

    String data = dataHexDump(dataText.getLineDelimiter());
    dataText.setText(data);

    // bold the first column all the way down
    int index = 0;
    while ((index = data.indexOf(':', index + 1)) != -1) {
        int start = index - INDEX_DIGITS;
        int length = INDEX_DIGITS;
        if (Character.isLetter(data.charAt(index - 1))) {
            start = index - ALPHA_CHARS;
            length = ALPHA_CHARS;
        }
        dataText.setStyleRange(
                new StyleRange(start, length, dataText.getForeground(), dataText.getBackground(), SWT.BOLD));
    }

    statusLabel.setText("");

    // Redraw both canvases.
    resetScrollBars();
    paletteCanvas.redraw();
    imageCanvas.redraw();
}

From source file:com.jaredrummler.android.device.DeviceName.java

/**
 * <p>Capitalizes getAllProcesses the whitespace separated words in a String. Only the first
 * letter of each word is changed.</p>
 *
 * Whitespace is defined by {@link Character#isWhitespace(char)}.
 *
 * @param str//w ww.j  a v a 2  s. c  o m
 *     the String to capitalize
 * @return capitalized The capitalized String
 */
private static String capitalize(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }
    char[] arr = str.toCharArray();
    boolean capitalizeNext = true;
    String phrase = "";
    for (char c : arr) {
        if (capitalizeNext && Character.isLetter(c)) {
            phrase += Character.toUpperCase(c);
            capitalizeNext = false;
            continue;
        } else if (Character.isWhitespace(c)) {
            capitalizeNext = true;
        }
        phrase += c;
    }
    return phrase;
}

From source file:xc.mst.services.normalization.NormalizationService.java

/**
 * Creates a new 035 field on the record based on the existing 001 field if
 * there is no 003 field. For example, if 001 = 12345 and the organization
 * code in the configuration file is NRU, the new 035 will be (NRU)12345.
 *
 * @param marcXml/* w  ww.j a  va  2s . co  m*/
 *            The original MARCXML record
 * @return The MARCXML record after performing this normalization step.
 */
private MarcXmlManager supplyMARCOrgCode(MarcXmlManager marcXml) {
    if (LOG.isDebugEnabled())
        LOG.debug("Entering SupplyMARCOrgCode normalization step.");

    // Get the 001 and 003 control fields
    String control001 = marcXml.getField001();

    String control003 = marcXml.getField003();

    // If either control field didn't exist, we don't have to do anything
    if (control003 != null || control001 == null) {
        if (LOG.isDebugEnabled())
            LOG.debug(
                    "The record was missing either an 001 or contained an 003 control field, so we do not have to supply a marc organization code into a new 035 field.");

        return marcXml;
    }

    String new003 = null;

    if (Character.isLetter(control001.charAt(0))) {
        int index = 0;
        StringBuffer s = new StringBuffer();
        while (Character.isLetter(control001.charAt(index))) {
            s.append(control001.charAt(index));
            index++;
        }
        new003 = s.toString();

        control001 = control001.substring(new003.length());
    } else {
        // Add an 003 to the header
        new003 = getOrganizationCode();
    }

    if (LOG.isDebugEnabled())
        LOG.debug("Supplying the record's organization code to a new 003 field with value " + new003 + ".");

    // Add the new 003 field
    marcXml.addMarcXmlControlField("003", new003);
    marcXml.setField003(new003);

    // Create the new 035 field
    String new035 = "(" + getOrganizationCode() + ")" + control001;

    if (LOG.isDebugEnabled())
        LOG.debug("Supplying the record's organization code to a new 035 field with value " + new035 + ".");

    // Add the new 035 field
    marcXml.addMarcXmlField("035", new035);

    return marcXml;
}

From source file:org.ednovo.gooru.domain.service.user.impl.UserServiceImpl.java

@Override
public boolean checkPasswordWithAlphaNumeric(final String password) {
    int letterSize = 0;
    int digitSize = 0;
    for (int i = 0; i < password.length(); i++) {
        if (Character.isDigit(password.charAt(i))) {
            digitSize = digitSize + 1;//from www  .j  a va2s .  co m
        } else if (Character.isLetter(password.charAt(i))) {
            letterSize = letterSize + 1;
        }
    }
    if ((digitSize == 0) || (letterSize == 0)) {
        return true;
    } else {
        return false;
    }
}

From source file:usbong.android.utils.UsbongUtils.java

public static String performSimpleFileEncrypt(int key, String fileData) {
    StringBuffer myFileData = new StringBuffer(fileData.toString());
    StringBuffer encrypted = new StringBuffer();
    int myFileDataLength = fileData.length();
    int myAlphanumericLength = alphanumeric.length;
    boolean isUpperCase = false;

    for (int i = 0; i < myFileDataLength; i++) {
        if (Character.isUpperCase(myFileData.charAt(i))) {
            isUpperCase = true;//from w  ww .  j  av a2  s  .c  o m
        } else {
            isUpperCase = false;
        }

        if (Character.isLetter(myFileData.charAt(i)) || Character.isDigit(myFileData.charAt(i))) {
            for (int k = 0; k < myAlphanumericLength; k++) {
                if (Character.toLowerCase(myFileData.charAt(i)) == alphanumeric[k]) {
                    int counter = (k + key) % myAlphanumericLength; //do a plus
                    if (isUpperCase) {
                        encrypted.append(Character.toUpperCase(alphanumeric[counter]));
                    } else {
                        encrypted.append(alphanumeric[counter]);
                    }
                }
            }
        } else {
            encrypted.append(fileData.charAt(i));
        }
    }
    return encrypted.toString();
}

From source file:usbong.android.utils.UsbongUtils.java

public static String performSimpleFileDecrypt(int key, String fileData) {
    StringBuffer myFileData = new StringBuffer(fileData.toString());
    StringBuffer decoded = new StringBuffer();
    int myFileDataLength = fileData.length();
    int myAlphanumericLength = alphanumeric.length;
    boolean isUpperCase = false;

    for (int i = 0; i < myFileDataLength; i++) {
        if (Character.isUpperCase(myFileData.charAt(i))) {
            isUpperCase = true;/*ww w.ja v a 2 s . co  m*/
        } else {
            isUpperCase = false;
        }

        if (Character.isLetter(myFileData.charAt(i)) || Character.isDigit(myFileData.charAt(i))) {
            for (int k = 0; k < myAlphanumericLength; k++) {
                if (Character.toLowerCase(myFileData.charAt(i)) == alphanumeric[k]) {
                    //Reference: http://stackoverflow.com/questions/11464890/first-char-to-upper-case;
                    //last accessed: 21 Dec. 2013; answered by Jon
                    //                   int counter = ((k-key) % 26 + 26) % 26;
                    int counter = ((k - key) % myAlphanumericLength + myAlphanumericLength)
                            % myAlphanumericLength;
                    if (isUpperCase) {
                        decoded.append(Character.toUpperCase(alphanumeric[counter]));
                    } else {
                        decoded.append(alphanumeric[counter]);
                    }
                }
            }
        } else {
            decoded.append(fileData.charAt(i));
        }
    }
    return decoded.toString();
}