/** * Attempts to create an Iterator for the given object by first * converting it to a Collection. * * @param a an array * @return an Iterator for the given Array. * @see org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#asCollection(java.lang.Object[]) * @since 1.6.4 */ public static <T> Iterator<T> iterator(T[] a) { return DefaultTypeTransformation.asCollection(a).iterator(); }
/** * Attempts to create an Iterator for the given object by first * converting it to a Collection. * * @param o an object * @return an Iterator for the given Object. * @see org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#asCollection(java.lang.Object) * @since 1.0 */ public static Iterator iterator(Object o) { return DefaultTypeTransformation.asCollection(o).iterator(); }
public static Object asArray(Object object, Class type) { if (type.isAssignableFrom(object.getClass())) { return object; } Collection list = asCollection(object); int size = list.size(); Class elementType = type.getComponentType(); Object array = Array.newInstance(elementType, size); int idx = 0; for (Iterator iter = list.iterator(); iter.hasNext(); idx++) { Object element = iter.next(); Array.set(array, idx, castToType(element, elementType)); } return array; }
/** * Method for overloading the behavior of the 'case' method in switch statements. * The default implementation handles arrays types but otherwise simply delegates * to Object#equals, but this may be overridden for other types. In this example: * <pre> switch( a ) { * case b: //some code * }</pre> * "some code" is called when <code>b.isCase( a )</code> returns * <code>true</code>. * * @param caseValue the case value * @param switchValue the switch value * @return true if the switchValue is deemed to be equal to the caseValue * @since 1.0 */ public static boolean isCase(Object caseValue, Object switchValue) { if (caseValue.getClass().isArray()) { return isCase(DefaultTypeTransformation.asCollection(caseValue), switchValue); } return caseValue.equals(switchValue); }
List collectedCombos = new ArrayList(); for (Object collection : collections) { Iterable items = DefaultTypeTransformation.asCollection(collection); if (collectedCombos.isEmpty()) { for (Object item : items) {
public Integer mockCallWithOneCollectionParam(Object collection) { Collection coll = DefaultTypeTransformation.asCollection(collection); return new Integer(coll.size()); }
return object; Collection list = DefaultTypeTransformation.asCollection(object); int size = list.size(); Class elementType = type.getComponentType();
/** * Asserts that the given object can be converted into a collection and iterator * of the given size */ protected void assertAsCollection(Object collectionObject, int count) { Collection collection = DefaultTypeTransformation.asCollection(collectionObject); assertTrue("Collection is not null", collection != null); assertEquals("Collection size", count, collection.size()); assertIterator("collections iterator", collection.iterator(), count); assertIterator("InvokerHelper.asIterator", InvokerHelper.asIterator(collectionObject), count); assertIterator("InvokerHelper.asIterator(InvokerHelper.asCollection)", InvokerHelper.asIterator(collection), count); assertIterator("InvokerHelper.asIterator(InvokerHelper.asIterator)", InvokerHelper.asIterator(InvokerHelper.asIterator(collectionObject)), count); }
/** * Attempts to create an Iterator for the given object by first * converting it to a Collection. * * @param o an object * @return an Iterator for the given Object. * @see DefaultTypeTransformation#asCollection(Object) */ public static Iterator iterator(Object o) { return DefaultTypeTransformation.asCollection(o).iterator(); }
/** * Attempts to create an Iterator for the given object by first * converting it to a Collection. * * @param a an array * @return an Iterator for the given Array. * @see org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#asCollection(java.lang.Object[]) * @since 1.6.4 */ public static <T> Iterator<T> iterator(T[] a) { return DefaultTypeTransformation.asCollection(a).iterator(); }
/** * Attempts to create an Iterator for the given object by first * converting it to a Collection. * * @param o an object * @return an Iterator for the given Object. * @see org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#asCollection(java.lang.Object) * @since 1.0 */ public static Iterator iterator(Object o) { return DefaultTypeTransformation.asCollection(o).iterator(); }
/** * Attempts to create an Iterator for the given object by first * converting it to a Collection. * * @param o an object * @return an Iterator for the given Object. * @see DefaultTypeTransformation#asCollection(Object) * @since 1.0 */ public static Iterator iterator(Object o) { return DefaultTypeTransformation.asCollection(o).iterator(); }
/** * Attempts to create an Iterator for the given object by first * converting it to a Collection. * * @param a an array * @return an Iterator for the given Array. * @see DefaultTypeTransformation#asCollection(Object[]) * @since 1.6.4 */ public static <T> Iterator<T> iterator(T[] a) { return DefaultTypeTransformation.asCollection(a).iterator(); }
/** * Attempts to create an Iterator for the given object by first * converting it to a Collection. * * @param o an object * @return an Iterator for the given Object. * @see DefaultTypeTransformation#asCollection(Object) * @since 1.0 */ public static Iterator iterator(Object o) { return DefaultTypeTransformation.asCollection(o).iterator(); }
/** * Method for overloading the behavior of the 'case' method in switch statements. * The default implementation handles arrays types but otherwise simply delegates * to Object#equals, but this may be overridden for other types. In this example: * <pre> switch( a ) { * case b: //some code * }</pre> * "some code" is called when <code>b.isCase( a )</code> returns * <code>true</code>. * * @param caseValue the case value * @param switchValue the switch value * @return true if the switchValue is deemed to be equal to the caseValue */ public static boolean isCase(Object caseValue, Object switchValue) { if (caseValue.getClass().isArray()) { return isCase(DefaultTypeTransformation.asCollection(caseValue), switchValue); } return caseValue.equals(switchValue); }
/** * Method for overloading the behavior of the 'case' method in switch statements. * The default implementation handles arrays types but otherwise simply delegates * to Object#equals, but this may be overridden for other types. In this example: * <pre> switch( a ) { * case b: //some code * }</pre> * "some code" is called when <code>b.isCase( a )</code> returns * <code>true</code>. * * @param caseValue the case value * @param switchValue the switch value * @return true if the switchValue is deemed to be equal to the caseValue * @since 1.0 */ public static boolean isCase(Object caseValue, Object switchValue) { if (caseValue.getClass().isArray()) { return isCase(DefaultTypeTransformation.asCollection(caseValue), switchValue); } return caseValue.equals(switchValue); }
/** * Method for overloading the behavior of the 'case' method in switch statements. * The default implementation handles arrays types but otherwise simply delegates * to Object#equals, but this may be overridden for other types. In this example: * <pre> switch( a ) { * case b: //some code * }</pre> * "some code" is called when <code>b.isCase( a )</code> returns * <code>true</code>. * * @param caseValue the case value * @param switchValue the switch value * @return true if the switchValue is deemed to be equal to the caseValue * @since 1.0 */ public static boolean isCase(Object caseValue, Object switchValue) { if (caseValue.getClass().isArray()) { return isCase(DefaultTypeTransformation.asCollection(caseValue), switchValue); } return caseValue.equals(switchValue); }
/** * Method for overloading the behavior of the 'case' method in switch statements. * The default implementation handles arrays types but otherwise simply delegates * to Object#equals, but this may be overridden for other types. In this example: * <pre> switch( a ) { * case b: //some code * }</pre> * "some code" is called when <code>b.isCase( a )</code> returns * <code>true</code>. * * @param caseValue the case value * @param switchValue the switch value * @return true if the switchValue is deemed to be equal to the caseValue * @since 1.0 */ public static boolean isCase(Object caseValue, Object switchValue) { if (caseValue.getClass().isArray()) { return isCase(DefaultTypeTransformation.asCollection(caseValue), switchValue); } return caseValue.equals(switchValue); }
List collectedCombos = new ArrayList(); for (Iterator outer = collections.iterator(); outer.hasNext();) { Collection items = DefaultTypeTransformation.asCollection(outer.next()); if (collectedCombos.isEmpty()) { for (Iterator iterator = items.iterator(); iterator.hasNext();) {
return format(DefaultTypeTransformation.asCollection(arguments), verbose);