Example usage for java.lang Character isLetterOrDigit

List of usage examples for java.lang Character isLetterOrDigit

Introduction

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

Prototype

public static boolean isLetterOrDigit(int codePoint) 

Source Link

Document

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

Usage

From source file:com.taobao.common.tfs.impl.TfsSession.java

public void setTfsClusterIndex(char tfsClusterIndex) {
    if (Character.isLetterOrDigit(tfsClusterIndex)) {
        this.tfsClusterIndex = tfsClusterIndex;
    }/* w ww  .  j  a  v a2s  . co m*/
}

From source file:com.dell.doradus.db.s3.AmazonS3Service.java

public String encode(String name) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);
        if (c != '_' && Character.isLetterOrDigit(c))
            sb.append(c);//from w  ww.j a  va2 s  .  c o  m
        else {
            String esc = String.format("_%02x", (int) c);
            sb.append(esc);
        }
    }
    return sb.toString();
}

From source file:com.github.jferard.pgloaderutils.sniffer.csv.HeaderRowAnalyzer.java

private int advanceCurFieldStartIndex(String curExpectedField, String line, int curFieldDelimiterBlockIndex,
        int nextFieldFirstLetterIndex) throws IOException {
    final char maybeDelimiter = line.charAt(curFieldDelimiterBlockIndex);
    int nextFieldStartIndex;
    // just a delimiter
    if (nextFieldFirstLetterIndex == curFieldDelimiterBlockIndex + 1) {
        if (Character.isLetterOrDigit(maybeDelimiter))
            throw new IOException("Bad delimiter after field of field:" + curExpectedField + " (" + line + ")");

        this.delimiter = maybeDelimiter;
        nextFieldStartIndex = nextFieldFirstLetterIndex;
    } else {/*from   w  w  w.j  a v a2  s  .c  om*/
        // trim
        int i = curFieldDelimiterBlockIndex;
        while (Character.isSpaceChar(line.charAt(i)))
            i++;

        int j = nextFieldFirstLetterIndex - 1;
        while (Character.isSpaceChar(line.charAt(j)))
            j--;
        if (j > i) { // only space, tabs, ... chars
            if (Character.isLetterOrDigit(maybeDelimiter))
                throw new IOException(
                        "Bad delimiter after field of field:" + curExpectedField + " (" + line + ")");
            this.delimiterCounter.put(maybeDelimiter);
            nextFieldStartIndex = nextFieldFirstLetterIndex;
        } else if (i < j) {
            this.delimiterCounter.put(line.charAt(i));
            this.quoteCounter.put(line.charAt(j));
            nextFieldStartIndex = j;
        } else {
            this.delimiterCounter.put(line.charAt(i));
            nextFieldStartIndex = nextFieldFirstLetterIndex;
        }
    }
    return nextFieldStartIndex;
}

From source file:org.openmicroscopy.shoola.util.ui.search.LuceneQueryBuilder.java

/**
 * Replaces non alpha-numeric characters (excluding underscore) with spaces
 * (which act like OR); will not replace any characters within quotes.
 * /*w  ww  . j  a  va 2 s  .  co m*/
 * @param s
 * @return
 */
private static String replaceNonAlphaNummeric(String s) {

    char[] result = new char[s.length()];

    boolean insideQuotes = false;
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c == '"') {
            insideQuotes = !insideQuotes;
            result[i] = c;
            continue;
        }
        if (!insideQuotes && !Character.isLetterOrDigit(c) && !WILD_CARDS.contains("" + c) && c != '_')
            result[i] = ' ';
        else
            result[i] = c;
    }

    return new String(result);
}

From source file:bboss.org.apache.velocity.runtime.parser.node.NodeUtils.java

/**
 * Utility method to interpolate context variables
 * into string literals. So that the following will
 * work:// w ww .  j a v a 2s .c om
 *
 * #set $name = "candy"
 * $image.getURI("${name}.jpg")
 *
 * And the string literal argument will
 * be transformed into "candy.jpg" before
 * the method is executed.
 * 
 * @deprecated this method isn't called by any class
 * 
 * @param argStr
 * @param vars
 * @return Interpoliation result.
 * @throws MethodInvocationException
 */
