public Object getProperty(Object object) { return DefaultGroovyMethods.getAt((Collection) object, name); }
/** * Select a List of items from an array using a Collection to * identify the indices to be selected. * * @param self an array * @param indices a Collection of indices * @return a new list of the values at the given indices * @since 1.0 */ public static <T> List<T> getAt(T[] self, Collection indices) { List<T> answer = new ArrayList<T>(indices.size()); for (Object value : indices) { if (value instanceof Range) { answer.addAll(getAt(self, (Range) value)); } else if (value instanceof Collection) { answer.addAll(getAt(self, (Collection) value)); } else { int idx = DefaultTypeTransformation.intUnbox(value); answer.add(getAtImpl(self, idx)); } } return answer; }
/** * * @param array an Array of Objects * @param range an ObjectRange * @return a range of a list from the range's from index up to but not * including the range's to value * @since 1.0 */ public static <T> List<T> getAt(T[] array, ObjectRange range) { List<T> list = Arrays.asList(array); return getAt(list, range); }
/** * * @param array an Array of Objects * @param range an IntRange * @return a range of a list from the range's from index up to but not * including the range's to value * @since 1.0 */ public static <T> List<T> getAt(T[] array, IntRange range) { List<T> list = Arrays.asList(array); return getAt(list, range); }
/** * Support subscript operator for list access. */ public static <T> T getAt(List<T> self, Number idx) { return getAt(self, idx.intValue()); }
/** * Support the range subscript operator for an Array * * @param array an Array of Objects * @param range a Range * @return a range of a list from the range's from index up to but not * including the range's to value * @since 1.0 */ public static <T> List<T> getAt(T[] array, Range range) { List<T> list = Arrays.asList(array); return getAt(list, range); }
public Object getProperty(Object object) { return DefaultGroovyMethods.getAt(Arrays.asList((Object[]) object), name); }
/** * Support the subscript operator for an Iterable. Typical usage: * <pre class="groovyTestCase"> * // custom Iterable example: * class MyIterable implements Iterable { * Iterator iterator() { [1, 2, 3].iterator() } * } * def myIterable = new MyIterable() * assert myIterable[1] == 2 * * // Set example: * def set = [1,2,3] as LinkedHashSet * assert set[1] == 2 * </pre> * * @param self an Iterable * @param idx an index value (-self.size() <= idx < self.size()) but using -ve index values will be inefficient * @return the value at the given index (after normalisation) or null if no corresponding value was found * @since 2.1.0 */ public static <T> T getAt(Iterable<T> self, int idx) { return getAt(self.iterator(), idx); }
/** * Supports the range subscript operator for a GPathResult. * <pre> * def text = """ * <characterList> * <character>Wallace</character> * <character>Gromit</character> * <character>Shaun</character> * </characterList>""" * * GPathResult characterList = new XmlSlurper().parseText(text) * * assert characterList.character[1..2].join(',') == 'Gromit,Shaun' * </pre> * @param range a Range indicating the items to get * @return a new list based on range borders */ public Object getAt(final IntRange range) { return DefaultGroovyMethods.getAt(list(), range); }
/** * Select a List of items from a List using a Collection to * identify the indices to be selected. * <pre class="groovyTestCase">def list = [true, 1, 3.4, false] * assert list[1,0,2] == [1, true, 3.4]</pre> * * @param self a List * @param indices a Collection of indices * @return a new list of the values at the given indices * @since 1.0 */ public static <T> List<T> getAt(List<T> self, Collection indices) { List<T> answer = new ArrayList<T>(indices.size()); for (Object value : indices) { if (value instanceof Range || value instanceof Collection) { answer.addAll((List<T>)InvokerHelper.invokeMethod(self, "getAt", value)); } else { int idx = DefaultTypeTransformation.intUnbox(value); answer.add(getAt(self, idx)); } } return answer; }
return mc.getProperty(Class.class, object, name, useSuper, false); } else if (object instanceof Collection) { return DefaultGroovyMethods.getAt((Collection) object, name); } else if (object instanceof Object[]) { return DefaultGroovyMethods.getAt(Arrays.asList((Object[]) object), name); } else { MetaMethod addListenerMethod = listeners.get(name);
/** * Select a List of characters from a String using a Collection * to identify the indices to be selected. * * @param self a String * @param indices a Collection of indices * @return a String consisting of the characters at the given indices * @since 1.0 */ public static String getAt(String self, Collection indices) { return (String) getAt((CharSequence) self, indices); }
/** * Support the range subscript operator for CharSequence or StringBuffer with IntRange * * @param text a CharSequence * @param range an IntRange * @return the subsequence CharSequence * @since 1.0 */ public static CharSequence getAt(CharSequence text, IntRange range) { return getAt(text, (Range) range); }
/** * Support the range subscript operator for String with IntRange * * @param text a String * @param range an IntRange * @return the resulting String * @since 1.0 */ public static String getAt(String text, IntRange range) { return getAt(text, (Range) range); }
/** * Support the range subscript operator for String with IntRange * * @param text a String * @param range an IntRange * @return the resulting String * @since 1.0 */ public static String getAt(String text, IntRange range) { return getAt(text, (Range) range); }
/** * Select a List of characters from a String using a Collection * to identify the indices to be selected. * * @param self a String * @param indices a Collection of indices * @return a String consisting of the characters at the given indices * @since 1.0 */ public static String getAt(String self, Collection indices) { return (String) getAt((CharSequence) self, indices); }
/** * Support the range subscript operator for CharSequence or StringBuffer with IntRange * * @param text a CharSequence * @param range an IntRange * @return the subsequence CharSequence */ public static CharSequence getAt(CharSequence text, IntRange range) { return getAt(text, (Range) range); }
/** * * @param array an Array of Objects * @param range an ObjectRange * @return a range of a list from the range's from index up to but not * including the range's to value * @since 1.0 */ public static <T> List<T> getAt(T[] array, ObjectRange range) { List<T> list = Arrays.asList(array); return getAt(list, range); }
/** * * @param array an Array of Objects * @param range an IntRange * @return a range of a list from the range's from index up to but not * including the range's to value * @since 1.0 */ public static <T> List<T> getAt(T[] array, IntRange range) { List<T> list = Arrays.asList(array); return getAt(list, range); }
/** * Support the range subscript operator for an Array * * @param array an Array of Objects * @param range a Range * @return a range of a list from the range's from index up to but not * including the ranges's to value */ public static List getAt(Object[] array, Range range) { List list = Arrays.asList(array); return getAt(list, range); }