Example usage for java.lang Character isAlphabetic

List of usage examples for java.lang Character isAlphabetic

Introduction

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

Prototype

public static boolean isAlphabetic(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is an alphabet.

Usage

From source file:com.fizzed.rocker.compiler.RockerUtil.java

static public void appendByteAsJavaByteInitializer(StringBuilder sb, byte b) {
    if (b >= 0 && b < 128) {
        if (Character.isAlphabetic(b)) {
            sb.append("'").append((char) b).append("'");
        } else {// w w  w. j  a  va2 s.co m
            // no cast needed
            sb.append("0x").append(byteArrayToHex(new byte[] { b }));
        }
    } else {
        // cast needed
        sb.append("(byte)0x").append(byteArrayToHex(new byte[] { b }));
    }
}

From source file:com.evolveum.polygon.connector.ldap.ConnectionManager.java

private ServerDefinition selectServer(Dn dn) {
    String stringDn = dn != null ? dn.getName() : null;
    if (StringUtils.isBlank(stringDn) || !Character.isAlphabetic(stringDn.charAt(0))) {
        // Do not even bother to choose. There are the strange
        // things such as empty DN or the <GUID=...> insanity.
        // The selection will not work anyway.
        if (defaultServerDefinition == null) {
            throw new IllegalStateException("No default connection in this connection manager");
        }/*from w ww  .  ja  va2  s .  c om*/
        return defaultServerDefinition;
    }
    Dn selectedBaseContext = null;
    for (ServerDefinition server : servers) {
        Dn serverBaseContext = server.getBaseContext();
        LOG.ok("SELECT: considering {0} ({1}) for {2}", server.getHost(), serverBaseContext, dn);
        if (serverBaseContext == null) {
            continue;
        }
        if (serverBaseContext.equals(dn)) {
            // we cannot get tighter match than this
            selectedBaseContext = dn;
            LOG.ok("SELECT: accepting {0} because {1} is an exact match", server.getHost(), serverBaseContext);
            break;
        }
        if (LdapUtil.isAncestorOf(serverBaseContext, dn, schemaTranslator)) {
            if (serverBaseContext == null || serverBaseContext.isDescendantOf(selectedBaseContext)) {
                LOG.ok("SELECT: accepting {0} because {1} is under {2} and it is the best we have",
                        server.getHost(), dn, serverBaseContext);
                selectedBaseContext = serverBaseContext;
            } else {
                LOG.ok("SELECT: accepting {0} because {1} is under {2} but it is NOT the best we have, {3} is better",
                        server.getHost(), dn, serverBaseContext, selectedBaseContext);
            }
        } else {
            LOG.ok("SELECT: refusing {0} because {1} ({2}) is not under {3} ({4})", server.getHost(), dn,
                    dn.isSchemaAware(), serverBaseContext, serverBaseContext.isSchemaAware());
        }
    }
    LOG.ok("SELECT: selected base context: {0}", selectedBaseContext);
    List<ServerDefinition> selectedServers = new ArrayList<>();
    for (ServerDefinition server : servers) {
        if (selectedBaseContext == null && server.getBaseContext() == null) {
            if (server.getOrigin() == Origin.REFERRAL) {
                // avoid using dynamically added servers as a fallback
                // for all queries
                continue;
            } else {
                selectedServers.add(server);
            }
        }
        if (selectedBaseContext == null || server.getBaseContext() == null) {
            continue;
        }
        if (selectedBaseContext.equals(server.getBaseContext())) {
            selectedServers.add(server);
        }
    }
    LOG.ok("SELECT: selected server list: {0}", selectedServers);
    ServerDefinition selectedServer = selectRandomItem(selectedServers);
    if (selectedServer == null) {
        LOG.ok("SELECT: selected default for {0}", dn);
        if (defaultServerDefinition == null) {
            throw new IllegalStateException("No default connection in this connection manager");
        }
        return defaultServerDefinition;
    } else {
        LOG.ok("SELECT: selected {0} for {1}", selectedServer.getHost(), dn);
        return selectedServer;
    }
}

From source file:com.qwazr.utils.StringUtils.java

public static boolean anyAlpha(CharSequence chars) {
    if (chars == null)
        return false;
    return chars.chars().anyMatch(new IntPredicate() {
        @Override//w  ww. j  a va  2s . c  om
        public boolean test(int value) {
            return Character.isAlphabetic(value);
        }
    });
}

From source file:com.sillelien.dollar.script.DollarLexer.java

public static Parser<?> builtin() {
    return Scanners.pattern(new Pattern() {
        @Override/*from  w w w.j  av  a 2 s.c  o m*/
        public int match(@NotNull CharSequence src, int begin, int end) {
            int i = begin;
            //noinspection StatementWithEmptyBody
            for (; i < end && Character.isAlphabetic(src.charAt(i)); i++) {
                //
            }
            final String name = src.subSequence(begin, i).toString();
            if (Builtins.exists(name)) {
                return i - begin;
            } else {
                return Pattern.MISMATCH;
            }
        }
    }, "builtin").source().map(new Map<String, Tokens.Fragment>() {
        public Tokens.Fragment map(String text) {
            return Tokens.fragment(text, "builtin");
        }

        @NotNull
        @Override
        public String toString() {
            return "builtin";
        }
    });
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v2.KubernetesV2Service.java

default boolean characterAlphanumeric(String value, int index) {
    return Character.isAlphabetic(value.charAt(index)) || Character.isDigit(value.charAt(index));
}

From source file:com.replaymod.replaystudio.launcher.Launcher.java

public void parseConfig(Studio studio, String line, String[] args) {
    String ios = line.substring(1, line.indexOf(')'));
    String instructions = line.substring(line.indexOf(')') + 2, line.length() - 1);

    int arg = 0;/*www. j ava  2  s.  com*/
    try {
        for (String ioi : ios.split(",")) {
            String io = ioi.substring(1);
            if (ioi.charAt(0) == '<') {
                inputs.put(io, args[arg++]);
            } else if (ioi.charAt(0) == '>') {
                outputs.put(io, args[arg++]);
            } else if (ioi.charAt(0) == '-') {
                pipes.add(io);
            } else {
                throw new IllegalArgumentException("Config input/output is invalid: " + ioi);
            }
        }
    } catch (IndexOutOfBoundsException e) {
        System.out.println("Insufficient input/output files. Need at least " + arg);
        throw new CriticalException(7);
    }

    for (String instructionStr : instructions.split(Pattern.quote(")("))) {
        String ins = instructionStr;
        List<String> inputs = new ArrayList<>();
        List<String> outputs = new ArrayList<>();

        // Read inputs
        OUTER: while (true) {
            for (int i = 0; i < ins.length(); i++) {
                char c = ins.charAt(i);
                if (!Character.isAlphabetic(c)) {
                    inputs.add(ins.substring(0, i));
                    if (c == ',') {
                        ins = ins.substring(i + 1);
                        continue OUTER;
                    } else {
                        ins = ins.substring(i);
                        break OUTER;
                    }
                }
            }
            throw new IllegalArgumentException("Config input/output is invalid: " + instructionStr);
        }

        // Read outputs
        OUTER: while (true) {
            for (int i = ins.length() - 1; i >= 0; i--) {
                char c = ins.charAt(i);
                if (!Character.isAlphabetic(c)) {
                    outputs.add(ins.substring(i + 1));
                    if (c == ',') {
                        ins = ins.substring(0, i);
                        continue OUTER;
                    } else {
                        ins = ins.substring(0, i + 1);
                        break OUTER;
                    }
                }
            }
            throw new IllegalArgumentException("Config instruction input/output is invalid: " + instructionStr);
        }
        Collections.reverse(outputs);

        String options = ins.length() > 1 ? ins.substring(1, ins.length() - 1) : "";
        Instruction instruction;
        switch (ins.charAt(0)) {
        case '|': // split
            Collection<Long> splitAt = Collections2.transform(Arrays.asList(options.split(",")),
                    this::timeStampToMillis);
            instruction = new SplitInstruction(Longs.toArray(splitAt));
            break;
        case '&': // append
            instruction = new AppendInstruction();
            break;
        case '[': // squash
            instruction = new SquashInstruction(studio);
            break;
        case ':': // copy
            instruction = new CopyInstruction();
            break;
        case '>': // filter
            String filterName;
            JsonObject filterOptions;
            if (options.contains(",")) {
                String[] parts = options.split(",", 2);
                filterName = parts[0];
                filterOptions = new JsonParser().parse(parts[1]).getAsJsonObject();
            } else {
                filterName = options;
                filterOptions = new JsonObject();
            }
            Filter filter = studio.loadFilter(filterName);
            if (filter == null) {
                throw new IllegalStateException("Filter not found: " + filterName);
            }
            instruction = new FilterInstruction(studio, filter, filterOptions);
            break;
        default:
            throw new IllegalArgumentException("Config instruction is unknown: " + instructionStr);
        }

        instruction.getInputs().addAll(inputs);
        instruction.getOutputs().addAll(outputs);

        this.instructions.add(instruction);
    }
}

From source file:edu.stanford.muse.util.EmailUtils.java

/**
 * normalizes the given person name, by stripping whitespace at either end, normalizes spaces, so exactly 1 space between tokens.
 * returns null if not a valid name or has a banned word/string or is a single word name
 * retains case of the input as is./*from  ww w . j a v a2  s  .  c o  m*/
 * returns same case
 */
public static String cleanPersonName(String name) {
    // be careful with case, we want name to remain in its original case
    if (name == null)
        return null;
    name = name.trim();

    if (name.indexOf("@") >= 0) // an email addr, not a real name -- we dunno what's happening, just return it as is, just lowercasing it.
        return name.toLowerCase();

    // a surprising number of names in email headers start and end with a single quote
    // if so, strip it.
    if (name.startsWith("'") && name.endsWith("'"))
        name = name.substring(1, name.length() - 1);
    if (name.startsWith("\"") && name.endsWith("\""))
        name = name.substring(1, name.length() - 1);

    // check if it has any characters at all
    boolean allNonAlpha = true;
    for (char c : name.toCharArray()) {
        if (Character.isAlphabetic(c)) {
            allNonAlpha = false;
            break;
        }
    }

    // all non-alphabet? return nothing, because its likely a junk name like "(" or "((" (yes, we see plenty of those!)
    if (allNonAlpha)
        return null;

    // Strip stuff inside parens, e.g. sometimes names are like:
    // foo bar (at home) - or -
    // foo bar [some Dept]
    Matcher m1 = parensPattern.matcher(name);
    name = m1.replaceAll("");
    Matcher m2 = sqBracketsPattern.matcher(name);
    name = m2.replaceAll("");
    name = name.trim();

    // normalize spaces
    // return null if name has banned words - e.g. ben s's email has different people with the "name" (IPM Return requested)
    String result = "";
    for (String t : Util.tokenize(name)) {
        if (DictUtils.bannedWordsInPeopleNames.contains(t.toLowerCase())) {
            if (log.isDebugEnabled())
                log.debug("Will not consider name (because it has a banned word): " + name);
            return null;
        }
        result += t + " ";
    }

    result = result.trim(); // very important, we've added a space after the last token above

    String lowerCaseName = name.toLowerCase();
    for (String bannedString : DictUtils.bannedStringsInPeopleNames)
        if (lowerCaseName.indexOf(bannedString) >= 0) {
            if (log.isDebugEnabled()) {
                log.debug("Will not consider name due to banned string: " + name + " due to string: "
                        + bannedString);
            }
            return null;
        }

    if (Util.tokenize(name).size() < 2) {
        return null; // single word names should not be considered for merging
    }

    return result;
}

From source file:edu.stanford.muse.util.Util.java

public static List<String> tokenizeAlphaChars(String s) {
    List<String> result = new ArrayList<String>();
    if (Util.nullOrEmpty(s))
        return result;

    int startIdx = -1;
    char[] chars = s.toCharArray();
    boolean inWord = false;
    for (int i = 0; i < chars.length; i++) {
        boolean isAlphabetic = Character.isAlphabetic(chars[i]);

        if (isAlphabetic && !inWord) {
            inWord = true;/*www . j  a  va  2 s  .  c  o  m*/
            startIdx = i;
        }
        // if alphabetic and inWord, nothing to be done
        if (!isAlphabetic && inWord) {
            result.add(s.substring(startIdx, i)); // i will not be included
        }

        inWord = isAlphabetic;
    }
    if (inWord)
        result.add(s.substring(startIdx));

    return result;
}

From source file:net.yacy.cora.document.id.MultiProtocolURL.java

/**
 * create word tokens for parser. Find CamelCases and separate these words
 * resulting words are not ordered by appearance, but all in sequence
 * @return string with unique tokens/*w w w  . j a  v  a  2s. c om*/
 */
public static String toTokens(final String s) {
    // remove all non-character & non-number
    final StringBuilder sb = new StringBuilder(s.length());
    char c;
    for (int i = 0; i < s.length(); i++) {
        c = s.charAt(i);
        if (Character.isAlphabetic(c) || Character.isDigit(c))
            sb.append(c);
        else
            sb.append(' ');
    }

    // split the string into tokens and add all camel-case splitting
    final String[] u = CommonPattern.SPACES.split(sb);
    final Set<String> token = new LinkedHashSet<String>();
    for (final String r : u)
        token.add(r);
    for (final String r : u)
        token.addAll(parseCamelCase(r));

    // construct a String again
    sb.setLength(0);
    for (final String v : token)
        if (v.length() >= 1)
            sb.append(v).append(' ');
    return sb.length() == 0 ? "" : sb.substring(0, sb.length() - 1);
}

From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java

private static String _stripFullyQualifiedClassNames(String content) throws IOException {

    String imports = JavaImportsFormatter.getImports(content);

    if (Validator.isNull(imports)) {
        return content;
    }//from w  ww  . ja v a 2s.  c o  m

    UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new UnsyncStringReader(imports));

    String line = null;

    while ((line = unsyncBufferedReader.readLine()) != null) {
        int x = line.indexOf("import ");

        if (x == -1) {
            continue;
        }

        String importPackageAndClassName = line.substring(x + 7, line.lastIndexOf(StringPool.SEMICOLON));

        for (x = -1;;) {
            x = content.indexOf(importPackageAndClassName, x + 1);

            if (x == -1) {
                break;
            }

            char nextChar = content.charAt(x + importPackageAndClassName.length());
            char previousChar = content.charAt(x - 1);

            if (Character.isAlphabetic(nextChar) || (nextChar == CharPool.QUOTE)
                    || (nextChar == CharPool.SEMICOLON) || (previousChar == CharPool.QUOTE)) {

                continue;
            }

            String importClassName = importPackageAndClassName
                    .substring(importPackageAndClassName.lastIndexOf(StringPool.PERIOD) + 1);

            content = StringUtil.replaceFirst(content, importPackageAndClassName, importClassName, x);
        }
    }

    return content;
}