Java Code Examples for jodd.util.StringUtil#count()

The following examples show how to use jodd.util.StringUtil#count() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultClassLoaderStrategy.java    From web-data-extractor with Apache License 2.0 6 votes vote down vote up
/**
 * Prepares classname for loading, respecting the arrays.
 * Returns <code>null</code> if class name is not an array.
 */
public static String prepareArrayClassnameForLoading(String className) {
    int bracketCount = StringUtil.count(className, '[');

    if (bracketCount == 0) {
        // not an array
        return null;
    }

    String brackets = StringUtil.repeat('[', bracketCount);

    int bracketIndex = className.indexOf('[');
    className = className.substring(0, bracketIndex);

    int primitiveNdx = getPrimitiveClassNameIndex(className);
    if (primitiveNdx >= 0) {
        className = String.valueOf(PRIMITIVE_BYTECODE_NAME[primitiveNdx]);

        return brackets + className;
    } else {
        return brackets + 'L' + className + ';';
    }
}
 
Example 2
Source File: DefaultClassLoaderStrategy.java    From web-data-extractor with Apache License 2.0 6 votes vote down vote up
/**
 * Loads array class using component type.
 */
protected Class loadArrayClassByComponentType(String className, ClassLoader classLoader) throws ClassNotFoundException {
    int ndx = className.indexOf('[');
    int multi = StringUtil.count(className, '[');

    String componentTypeName = className.substring(0, ndx);

    Class componentType = loadClass(componentTypeName, classLoader);

    if (multi == 1) {
        return Array.newInstance(componentType, 0).getClass();
    }

    int[] multiSizes;

    if (multi == 2) {
        multiSizes = new int[]{0, 0};
    } else if (multi == 3) {
        multiSizes = new int[]{0, 0, 0};
    } else {
        multiSizes = (int[]) Array.newInstance(int.class, multi);
    }

    return Array.newInstance(componentType, multiSizes).getClass();
}