idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
6,300
E unlinkFirst ( ) { final E f = first ; final E next = f . getNext ( ) ; f . setNext ( null ) ; first = next ; if ( next == null ) { last = null ; } else { next . setPrevious ( null ) ; } return f ; }
Unlinks the non - null first element .
6,301
E unlinkLast ( ) { final E l = last ; final E prev = l . getPrevious ( ) ; l . setPrevious ( null ) ; last = prev ; if ( prev == null ) { first = null ; } else { prev . setNext ( null ) ; } return l ; }
Unlinks the non - null last element .
6,302
private Object callGlobal ( String name , Object [ ] args ) { return callGlobal ( name , args , context ) ; }
call the script global function of the given name
6,303
private static ClassLoader getParentLoader ( ) { ClassLoader ctxtLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; try { Class < ? > c = ctxtLoader . loadClass ( Script . class . getName ( ) ) ; if ( c == Script . class ) { return ctxtLoader ; } } catch ( ClassNotFoundException cnfe ) { } return Script . class . getClassLoader ( ) ; }
for GroovyClassLoader instance
6,304
public static String dump ( Object self ) { if ( self == null ) { return "null" ; } StringBuilder buffer = new StringBuilder ( "<" ) ; Class klass = self . getClass ( ) ; buffer . append ( klass . getName ( ) ) ; buffer . append ( "@" ) ; buffer . append ( Integer . toHexString ( self . hashCode ( ) ) ) ; boolean groovyObject = self instanceof GroovyObject ; while ( klass != null ) { for ( final Field field : klass . getDeclaredFields ( ) ) { if ( ( field . getModifiers ( ) & Modifier . STATIC ) == 0 ) { if ( groovyObject && field . getName ( ) . equals ( "metaClass" ) ) { continue ; } AccessController . doPrivileged ( new PrivilegedAction ( ) { public Object run ( ) { field . setAccessible ( true ) ; return null ; } } ) ; buffer . append ( " " ) ; buffer . append ( field . getName ( ) ) ; buffer . append ( "=" ) ; try { buffer . append ( InvokerHelper . toString ( field . get ( self ) ) ) ; } catch ( Exception e ) { buffer . append ( e ) ; } } } klass = klass . getSuperclass ( ) ; } buffer . append ( ">" ) ; return buffer . toString ( ) ; }
Generates a detailed dump string of an object showing its class hashCode and fields .
6,305
public static < T > T use ( Object self , Class categoryClass , Closure < T > closure ) { return GroovyCategorySupport . use ( categoryClass , closure ) ; }
Scoped use method
6,306
public static void mixin ( MetaClass self , List < Class > categoryClasses ) { MixinInMetaClass . mixinClassesToMetaClass ( self , categoryClasses ) ; }
Extend object with category methods . All methods for given class and all super classes will be added to the object .
6,307
public static void mixin ( Class self , List < Class > categoryClasses ) { mixin ( getMetaClass ( self ) , categoryClasses ) ; }
Extend class globally with category methods . All methods for given class and all super classes will be added to the class .
6,308
public static < T > T use ( Object self , List < Class > categoryClassList , Closure < T > closure ) { return GroovyCategorySupport . use ( categoryClassList , closure ) ; }
Scoped use method with list of categories .
6,309
public static void addShutdownHook ( Object self , Closure closure ) { Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( closure ) ) ; }
Allows the usage of addShutdownHook without getting the runtime first .
6,310
public static void print ( Object self , Object value ) { if ( self instanceof Writer ) { try { ( ( Writer ) self ) . write ( InvokerHelper . toString ( value ) ) ; } catch ( IOException e ) { } } else { System . out . print ( InvokerHelper . toString ( value ) ) ; } }
Print a value formatted Groovy style to self if it is a Writer otherwise to the standard output stream .
6,311
public static void print ( PrintWriter self , Object value ) { self . print ( InvokerHelper . toString ( value ) ) ; }
Print a value formatted Groovy style to the print writer .
6,312
public static void print ( PrintStream self , Object value ) { self . print ( InvokerHelper . toString ( value ) ) ; }
Print a value formatted Groovy style to the print stream .
6,313
public static void println ( Object self ) { if ( self instanceof Writer ) { PrintWriter pw = new GroovyPrintWriter ( ( Writer ) self ) ; pw . println ( ) ; } else { System . out . println ( ) ; } }
Print a linebreak to the standard output stream .
6,314
public static void println ( Closure self ) { Object owner = getClosureOwner ( self ) ; InvokerHelper . invokeMethod ( owner , "println" , EMPTY_OBJECT_ARRAY ) ; }
Print a linebreak to the standard output stream . This method delegates to the owner to execute the method .
6,315
public static void printf ( Object self , String format , Object [ ] values ) { if ( self instanceof PrintStream ) ( ( PrintStream ) self ) . printf ( format , values ) ; else System . out . printf ( format , values ) ; }
Printf to the standard output stream .
6,316
public static void printf ( Closure self , String format , Object [ ] values ) { Object owner = getClosureOwner ( self ) ; Object [ ] newValues = new Object [ values . length + 1 ] ; newValues [ 0 ] = format ; System . arraycopy ( values , 0 , newValues , 1 , values . length ) ; InvokerHelper . invokeMethod ( owner , "printf" , newValues ) ; }
Printf 0 or more values to the standard output stream using a format string . This method delegates to the owner to execute the method .
6,317
public static void printf ( Closure self , String format , Object value ) { Object owner = getClosureOwner ( self ) ; Object [ ] newValues = new Object [ 2 ] ; newValues [ 0 ] = format ; newValues [ 1 ] = value ; InvokerHelper . invokeMethod ( owner , "printf" , newValues ) ; }
Printf a value to the standard output stream using a format string . This method delegates to the owner to execute the method .
6,318
public static String sprintf ( Object self , String format , Object [ ] values ) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ; PrintStream out = new PrintStream ( outputStream ) ; out . printf ( format , values ) ; return outputStream . toString ( ) ; }
Sprintf to a string .
6,319
public static void print ( Object self , PrintWriter out ) { if ( out == null ) { out = new PrintWriter ( System . out ) ; } out . print ( InvokerHelper . toString ( self ) ) ; }
Print to a console in interactive format .
6,320
public static Object invokeMethod ( Object object , String method , Object arguments ) { return InvokerHelper . invokeMethod ( object , method , arguments ) ; }
Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily .
6,321
public static < T > Iterator < T > unique ( Iterator < T > self ) { return uniqueItems ( new IteratorIterableAdapter < T > ( self ) ) . listIterator ( ) ; }
Returns an iterator equivalent to this iterator with all duplicated items removed by using Groovy s default number - aware comparator . The original iterator will become exhausted of elements after determining the unique values . A new iterator for the unique values will be returned .
6,322
public static < T > Iterator < T > unique ( Iterator < T > self , Comparator < T > comparator ) { return uniqueItems ( new IteratorIterableAdapter < T > ( self ) , comparator ) . listIterator ( ) ; }
Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator . The original iterator will be exhausted upon returning .
6,323
public static < T > Iterable < T > each ( Iterable < T > self , @ ClosureParams ( FirstParam . FirstGenericType . class ) Closure closure ) { each ( self . iterator ( ) , closure ) ; return self ; }
Iterates through an Iterable passing each item to the given closure .
6,324
public static < T > Iterator < T > each ( Iterator < T > self , @ ClosureParams ( FirstParam . FirstGenericType . class ) Closure closure ) { while ( self . hasNext ( ) ) { Object arg = self . next ( ) ; closure . call ( arg ) ; } return self ; }
Iterates through an Iterator passing each item to the given closure .
6,325
public static < T > SortedSet < T > each ( SortedSet < T > self , @ ClosureParams ( FirstParam . FirstGenericType . class ) Closure closure ) { return ( SortedSet < T > ) each ( ( Iterable < T > ) self , closure ) ; }
Iterates through a SortedSet passing each item to the given closure .
6,326
public static < K , V > Map < K , V > reverseEach ( Map < K , V > self , @ ClosureParams ( MapEntryOrKeyValue . class ) Closure closure ) { final Iterator < Map . Entry < K , V > > entries = reverse ( self . entrySet ( ) . iterator ( ) ) ; while ( entries . hasNext ( ) ) { callClosureForMapEntry ( closure , entries . next ( ) ) ; } return self ; }
Allows a Map to be iterated through in reverse order using a closure .
6,327
public static < T > T [ ] reverseEach ( T [ ] self , @ ClosureParams ( FirstParam . Component . class ) Closure closure ) { each ( new ReverseListIterator < T > ( Arrays . asList ( self ) ) , closure ) ; return self ; }
Iterate over each element of the array in the reverse order .
6,328
public static < T > Number count ( T [ ] self , @ ClosureParams ( FirstParam . Component . class ) Closure closure ) { return count ( ( Iterable ) Arrays . asList ( self ) , closure ) ; }
Counts the number of occurrences which satisfy the given closure from inside this array .
6,329
public static < T > List < T > toList ( Iterator < T > self ) { List < T > answer = new ArrayList < T > ( ) ; while ( self . hasNext ( ) ) { answer . add ( self . next ( ) ) ; } return answer ; }
Convert an iterator to a List . The iterator will become exhausted of elements after making this conversion .
6,330
public static < T > List < T > toList ( Enumeration < T > self ) { List < T > answer = new ArrayList < T > ( ) ; while ( self . hasMoreElements ( ) ) { answer . add ( self . nextElement ( ) ) ; } return answer ; }
Convert an enumeration to a List .
6,331
public static < K , V , E > Map < K , V > collectEntries ( Iterator < E > self , @ ClosureParams ( FirstParam . FirstGenericType . class ) Closure < ? > transform ) { return collectEntries ( self , new LinkedHashMap < K , V > ( ) , transform ) ; }
A variant of collectEntries for Iterators .
6,332
public static < K , V > Map < K , V > collectEntries ( Iterator < ? > self ) { return collectEntries ( self , Closure . IDENTITY ) ; }
A variant of collectEntries for Iterators using the identity closure as the transform .
6,333
public static < K , V , E > Map < K , V > collectEntries ( Iterator < E > self , Map < K , V > collector , @ ClosureParams ( FirstParam . FirstGenericType . class ) Closure < ? > transform ) { while ( self . hasNext ( ) ) { E next = self . next ( ) ; addEntry ( collector , transform . call ( next ) ) ; } return collector ; }
A variant of collectEntries for Iterators using a supplied map as the destination of transformed entries .
6,334
public static < K , V > Map < K , V > collectEntries ( Iterable < ? > self , Map < K , V > collector ) { return collectEntries ( self . iterator ( ) , collector ) ; }
A variant of collectEntries for Iterables using the identity closure as the transform and a supplied map as the destination of transformed entries .
6,335
public static Object find ( Object self , Closure closure ) { BooleanClosureWrapper bcw = new BooleanClosureWrapper ( closure ) ; for ( Iterator iter = InvokerHelper . asIterator ( self ) ; iter . hasNext ( ) ; ) { Object value = iter . next ( ) ; if ( bcw . call ( value ) ) { return value ; } } return null ; }
Finds the first value matching the closure condition .
6,336
public static < S , T , U extends T , V extends T > T findResult ( Collection < S > self , U defaultResult , @ ClosureParams ( FirstParam . FirstGenericType . class ) Closure < V > condition ) { return findResult ( ( Iterable < S > ) self , defaultResult , condition ) ; }
Iterates through the collection calling the given closure for each item but stopping once the first non - null result is found and returning that result . If all are null the defaultResult is returned .
6,337
public static < T , U > T findResult ( Iterator < U > self , @ ClosureParams ( FirstParam . FirstGenericType . class ) Closure < T > condition ) { while ( self . hasNext ( ) ) { U next = self . next ( ) ; T result = condition . call ( next ) ; if ( result != null ) { return result ; } } return null ; }
Iterates through the Iterator calling the given closure condition for each item but stopping once the first non - null result is found and returning that result . If all results are null null is returned .
6,338
public static < T , U > T findResult ( Iterable < U > self , @ ClosureParams ( FirstParam . FirstGenericType . class ) Closure < T > condition ) { return findResult ( self . iterator ( ) , condition ) ; }
Iterates through the Iterable calling the given closure condition for each item but stopping once the first non - null result is found and returning that result . If all results are null null is returned .
6,339
public static < S , T , U extends T , V extends T > T findResult ( S [ ] self , U defaultResult , @ ClosureParams ( FirstParam . Component . class ) Closure < V > condition ) { return findResult ( new ArrayIterator < S > ( self ) , defaultResult , condition ) ; }
Iterates through the Array calling the given closure condition for each item but stopping once the first non - null result is found and returning that result . If all are null the defaultResult is returned .
6,340
public static < S , T > T findResult ( S [ ] self , @ ClosureParams ( FirstParam . Component . class ) Closure < T > condition ) { return findResult ( new ArrayIterator < S > ( self ) , condition ) ; }
Iterates through the Array calling the given closure condition for each item but stopping once the first non - null result is found and returning that result . If all results are null null is returned .
6,341
public static < T , U > Collection < T > findResults ( Iterator < U > self , @ ClosureParams ( FirstParam . FirstGenericType . class ) Closure < T > filteringTransform ) { List < T > result = new ArrayList < T > ( ) ; while ( self . hasNext ( ) ) { U value = self . next ( ) ; T transformed = filteringTransform . call ( value ) ; if ( transformed != null ) { result . add ( transformed ) ; } } return result ; }
Iterates through the Iterator transforming items using the supplied closure and collecting any non - null results .
6,342
public static < T , U > Collection < T > findResults ( U [ ] self , @ ClosureParams ( FirstParam . Component . class ) Closure < T > filteringTransform ) { return findResults ( new ArrayIterator < U > ( self ) , filteringTransform ) ; }
Iterates through the Array transforming items using the supplied closure and collecting any non - null results .
6,343
public static Collection findAll ( Object self , Closure closure ) { List answer = new ArrayList ( ) ; Iterator iter = InvokerHelper . asIterator ( self ) ; return findAll ( closure , answer , iter ) ; }
Finds all items matching the closure condition .
6,344
public static boolean removeAll ( Collection self , Object [ ] items ) { Collection pickFrom = new TreeSet ( new NumberAwareComparator ( ) ) ; pickFrom . addAll ( Arrays . asList ( items ) ) ; return self . removeAll ( pickFrom ) ; }
Modifies this collection by removing its elements that are contained within the specified object array .
6,345
public static < T > boolean retainAll ( Collection < T > self , @ ClosureParams ( FirstParam . FirstGenericType . class ) Closure condition ) { Iterator iter = InvokerHelper . asIterator ( self ) ; BooleanClosureWrapper bcw = new BooleanClosureWrapper ( condition ) ; boolean result = false ; while ( iter . hasNext ( ) ) { Object value = iter . next ( ) ; if ( ! bcw . call ( value ) ) { iter . remove ( ) ; result = true ; } } return result ; }
Modifies this collection so that it retains only its elements that are matched according to the specified closure condition . In other words removes from this collection all of its elements that don t match .
6,346
public static < T > boolean addAll ( Collection < T > self , T [ ] items ) { return self . addAll ( Arrays . asList ( items ) ) ; }
Modifies the collection by adding all of the elements in the specified array to the collection . The behavior of this operation is undefined if the specified array is modified while the operation is in progress .
6,347
public static Collection split ( Object self , Closure closure ) { List accept = new ArrayList ( ) ; List reject = new ArrayList ( ) ; return split ( closure , accept , reject , InvokerHelper . asIterator ( self ) ) ; }
Splits all items into two lists based on the closure condition . The first list contains all items matching the closure expression . The second list all those that don t .
6,348
public static < T > Collection < Collection < T > > split ( T [ ] self , @ ClosureParams ( FirstParam . Component . class ) Closure closure ) { List < T > accept = new ArrayList < T > ( ) ; List < T > reject = new ArrayList < T > ( ) ; Iterator < T > iter = new ArrayIterator < T > ( self ) ; return split ( closure , accept , reject , iter ) ; }
Splits all items into two collections based on the closure condition . The first list contains all items which match the closure expression . The second list all those that don t .
6,349
public static Object sum ( Iterator < Object > self ) { return sum ( toList ( self ) , null , true ) ; }
Sums the items from an Iterator . This is equivalent to invoking the plus method on all items from the Iterator . The iterator will become exhausted of elements after determining the sum value .
6,350
public static Object sum ( Object [ ] self , Object initialValue ) { return sum ( toList ( self ) , initialValue , false ) ; }
Sums the items in an array adding the result to some initial value .
6,351
public static < T > T min ( Iterator < T > self , Comparator < T > comparator ) { return min ( ( Iterable < T > ) toList ( self ) , comparator ) ; }
Selects the minimum value found from the Iterator using the given comparator .
6,352
public static < T > T max ( Iterator < T > self , Comparator < T > comparator ) { return max ( ( Iterable < T > ) toList ( self ) , comparator ) ; }
Selects the maximum value found from the Iterator using the given comparator .
6,353
public static < T > List < T > getAt ( T [ ] array , Range range ) { List < T > list = Arrays . asList ( array ) ; return getAt ( list , range ) ; }
Support the range subscript operator for an Array
6,354
public static < T > List < T > toList ( T [ ] array ) { return new ArrayList < T > ( Arrays . asList ( array ) ) ; }
Allows conversion of arrays into a mutable List .
6,355
public static < T > T getAt ( List < T > self , Number idx ) { return getAt ( self , idx . intValue ( ) ) ; }
Support subscript operator for list access .
6,356
public static < T > void putAt ( List < T > self , Number idx , T value ) { putAt ( self , idx . intValue ( ) , value ) ; }
Support subscript operator for list modification .
6,357
public static < K , V > V putAt ( Map < K , V > self , K key , V value ) { self . put ( key , value ) ; return value ; }
A helper method to allow maps to work with subscript operators
6,358
public static < K , V > Map < K , V > asImmutable ( Map < K , V > self ) { return asUnmodifiable ( new LinkedHashMap < K , V > ( self ) ) ; }
A convenience method for creating an immutable Map .
6,359
public static < K , V > SortedMap < K , V > asImmutable ( SortedMap < K , V > self ) { return asUnmodifiable ( new TreeMap < K , V > ( self ) ) ; }
A convenience method for creating an immutable SortedMap .
6,360
public static < T > Set < T > asImmutable ( Set < T > self ) { return asUnmodifiable ( new LinkedHashSet < T > ( self ) ) ; }
A convenience method for creating an immutable Set .
6,361
public static < T > SortedSet < T > asImmutable ( SortedSet < T > self ) { return asUnmodifiable ( new TreeSet < T > ( self ) ) ; }
A convenience method for creating an immutable SortedSet .
6,362
public static < T > Collection < T > asImmutable ( Collection < T > self ) { return asUnmodifiable ( ( Collection < T > ) new ArrayList < T > ( self ) ) ; }
A convenience method for creating an immutable Collection .
6,363
public static < K , V > Map < K , V > asUnmodifiable ( Map < K , V > self ) { return Collections . unmodifiableMap ( self ) ; }
Creates an unmodifiable view of a Map .
6,364
public static < K , V > SortedMap < K , V > asUnmodifiable ( SortedMap < K , V > self ) { return Collections . unmodifiableSortedMap ( self ) ; }
Creates an unmodifiable view of a SortedMap .
6,365
public static < T > Set < T > asUnmodifiable ( Set < T > self ) { return Collections . unmodifiableSet ( self ) ; }
Creates an unmodifiable view of a Set .
6,366
public static < T > SortedSet < T > asUnmodifiable ( SortedSet < T > self ) { return Collections . unmodifiableSortedSet ( self ) ; }
Creates an unmodifiable view of a SortedSet .
6,367
public static < T > Collection < T > asUnmodifiable ( Collection < T > self ) { return Collections . unmodifiableCollection ( self ) ; }
Creates an unmodifiable view of a Collection .
6,368
public static < K , V > Map < K , V > asSynchronized ( Map < K , V > self ) { return Collections . synchronizedMap ( self ) ; }
A convenience method for creating a synchronized Map .
6,369
public static < K , V > SortedMap < K , V > asSynchronized ( SortedMap < K , V > self ) { return Collections . synchronizedSortedMap ( self ) ; }
A convenience method for creating a synchronized SortedMap .
6,370
public static < T > Collection < T > asSynchronized ( Collection < T > self ) { return Collections . synchronizedCollection ( self ) ; }
A convenience method for creating a synchronized Collection .
6,371
public static < T > List < T > asSynchronized ( List < T > self ) { return Collections . synchronizedList ( self ) ; }
A convenience method for creating a synchronized List .
6,372
public static < T > Set < T > asSynchronized ( Set < T > self ) { return Collections . synchronizedSet ( self ) ; }
A convenience method for creating a synchronized Set .
6,373
public static < T > SortedSet < T > asSynchronized ( SortedSet < T > self ) { return Collections . synchronizedSortedSet ( self ) ; }
A convenience method for creating a synchronized SortedSet .
6,374
public static < T > T [ ] sort ( T [ ] self ) { Arrays . sort ( self , new NumberAwareComparator < T > ( ) ) ; return self ; }
Modifies this array so that its elements are in sorted order . The array items are assumed to be comparable .
6,375
public static < T > Iterator < T > sort ( Iterator < T > self ) { return sort ( ( Iterable < T > ) toList ( self ) ) . listIterator ( ) ; }
Sorts the given iterator items into a sorted iterator . The items are assumed to be comparable . The original iterator will become exhausted of elements after completing this method call . A new iterator is produced that traverses the items in sorted order .
6,376
public static < T > Iterator < T > sort ( Iterator < T > self , Comparator < ? super T > comparator ) { return sort ( ( Iterable < T > ) toList ( self ) , true , comparator ) . listIterator ( ) ; }
Sorts the given iterator items into a sorted iterator using the comparator . The original iterator will become exhausted of elements after completing this method call . A new iterator is produced that traverses the items in sorted order .
6,377
public static < T > Iterator < T > toSorted ( Iterator < T > self , Comparator < T > comparator ) { return toSorted ( toList ( self ) , comparator ) . listIterator ( ) ; }
Sorts the given iterator items using the comparator . The original iterator will become exhausted of elements after completing this method call . A new iterator is produced that traverses the items in sorted order .
6,378
public static < T > Set < T > toSorted ( SortedSet < T > self ) { return new LinkedHashSet < T > ( self ) ; }
Avoids doing unnecessary work when sorting an already sorted set
6,379
public static < K , V > Map < K , V > toSorted ( SortedMap < K , V > self ) { return new LinkedHashMap < K , V > ( self ) ; }
Avoids doing unnecessary work when sorting an already sorted map
6,380
public static < T > T pop ( List < T > self ) { if ( self . isEmpty ( ) ) { throw new NoSuchElementException ( "Cannot pop() an empty List" ) ; } return self . remove ( 0 ) ; }
Removes the initial item from the List .
6,381
public static < T > T removeLast ( List < T > self ) { if ( self . isEmpty ( ) ) { throw new NoSuchElementException ( "Cannot removeLast() an empty List" ) ; } return self . remove ( self . size ( ) - 1 ) ; }
Removes the last item from the List .
6,382
public static < K , V > Map < K , V > putAll ( Map < K , V > self , Collection < ? extends Map . Entry < ? extends K , ? extends V > > entries ) { for ( Map . Entry < ? extends K , ? extends V > entry : entries ) { self . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } return self ; }
Provides an easy way to append multiple Map . Entry values to a Map .
6,383
public static < T > boolean push ( List < T > self , T value ) { self . add ( 0 , value ) ; return true ; }
Prepends an item to the start of the List .
6,384
public static < T > Iterator < T > tail ( Iterator < T > self ) { if ( ! self . hasNext ( ) ) { throw new NoSuchElementException ( "Cannot access tail() for an empty Iterator" ) ; } self . next ( ) ; return self ; }
Returns the original iterator after throwing away the first element .
6,385
@ SuppressWarnings ( "unchecked" ) public static < T > T asType ( Iterable iterable , Class < T > clazz ) { if ( Collection . class . isAssignableFrom ( clazz ) ) { return asType ( ( Collection ) toList ( iterable ) , clazz ) ; } return asType ( ( Object ) iterable , clazz ) ; }
Converts the given iterable to another type .
6,386
@ SuppressWarnings ( "unchecked" ) public static < T > T asType ( Closure cl , Class < T > clazz ) { if ( clazz . isInterface ( ) && ! ( clazz . isInstance ( cl ) ) ) { if ( Traits . isTrait ( clazz ) ) { Method samMethod = CachedSAMClass . getSAMMethod ( clazz ) ; if ( samMethod != null ) { Map impl = Collections . singletonMap ( samMethod . getName ( ) , cl ) ; return ( T ) ProxyGenerator . INSTANCE . instantiateAggregate ( impl , Collections . < Class > singletonList ( clazz ) ) ; } } return ( T ) Proxy . newProxyInstance ( clazz . getClassLoader ( ) , new Class [ ] { clazz } , new ConvertedClosure ( cl ) ) ; } try { return asType ( ( Object ) cl , clazz ) ; } catch ( GroovyCastException ce ) { try { return ( T ) ProxyGenerator . INSTANCE . instantiateAggregateFromBaseClass ( cl , clazz ) ; } catch ( GroovyRuntimeException cause ) { throw new GroovyCastException ( "Error casting closure to " + clazz . getName ( ) + ", Reason: " + cause . getMessage ( ) ) ; } } }
Coerces the closure to an implementation of the given class . The class is assumed to be an interface or class with a single method definition . The closure is used as the implementation of that single method .
6,387
@ SuppressWarnings ( "unchecked" ) public static < T > T asType ( Map map , Class < T > clazz ) { if ( ! ( clazz . isInstance ( map ) ) && clazz . isInterface ( ) && ! Traits . isTrait ( clazz ) ) { return ( T ) Proxy . newProxyInstance ( clazz . getClassLoader ( ) , new Class [ ] { clazz } , new ConvertedMap ( map ) ) ; } try { return asType ( ( Object ) map , clazz ) ; } catch ( GroovyCastException ce ) { try { return ( T ) ProxyGenerator . INSTANCE . instantiateAggregateFromBaseClass ( map , clazz ) ; } catch ( GroovyRuntimeException cause ) { throw new GroovyCastException ( "Error casting map to " + clazz . getName ( ) + ", Reason: " + cause . getMessage ( ) ) ; } } }
Coerces this map to the given type using the map s keys as the public method names and values as the implementation . Typically the value would be a closure which behaves like the method implementation .
6,388
@ SuppressWarnings ( "unchecked" ) public static < T > T [ ] reverse ( T [ ] self , boolean mutate ) { if ( ! mutate ) { return ( T [ ] ) toList ( new ReverseListIterator < T > ( Arrays . asList ( self ) ) ) . toArray ( ) ; } List < T > items = Arrays . asList ( self ) ; Collections . reverse ( items ) ; System . arraycopy ( items . toArray ( ) , 0 , self , 0 , items . size ( ) ) ; return self ; }
Reverse the items in an array . If mutate is true the original array is modified in place and returned . Otherwise a new array containing the reversed items is produced .
6,389
public static < T > Iterator < T > reverse ( Iterator < T > self ) { return new ReverseListIterator < T > ( toList ( self ) ) ; }
Reverses the iterator . The original iterator will become exhausted of elements after determining the reversed values . A new iterator for iterating through the reversed values is returned .
6,390
public static < T > Set < T > plus ( Set < T > left , Collection < T > right ) { return ( Set < T > ) plus ( ( Collection < T > ) left , right ) ; }
Create a Set as a union of a Set and a Collection . This operation will always create a new object for the result while the operands remain unchanged .
6,391
public static < T > List < T > plus ( List < T > self , int index , Iterable < T > additions ) { return plus ( self , index , toList ( additions ) ) ; }
Creates a new List by inserting all of the elements in the given Iterable to the elements from this List at the specified index .
6,392
public static < T > Set < T > minus ( Set < T > self , Collection < ? > removeMe ) { Comparator comparator = ( self instanceof SortedSet ) ? ( ( SortedSet ) self ) . comparator ( ) : null ; final Set < T > ansSet = createSimilarSet ( self ) ; ansSet . addAll ( self ) ; if ( removeMe != null ) { for ( T o1 : self ) { for ( Object o2 : removeMe ) { boolean areEqual = ( comparator != null ) ? ( comparator . compare ( o1 , o2 ) == 0 ) : coercedEquals ( o1 , o2 ) ; if ( areEqual ) { ansSet . remove ( o1 ) ; } } } } return ansSet ; }
Create a Set composed of the elements of the first Set minus the elements of the given Collection .
6,393
public static < T > Set < T > minus ( Set < T > self , Iterable < ? > removeMe ) { return minus ( self , asCollection ( removeMe ) ) ; }
Create a Set composed of the elements of the first Set minus the elements from the given Iterable .
6,394
public static < T > Set < T > minus ( Set < T > self , Object removeMe ) { Comparator comparator = ( self instanceof SortedSet ) ? ( ( SortedSet ) self ) . comparator ( ) : null ; final Set < T > ansSet = createSimilarSet ( self ) ; for ( T t : self ) { boolean areEqual = ( comparator != null ) ? ( comparator . compare ( t , removeMe ) == 0 ) : coercedEquals ( t , removeMe ) ; if ( ! areEqual ) ansSet . add ( t ) ; } return ansSet ; }
Create a Set composed of the elements of the first Set minus the given element .
6,395
public static < T > SortedSet < T > minus ( SortedSet < T > self , Collection < ? > removeMe ) { return ( SortedSet < T > ) minus ( ( Set < T > ) self , removeMe ) ; }
Create a SortedSet composed of the elements of the first SortedSet minus the elements of the given Collection .
6,396
public static < T > SortedSet < T > minus ( SortedSet < T > self , Iterable < ? > removeMe ) { return ( SortedSet < T > ) minus ( ( Set < T > ) self , removeMe ) ; }
Create a SortedSet composed of the elements of the first SortedSet minus the elements of the given Iterable .
6,397
public static < T > SortedSet < T > minus ( SortedSet < T > self , Object removeMe ) { return ( SortedSet < T > ) minus ( ( Set < T > ) self , removeMe ) ; }
Create a SortedSet composed of the elements of the first SortedSet minus the given element .
6,398
@ SuppressWarnings ( "unchecked" ) public static < T > T [ ] minus ( T [ ] self , Iterable removeMe ) { return ( T [ ] ) minus ( toList ( self ) , removeMe ) . toArray ( ) ; }
Create an array composed of the elements of the first array minus the elements of the given Iterable .
6,399
public static < K , V > Map < K , V > leftShift ( Map < K , V > self , Map . Entry < K , V > entry ) { self . put ( entry . getKey ( ) , entry . getValue ( ) ) ; return self ; }
Overloads the left shift operator to provide an easy way to append Map . Entry values to a Map .