Java Code Examples for org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#intUnbox()

The following examples show how to use org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#intUnbox() . 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: StringGroovyMethods.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * Selects a List of values from a Matcher using a Collection
 * to identify the indices to be selected.
 *
 * @param self    a Matcher
 * @param indices a Collection of indices
 * @return a String of the values at the given indices
 *
 * @since 1.6.0
 */
public static List getAt(final Matcher self, Collection indices) {
    List result = new ArrayList();
    if (indices instanceof IntRange) {
        int size = (int) size(self);
        RangeInfo info = subListBorders(size, (Range) indices);
        indices = new IntRange(((IntRange)indices).getInclusive(), info.from, info.to - 1);
    }
    for (Object value : indices) {
        if (value instanceof Range) {
            result.addAll(getAt(self, (Range) value));
        } else {
            int idx = DefaultTypeTransformation.intUnbox(value);
            result.add(getAt(self, idx));
        }
    }
    return result;
}
 
Example 2
Source File: StringGroovyMethods.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Selects a List of characters from a CharSequence using a Collection
 * to identify the indices to be selected.
 *
 * @param self    a CharSequence
 * @param indices a Collection of indices
 * @return a String consisting of the characters at the given indices
 *
 * @since 1.0
 */
public static String getAt(final CharSequence self, final Collection indices) {
    StringBuilder answer = new StringBuilder();
    for (Object value : indices) {
        if (value instanceof Range) {
            answer.append(getAt(self, (Range) value));
        } else if (value instanceof Collection) {
            answer.append(getAt(self, (Collection) value));
        } else {
            int idx = DefaultTypeTransformation.intUnbox(value);
            answer.append(getAt(self, idx));
        }
    }
    return answer.toString();
}
 
Example 3
Source File: ClosureComparator.java    From groovy with Apache License 2.0 4 votes vote down vote up
public int compare(T object1, T object2) {
    Object value = closure.call(object1, object2);
    return DefaultTypeTransformation.intUnbox(value);
}