public static String interpolate(String argStr, Context vars) throws MethodInvocationException {
    // if there's nothing to replace, skip this (saves buffer allocation)
    if (argStr.indexOf('$') == -1)
        return argStr;

    StrBuilder argBuf = new StrBuilder();

    for (int cIdx = 0, is = argStr.length(); cIdx < is;) {
        char ch = argStr.charAt(cIdx);

        if (ch == '$') {
            StrBuilder nameBuf = new StrBuilder();
            for (++cIdx; cIdx < is; ++cIdx) {
                ch = argStr.charAt(cIdx);
                if (ch == '_' || ch == '-' || Character.isLetterOrDigit(ch))
                    nameBuf.append(ch);
                else if (ch == '{' || ch == '}')
                    continue;
                else
                    break;
            }

            if (nameBuf.length() > 0) {
                Object value = vars.get(nameBuf.toString());

                if (value == null)
                    argBuf.append("$").append(nameBuf.toString());
                else
                    argBuf.append(value.toString());
            }

        } else {
            argBuf.append(ch);
            ++cIdx;
        }
    }

    return argBuf.toString();
}

From source file:com.aelitis.azureus.core.metasearch.Result.java

/**
 * //from  www  .java  2 s.c  o  m
 * @return a value between 0 and 1 representing the rank of the result
 */
public float getRank() {

    int seeds = getNbSeeds();
    int peers = getNbPeers();

    if (seeds < 0) {
        seeds = 0;
    }

    if (peers < 0) {
        peers = 0;
    }

    int totalVirtualPeers = 3 * seeds + peers + 2;

    int superSeeds = getNbSuperSeeds();
    if (superSeeds > 0) {
        totalVirtualPeers += 50 * superSeeds;
    }

    int votes = getVotes();
    if (votes > 0) {
        if (votes > 50) {
            votes = 50;
        }
        totalVirtualPeers += 5 * votes;
    }

    int votesDown = getVotesDown();
    if (votesDown > 0) {
        totalVirtualPeers -= 200 * votesDown;
    }

    if (totalVirtualPeers < 2)
        totalVirtualPeers = 2;

    float rank = (float) (Math.log(totalVirtualPeers) / Math.log(10)) / 5f;

    if (rank > 2f)
        rank = 2f;

    if (isPrivate()) {
        rank /= 2;
    }

    String queryString = getSearchQuery();
    String name = getName();
    if (queryString != null && name != null) {
        name = name.toLowerCase(Locale.ENGLISH);

        String token = "";

        List<String> tokens = new ArrayList<String>();

        char[] chars = queryString.toCharArray();

        for (char c : chars) {

            if (Character.isLetterOrDigit(c)) {

                token += String.valueOf(c).toLowerCase(Locale.ENGLISH);

            } else {

                if (token.length() > 0) {

                    tokens.add(token);

                    token = "";
                }
            }
        }

        if (token.length() > 0) {

            tokens.add(token);
        }

        for (String s : tokens) {
            if (!name.contains(s)) {
                rank /= 2;
            }
        }
    }

    rank = applyRankBias(rank);

    return rank;
}

From source file:org.owasp.jbrofuzz.core.Prototype.java

public static boolean isValidFuzzerID(final String fuzzerID) {

    final int fuzzerLength = fuzzerID.length();

    if (fuzzerLength != 11) {
        return false;
    }//from w w  w  . j  a  v a  2s.com

    if (!Character.isDigit(fuzzerID.charAt(0))) {
        return false;
    }

    if (!Character.isDigit(fuzzerID.charAt(1))) {
        return false;
    }

    if (!Character.isDigit(fuzzerID.charAt(2))) {
        return false;
    }

    if (fuzzerID.charAt(3) != '-') {
        return false;
    }

    if (!Character.isLetterOrDigit(fuzzerID.charAt(4))) {
        return false;
    }

    if (!Character.isLetterOrDigit(fuzzerID.charAt(5))) {
        return false;
    }

    if (!Character.isLetterOrDigit(fuzzerID.charAt(6))) {
        return false;
    }

    if (fuzzerID.charAt(7) != '-') {
        return false;
    }

    if (!Character.isLetterOrDigit(fuzzerID.charAt(8))) {
        return false;
    }

    if (!Character.isLetterOrDigit(fuzzerID.charAt(9))) {
        return false;
    }

    if (!Character.isLetterOrDigit(fuzzerID.charAt(10))) {
        return false;
    }

    return true;

}

From source file:com.mirth.connect.client.ui.components.rsta.ac.js.MirthSourceCompletionProvider.java

