All Downloads are FREE. Search and download functionalities are using the official Maven repository.

webit.script.resolvers.impl.CharSequenceResolver Maven / Gradle / Ivy

// 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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy