Example usage for org.apache.commons.lang CharUtils toIntValue

List of usage examples for org.apache.commons.lang CharUtils toIntValue

Introduction

In this page you can find the example usage for org.apache.commons.lang CharUtils toIntValue.

Prototype

public static int toIntValue(Character ch) 

Source Link

Document

Converts the character to the Integer it represents, throwing an exception if the character is not numeric.

Usage

From source file:org.richfaces.tests.metamer.model.treeAdaptor.KeyConverter.java

public Object getAsObject(FacesContext context, UIComponent component, String value) {
    List<RecursiveNode> list = RichTreeModelRecursiveAdaptorBean.getRootNodesStatically();
    RecursiveNode recursive = null;// www .j a  va  2  s  .  c  o m
    ModelNode model = null;

    char alpha = ' ';
    for (int i = 0; i < value.length(); i++) {
        char ch = value.charAt(i);
        if (CharUtils.isAsciiAlpha(ch)) {
            alpha = ch;
            switch (alpha) {
            case 'M':
                model = recursive.getModel();
                break;
            default:
            }
        }
        if (CharUtils.isAsciiNumeric(ch)) {
            int num = CharUtils.toIntValue(ch);
            switch (alpha) {
            case 'R':
                recursive = list.get(num);
                list = recursive.getRecursiveList();
                break;

            case 'K':
                for (ModelNodeImpl.K key : model.getMap().keySet()) {
                    if (key.number == num) {
                        return key;
                    }
                }
                throw new IllegalStateException();
            default:
            }
        }
    }

    if (Strings.isNullOrEmpty(value)) {
        return null;
    }

    return null;
}