Package webit.script.resolvers.impl

Source Code of webit.script.resolvers.impl.CharSequenceResolver

// Copyright (c) 2013-2014, Webit Team. All Rights Reserved.
package webit.script.resolvers.impl;

import webit.script.exceptions.ScriptRuntimeException;
import webit.script.resolvers.GetResolver;
import webit.script.util.StringUtil;

/**
*
* @author Zqq
*/
public class CharSequenceResolver implements GetResolver {

    public Object get(final Object object, final Object property) {
        if (property instanceof Number) {
            try {
                return ((CharSequence) object).charAt(((Number) property).intValue());
            } catch (IndexOutOfBoundsException e) {
                throw new ScriptRuntimeException(StringUtil.concat("index out of bounds:", property));
            }
        }
        if ("length".equals(property) || "size".equals(property)) {
            return ((CharSequence) object).length();
        }
        if ("isEmpty".equals(property)) {
            return ((CharSequence) object).length() == 0;
        }
        throw new ScriptRuntimeException(StringUtil.concat("Invalid property or can't read: java.lang.CharSequence#", property));
    }

    public Class getMatchClass() {
        return CharSequence.class;
    }
}
TOP

Related Classes of webit.script.resolvers.impl.CharSequenceResolver

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.