@Override
public List<Completion> getCompletionsAt(JTextComponent tc, Point p) {
    Set<Completion> completions = new HashSet<Completion>();
    List<Completion> parentCompletions = super.getCompletionsAt(tc, p);
    if (CollectionUtils.isNotEmpty(parentCompletions)) {
        completions.addAll(parentCompletions);
    }/*from  w ww.j av a2 s  .co m*/

    int offset = tc.viewToModel(p);
    if (offset < 0 || offset >= tc.getDocument().getLength()) {
        lastCompletionsAtText = null;
        lastParameterizedCompletionsAt = null;
        return new ArrayList<Completion>(completions);
    }

    Segment s = new Segment();
    Document doc = tc.getDocument();
    Element root = doc.getDefaultRootElement();
    int line = root.getElementIndex(offset);
    Element elem = root.getElement(line);
    int start = elem.getStartOffset();
    int end = elem.getEndOffset() - 1;

    try {

        doc.getText(start, end - start, s);

        // Get the valid chars before the specified offset.
        int startOffs = s.offset + (offset - start) - 1;
        while (startOffs >= s.offset && Character.isLetterOrDigit(s.array[startOffs])) {
            startOffs--;
        }

        // Get the valid chars at and after the specified offset.
        int endOffs = s.offset + (offset - start);
        while (endOffs < s.offset + s.count && Character.isLetterOrDigit(s.array[endOffs])) {
            endOffs++;
        }

        int len = endOffs - startOffs - 1;
        if (len <= 0) {
            lastParameterizedCompletionsAt = null;
            return new ArrayList<Completion>(completions);
        }
        String text = new String(s.array, startOffs + 1, len);

        if (text.equals(lastCompletionsAtText)) {
            if (CollectionUtils.isNotEmpty(lastParameterizedCompletionsAt)) {
                completions.addAll(lastParameterizedCompletionsAt);
            }
            return new ArrayList<Completion>(completions);
        }

        lastCompletionsAtText = text;
        lastParameterizedCompletionsAt = completionCache.getClassCompletions(tc, text);

        if (CollectionUtils.isNotEmpty(lastParameterizedCompletionsAt)) {
            completions.addAll(lastParameterizedCompletionsAt);
        }
        return new ArrayList<Completion>(completions);

    } catch (BadLocationException ble) {
        ble.printStackTrace(); // Never happens
    }

    lastCompletionsAtText = null;
    lastParameterizedCompletionsAt = null;

    return new ArrayList<Completion>(completions);
}

From source file:org.archive.modules.seeds.TextSeedModule.java

/**
 * Announce all seeds (and nonseed possible-directive lines) from
 * the given Reader//from w w w .ja v a 2s  . c o  m
 * @param reader source of seed/directive lines
 * @param latchOrNull if non-null, sent countDown after each line, allowing 
 * another thread to proceed after a configurable number of lines processed
 */
protected void announceSeedsFromReader(BufferedReader reader, CountDownLatch latchOrNull) {
    String s;
    Iterator<String> iter = new RegexLineIterator(new LineReadingIterator(reader),
            RegexLineIterator.COMMENT_LINE, RegexLineIterator.NONWHITESPACE_ENTRY_TRAILING_COMMENT,
            RegexLineIterator.ENTRY);

    int count = 0;
    while (iter.hasNext()) {
        s = (String) iter.next();
        if (Character.isLetterOrDigit(s.charAt(0))) {
            // consider a likely URI
            seedLine(s);
            count++;
            if (count % 20000 == 0) {
                System.runFinalization();
            }
        } else {
            // report just in case it's a useful directive
            nonseedLine(s);
        }
        if (latchOrNull != null) {
            latchOrNull.countDown();
        }
    }
    publishConcludedSeedBatch();
}

From source file:com.ing.connector.util.WStringUtil.java

/**
 *  generalFormating --> makes the first letter of any character
 *                       string uppercase; otherwise, makes all
 *                       characters lowercase
 *//* w  w  w  .  j  av a  2 s  . c om*/
private String generalFormating(String aString) {
    String lString = aString;
    char lPreviousChar = '\u0000';

    lString = lString.toUpperCase();

    char[] lCharArray = lString.toCharArray();

    for (int i = 0; i < lString.length(); i++) {
        if (Character.isLetterOrDigit(lPreviousChar)) {
            lCharArray[i] = Character.toLowerCase(lCharArray[i]);
        }
        lPreviousChar = lCharArray[i];
    }

    lString = new String(lCharArray);

    return lString;
}