Example usage for com.google.common.primitives Chars checkedCast

List of usage examples for com.google.common.primitives Chars checkedCast

Introduction

In this page you can find the example usage for com.google.common.primitives Chars checkedCast.

Prototype

public static char checkedCast(long value) 

Source Link

Document

Returns the char value that is equal to value , if possible.

Usage

From source file:com.google.gerrit.server.util.RegexListSearcher.java

public RegexListSearcher(String re) {
    if (re.startsWith("^")) {
        re = re.substring(1);/* w  w  w.  ja v a  2s. c  o  m*/
    }

    if (re.endsWith("$") && !re.endsWith("\\$")) {
        re = re.substring(0, re.length() - 1);
    }

    Automaton automaton = new RegExp(re).toAutomaton();
    prefixBegin = automaton.getCommonPrefix();
    prefixLen = prefixBegin.length();

    if (0 < prefixLen) {
        char max = Chars.checkedCast(prefixBegin.charAt(prefixLen - 1) + 1);
        prefixEnd = prefixBegin.substring(0, prefixLen - 1) + max;
        prefixOnly = re.equals(prefixBegin + ".*");
    } else {
        prefixEnd = "";
        prefixOnly = false;
    }

    pattern = prefixOnly ? null : new RunAutomaton(automaton);
}