Class DefaultGroovyMethods


  • public class DefaultGroovyMethods
    extends DefaultGroovyMethodsSupport
    This class defines new groovy methods which appear on normal JDK classes inside the Groovy environment. Static methods are used with the first parameter being the destination class, i.e. public static String reverse(String self) provides a reverse() method for String.

    NOTE: While this class contains many 'public' static methods, it is primarily regarded as an internal class (its internal package name suggests this also). We value backwards compatibility of these methods when used within Groovy but value less backwards compatibility at the Java method call level. I.e. future versions of Groovy may remove or move a method call in this file but would normally aim to keep the method available from within Groovy.

    Author:
    James Strachan, Jeremy Rayner, Sam Pullara, Rod Cope, Guillaume Laforge, John Wilson, Hein Meling, Dierk Koenig, Pilho Kim, Marc Guillemot, Russel Winder, bing ran, Jochen Theodorou, Paul King, Michael Baehr, Joachim Baumann, Alex Tkachman, Ted Naleid, Brad Long, Jim Jagielski, Rodolfo Velasco, jeremi Joslin, Hamlet D'Arcy, Cedric Champeau, Tim Yates, Dinko Srkoc, Andre Steingress
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.Class[] additionals  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static double abs​(java.lang.Double number)
      Get the absolute value
      static float abs​(java.lang.Float number)
      Get the absolute value
      static long abs​(java.lang.Long number)
      Get the absolute value
      static int abs​(java.lang.Number number)
      Get the absolute value
      static java.net.Socket accept​(java.net.ServerSocket serverSocket, boolean runInANewThread, Closure closure)
      Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread or the calling thread, as needed.
      static java.net.Socket accept​(java.net.ServerSocket serverSocket, Closure closure)
      Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread.
      static <T> boolean addAll​(java.util.Collection<T> self, T[] items)
      Modifies the collection by adding all of the elements in the specified array to the collection.
      static <T> boolean addAll​(java.util.List<T> self, int index, T[] items)
      Modifies this list by inserting all of the elements in the specified array into the list at the specified position.
      static void addShutdownHook​(java.lang.Object self, Closure closure)
      Allows the usage of addShutdownHook without getting the runtime first.
      static java.lang.Boolean and​(java.lang.Boolean left, java.lang.Boolean right)
      Logical conjunction of two boolean operators.
      static java.lang.Number and​(java.lang.Number left, java.lang.Number right)
      Bitwise AND together two Numbers.
      static java.util.BitSet and​(java.util.BitSet left, java.util.BitSet right)
      Bitwise AND together two BitSets.
      static boolean any​(java.lang.Object self)
      Iterates over the elements of a collection, and checks whether at least one element is true according to the Groovy Truth.
      static boolean any​(java.lang.Object self, Closure closure)
      Iterates over the contents of an object or collection, and checks whether a predicate is valid for at least one element.
      static <K,​V>
      boolean
      any​(java.util.Map<K,​V> self, Closure<?> closure)
      Iterates over the entries of a map, and checks whether a predicate is valid for at least one entry.
      static void append​(java.io.File file, byte[] bytes)
      Append bytes to the end of a File.
      static void append​(java.io.File self, java.io.InputStream stream)
      Append binary data to the file.
      static void append​(java.io.File file, java.lang.Object text)
      Append the text at the end of the File.
      static void append​(java.io.File file, java.lang.Object text, java.lang.String charset)
      Append the text at the end of the File, using a specified encoding.
      static boolean asBoolean​(boolean[] array)
      Coerces a boolean array to a boolean value.
      static boolean asBoolean​(byte[] array)
      Coerces a byte array to a boolean value.
      static boolean asBoolean​(char[] array)
      Coerces a char array to a boolean value.
      static boolean asBoolean​(double[] array)
      Coerces a double array to a boolean value.
      static boolean asBoolean​(float[] array)
      Coerces a float array to a boolean value.
      static boolean asBoolean​(int[] array)
      Coerces an int array to a boolean value.
      static boolean asBoolean​(long[] array)
      Coerces a long array to a boolean value.
      static boolean asBoolean​(short[] array)
      Coerces a short array to a boolean value.
      static boolean asBoolean​(java.lang.Boolean bool)
      Coerce an Boolean instance to a boolean value.
      static boolean asBoolean​(java.lang.Character character)
      Coerce a character to a boolean value.
      static boolean asBoolean​(java.lang.CharSequence string)
      Coerce a string (an instance of CharSequence) to a boolean value.
      static boolean asBoolean​(java.lang.Number number)
      Coerce a number to a boolean value.
      static boolean asBoolean​(java.lang.Object object)
      Coerce an object instance to a boolean value.
      static boolean asBoolean​(java.lang.Object[] array)
      Coerce an Object array to a boolean value.
      static boolean asBoolean​(java.util.Collection collection)
      Coerce a collection instance to a boolean value.
      static boolean asBoolean​(java.util.Enumeration enumeration)
      Coerce an enumeration instance to a boolean value.
      static boolean asBoolean​(java.util.Iterator iterator)
      Coerce an iterator instance to a boolean value.
      static boolean asBoolean​(java.util.Map map)
      Coerce a map instance to a boolean value.
      static boolean asBoolean​(java.util.regex.Matcher matcher)
      Coerce a Matcher instance to a boolean value.
      static <T> java.util.Collection<T> asImmutable​(java.util.Collection<? extends T> self)
      A convenience method for creating an immutable Collection.
      static <T> java.util.List<T> asImmutable​(java.util.List<? extends T> self)
      A convenience method for creating an immutable list
      static <K,​V>
      java.util.Map<K,​V>
      asImmutable​(java.util.Map<? extends K,​? extends V> self)
      A convenience method for creating an immutable map.
      static <T> java.util.Set<T> asImmutable​(java.util.Set<? extends T> self)
      A convenience method for creating an immutable list.
      static <K,​V>
      java.util.SortedMap<K,​V>
      asImmutable​(java.util.SortedMap<K,​? extends V> self)
      A convenience method for creating an immutable sorted map.
      static <T> java.util.SortedSet<T> asImmutable​(java.util.SortedSet<T> self)
      A convenience method for creating an immutable sorted set.
      static <T> java.util.List<T> asList​(java.util.Collection<T> self)
      Converts this Collection to a List.
      static <T> java.util.Collection<T> asSynchronized​(java.util.Collection<T> self)
      A convenience method for creating a synchronized Collection.
      static <T> java.util.List<T> asSynchronized​(java.util.List<T> self)
      A convenience method for creating a synchronized List.
      static <K,​V>
      java.util.Map<K,​V>
      asSynchronized​(java.util.Map<K,​V> self)
      A convenience method for creating a synchronized Map.
      static <T> java.util.Set<T> asSynchronized​(java.util.Set<T> self)
      A convenience method for creating a synchronized Set.
      static <K,​V>
      java.util.SortedMap<K,​V>
      asSynchronized​(java.util.SortedMap<K,​V> self)
      A convenience method for creating a synchronized SortedMap.
      static <T> java.util.SortedSet<T> asSynchronized​(java.util.SortedSet<T> self)
      A convenience method for creating a synchronized SortedSet.
      static <T> T asType​(Closure cl, java.lang.Class<T> clazz)
      Coerces the closure to an implementation of the given class.
      static <T> T asType​(GString self, java.lang.Class<T> c)
      Converts the GString to a File, or delegates to the default asType(java.lang.Object, java.lang.Class)
      static <T> T asType​(java.io.File f, java.lang.Class<T> c)
      Converts this File to a Writable or delegates to default asType(java.lang.Object, java.lang.Class).
      static <T> T asType​(java.lang.CharSequence self, java.lang.Class<T> c)
      Provides a method to perform custom 'dynamic' type conversion to the given class using the as operator.
      static <T> T asType​(java.lang.Number self, java.lang.Class<T> c)
      Transform this number to a the given type, using the 'as' operator.
      static <T> T asType​(java.lang.Object[] ary, java.lang.Class<T> clazz)
      Converts the given array to either a List, Set, or SortedSet.
      static <T> T asType​(java.lang.Object obj, java.lang.Class<T> type)
      Converts a given object to a type.
      static <T> T asType​(java.lang.String self, java.lang.Class<T> c)
      Provides a method to perform custom 'dynamic' type conversion to the given class using the as operator.
      static <T> T asType​(java.util.Collection col, java.lang.Class<T> clazz)
      Converts the given collection to another type.
      static <T> T asType​(java.util.Map map, java.lang.Class<T> clazz)
      Coerces this map to the given type, using the map's keys as the public method names, and values as the implementation.
      static java.io.File asWritable​(java.io.File file)
      Converts this File to a Writable.
      static java.io.File asWritable​(java.io.File file, java.lang.String encoding)
      Allows a file to return a Writable implementation that can output itself to a Writer stream.
      static java.util.regex.Pattern bitwiseNegate​(java.lang.CharSequence self)
      Turns a CharSequence into a regular expression Pattern
      static java.util.regex.Pattern bitwiseNegate​(java.lang.String self)
      Turns a String into a regular expression Pattern
      static java.util.BitSet bitwiseNegate​(java.util.BitSet self)
      Bitwise NEGATE a BitSet.
      protected static <T> T callClosureForLine​(Closure<T> closure, java.lang.String line, int counter)  
      protected static <T> T callClosureForMapEntry​(Closure<T> closure, java.util.Map.Entry entry)  
      protected static <T> T callClosureForMapEntryAndCounter​(Closure<T> closure, java.util.Map.Entry entry, int counter)  
      static java.lang.CharSequence capitalize​(java.lang.CharSequence self)
      Convenience method to capitalize the first letter of a CharSequence.
      static java.lang.String capitalize​(java.lang.String self)
      Convenience method to capitalize the first letter of a string (typically the first letter of a word).
      static java.lang.CharSequence center​(java.lang.CharSequence self, java.lang.Number numberOfChars)
      Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character around it as many times as needed so that it remains centered.
      static java.lang.CharSequence center​(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
      Pad a CharSequence to a minimum length specified by numberOfChars, appending the supplied padding CharSequence around the original as many times as needed keeping it centered.
      static java.lang.String center​(java.lang.String self, java.lang.Number numberOfChars)
      Pad a String to a minimum length specified by numberOfChars by adding the space character around it as many times as needed so that it remains centered.
      static java.lang.String center​(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
      Pad a String to a minimum length specified by numberOfChars, appending the supplied padding String around the original as many times as needed keeping it centered.
      static <T> java.util.List<java.util.List<T>> collate​(java.util.List<T> self, int size)
      Collates this list into sub-lists of length size.
      static <T> java.util.List<java.util.List<T>> collate​(java.util.List<T> self, int size, boolean keepRemainder)
      Collates this list into sub-lists of length size.
      static <T> java.util.List<java.util.List<T>> collate​(java.util.List<T> self, int size, int step)
      Collates this list into sub-lists of length size stepping through the code step elements for each subList.
      static <T> java.util.List<java.util.List<T>> collate​(java.util.List<T> self, int size, int step, boolean keepRemainder)
      Collates this list into sub-lists of length size stepping through the code step elements for each sub-list.
      static java.util.Collection collect​(java.lang.Object self)
      Iterates through this aggregate Object transforming each item into a new value using Closure.IDENTITY as a transformer, basically returning a list of items copied from the original object.
      static <T> java.util.List<T> collect​(java.lang.Object self, Closure<T> transform)
      Iterates through this aggregate Object transforming each item into a new value using the transform closure, returning a list of transformed values.
      static <T> java.util.Collection<T> collect​(java.lang.Object self, java.util.Collection<T> collector, Closure<? extends T> transform)
      Iterates through this aggregate Object transforming each item into a new value using the transform closure and adding it to the supplied collector.
      static <T> java.util.List<T> collect​(java.util.Collection<?> self, Closure<T> transform)
      Iterates through this collection transforming each entry into a new value using the transform closure returning a list of transformed values.
      static <T> java.util.Collection<T> collect​(java.util.Collection<?> self, java.util.Collection<T> collector, Closure<? extends T> transform)
      Iterates through this collection transforming each value into a new value using the transform closure and adding it to the supplied collector.
      static <T> java.util.List<T> collect​(java.util.Collection<T> self)
      Iterates through this collection transforming each entry into a new value using Closure.IDENTITY as a transformer, basically returning a list of items copied from the original collection.
      static <T> java.util.Collection<T> collect​(java.util.Map<?,​?> self, java.util.Collection<T> collector, Closure<? extends T> transform)
      Iterates through this Map transforming each map entry into a new value using the transform closure returning the collector with all transformed vakues added to it.
      static <T> java.util.List<T> collect​(java.util.Map self, Closure<T> transform)
      Iterates through this Map transforming each map entry into a new value using the transform closure returning a list of transformed values.
      static java.util.List collectAll​(java.util.Collection self, Closure transform)
      Deprecated.
      Use collectNested instead
      static java.util.Collection collectAll​(java.util.Collection self, java.util.Collection collector, Closure transform)
      Deprecated.
      Use collectNested instead
      static <K,​V>
      java.util.Map<K,​V>
      collectEntries​(java.lang.Object[] self)
      A variant of collectEntries using the identity closure as the transform.
      static <K,​V>
      java.util.Map<K,​V>
      collectEntries​(java.lang.Object[] self, Closure<?> transform)
      Iterates through this array transforming each item using the transform closure and returning a map of the resulting transformed entries.
      static <K,​V>
      java.util.Map<K,​V>
      collectEntries​(java.lang.Object[] self, java.util.Map<K,​V> collector)
      A variant of collectEntries using the identity closure as the transform.
      static <K,​V>
      java.util.Map<K,​V>
      collectEntries​(java.lang.Object[] self, java.util.Map<K,​V> collector, Closure<?> transform)
      Iterates through this array transforming each item using the transform closure and returning a map of the resulting transformed entries.
      static <K,​V>
      java.util.Map<K,​V>
      collectEntries​(java.util.Collection<?> self)
      A variant of collectEntries using the identity closure as the transform.
      static <K,​V>
      java.util.Map<K,​V>
      collectEntries​(java.util.Collection<?> self, Closure<?> transform)
      Iterates through this Collection transforming each item using the transform closure and returning a map of the resulting transformed entries.
      static <K,​V>
      java.util.Map<K,​V>
      collectEntries​(java.util.Collection<?> self, java.util.Map<K,​V> collector)
      A variant of collectEntries using the identity closure as the transform.
      static <K,​V>
      java.util.Map<K,​V>
      collectEntries​(java.util.Collection<?> self, java.util.Map<K,​V> collector, Closure<?> transform)
      Iterates through this Collection transforming each item using the closure as a transformer into a map entry, returning a map of the transformed entries.
      static java.util.Map<?,​?> collectEntries​(java.util.Map<?,​?> self, Closure<?> transform)
      Iterates through this Map transforming each entry using the transform closure and returning a map of the transformed entries.
      static <K,​V>
      java.util.Map<K,​V>
      collectEntries​(java.util.Map<?,​?> self, java.util.Map<K,​V> collector, Closure<?> transform)
      Iterates through this Map transforming each map entry using the transform closure returning a map of the transformed entries.
      static <T> java.util.List<T> collectMany​(java.lang.Object[] self, Closure<java.util.Collection<? extends T>> projection)
      Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.
      static <T> java.util.List<T> collectMany​(java.util.Collection self, Closure<java.util.Collection<? extends T>> projection)
      Projects each item from a source collection to a collection and concatenates (flattens) the resulting collections into a single list.
      static <T> java.util.Collection<T> collectMany​(java.util.Collection self, java.util.Collection<T> collector, Closure<java.util.Collection<? extends T>> projection)
      Projects each item from a source collection to a result collection and concatenates (flattens) the resulting collections adding them into the collector.
      static <T> java.util.List<T> collectMany​(java.util.Iterator<java.lang.Object> self, Closure<java.util.Collection<? extends T>> projection)
      Projects each item from a source iterator to a collection and concatenates (flattens) the resulting collections into a single list.
      static <T> java.util.Collection<T> collectMany​(java.util.Map<?,​?> self, Closure<java.util.Collection<? extends T>> projection)
      Projects each item from a source map to a result collection and concatenates (flattens) the resulting collections adding them into a collection.
      static <T> java.util.Collection<T> collectMany​(java.util.Map<?,​?> self, java.util.Collection<T> collector, Closure<java.util.Collection<? extends T>> projection)
      Projects each item from a source map to a result collection and concatenates (flattens) the resulting collections adding them into the collector.
      static java.util.List collectNested​(java.util.Collection self, Closure transform)
      Recursively iterates through this collection transforming each non-Collection value into a new value using the closure as a transformer.
      static java.util.Collection collectNested​(java.util.Collection self, java.util.Collection collector, Closure transform)
      Recursively iterates through this collection transforming each non-Collection value into a new value using the transform closure.
      static java.util.List combinations​(java.util.Collection self)
      Adds GroovyCollections#combinations(Collection) as a method on collections.
      static int compareTo​(java.lang.Character left, java.lang.Character right)
      Compare two Characters.
      static int compareTo​(java.lang.Character left, java.lang.Number right)
      Compare a Character and a Number.
      static int compareTo​(java.lang.Number left, java.lang.Character right)
      Compare a Number and a Character.
      static int compareTo​(java.lang.Number left, java.lang.Number right)
      Compare two Numbers.
      static boolean contains​(boolean[] self, java.lang.Object value)
      Checks whether the array contains the given value.
      static boolean contains​(byte[] self, java.lang.Object value)
      Checks whether the array contains the given value.
      static boolean contains​(char[] self, java.lang.Object value)
      Checks whether the array contains the given value.
      static boolean contains​(double[] self, java.lang.Object value)
      Checks whether the array contains the given value.
      static boolean contains​(float[] self, java.lang.Object value)
      Checks whether the array contains the given value.
      static boolean contains​(int[] self, java.lang.Object value)
      Checks whether the array contains the given value.
      static boolean contains​(long[] self, java.lang.Object value)
      Checks whether the array contains the given value.
      static boolean contains​(short[] self, java.lang.Object value)
      Checks whether the array contains the given value.
      static boolean contains​(java.lang.CharSequence self, java.lang.CharSequence text)
      Provide an implementation of contains() like Collection.contains(java.lang.Object) to make CharSequences more polymorphic.
      static boolean contains​(java.lang.Object[] self, java.lang.Object value)
      Checks whether the array contains the given value.
      static boolean contains​(java.lang.String self, java.lang.String text)
      Provide an implementation of contains() like Collection.contains(java.lang.Object) to make Strings more polymorphic.
      static boolean containsAll​(java.util.Collection self, java.lang.Object[] items)
      Returns true if this collection contains all of the elements in the specified array.
      static java.lang.Number count​(boolean[] self, java.lang.Object value)
      Counts the number of occurrences of the given value inside this array.
      static java.lang.Number count​(byte[] self, java.lang.Object value)
      Counts the number of occurrences of the given value inside this array.
      static java.lang.Number count​(char[] self, java.lang.Object value)
      Counts the number of occurrences of the given value inside this array.
      static java.lang.Number count​(double[] self, java.lang.Object value)
      Counts the number of occurrences of the given value inside this array.
      static java.lang.Number count​(float[] self, java.lang.Object value)
      Counts the number of occurrences of the given value inside this array.
      static java.lang.Number count​(int[] self, java.lang.Object value)
      Counts the number of occurrences of the given value inside this array.
      static java.lang.Number count​(long[] self, java.lang.Object value)
      Counts the number of occurrences of the given value inside this array.
      static java.lang.Number count​(short[] self, java.lang.Object value)
      Counts the number of occurrences of the given value inside this array.
      static int count​(java.lang.CharSequence self, java.lang.CharSequence text)
      Count the number of occurrences of a sub CharSequence.
      static java.lang.Number count​(java.lang.Object[] self, Closure closure)
      Counts the number of occurrences which satisfy the given closure from inside this array.
      static java.lang.Number count​(java.lang.Object[] self, java.lang.Object value)
      Counts the number of occurrences of the given value inside this array.
      static int count​(java.lang.String self, java.lang.String text)
      Count the number of occurrences of a substring.
      static java.lang.Number count​(java.util.Collection self, Closure closure)
      Counts the number of occurrences which satisfy the given closure from inside this collection.
      static java.lang.Number count​(java.util.Collection self, java.lang.Object value)
      Counts the number of occurrences of the given value inside this collection.
      static java.lang.Number count​(java.util.Iterator self, Closure closure)
      Counts the number of occurrences which satisfy the given closure from the items within this Iterator.
      static java.lang.Number count​(java.util.Iterator self, java.lang.Object value)
      Counts the number of occurrences of the given value from the items within this Iterator.
      static java.lang.Number count​(java.util.Map self, Closure<?> closure)
      Counts the number of occurrences which satisfy the given closure from inside this map.
      static <K> java.util.Map<K,​java.lang.Integer> countBy​(java.lang.Object[] self, Closure<K> closure)
      Sorts all array members into groups determined by the supplied mapping closure and counts the group size.
      static <K> java.util.Map<K,​java.lang.Integer> countBy​(java.util.Collection self, Closure<K> closure)
      Sorts all collection members into groups determined by the supplied mapping closure and counts the group size.
      static <K> java.util.Map<K,​java.lang.Integer> countBy​(java.util.Iterator self, Closure<K> closure)
      Sorts all iterator items into groups determined by the supplied mapping closure and counts the group size.
      static <K> java.util.Map<K,​java.lang.Integer> countBy​(java.util.Map self, Closure<K> closure)
      Groups the members of a map into groups determined by the supplied mapping closure and counts the frequency of the created groups.
      protected static StringBufferWriter createStringBufferWriter​(java.lang.StringBuffer self)  
      protected static java.io.StringWriter createStringWriter​(java.lang.String self)  
      static boolean deleteDir​(java.io.File self)
      Deletes a directory with all contained files and subdirectories.
      static java.lang.CharSequence denormalize​(java.lang.CharSequence self)
      Return a CharSequence with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator.
      static java.lang.String denormalize​(java.lang.String self)
      Return a String with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator.
      static boolean disjoint​(java.util.Collection left, java.util.Collection right)
      Returns true if the intersection of two collections is empty.
      static java.lang.Number div​(java.lang.Character left, java.lang.Character right)
      Divide one Character by another.
      static java.lang.Number div​(java.lang.Character left, java.lang.Number right)
      Divide a Character by a Number.
      static java.lang.Number div​(java.lang.Number left, java.lang.Character right)
      Divide a Number by a Character.
      static void downto​(double self, java.lang.Number to, Closure closure)
      Iterates from this number down to the given number, inclusive, decrementing by one each time.
      static void downto​(float self, java.lang.Number to, Closure closure)
      Iterates from this number down to the given number, inclusive, decrementing by one each time.
      static void downto​(long self, java.lang.Number to, Closure closure)
      Iterates from this number down to the given number, inclusive, decrementing by one each time.
      static void downto​(java.lang.Double self, java.lang.Number to, Closure closure)
      Iterates from this number down to the given number, inclusive, decrementing by one each time.
      static void downto​(java.lang.Float self, java.lang.Number to, Closure closure)
      Iterates from this number down to the given number, inclusive, decrementing by one each time.
      static void downto​(java.lang.Long self, java.lang.Number to, Closure closure)
      Iterates from this number down to the given number, inclusive, decrementing by one each time.
      static void downto​(java.lang.Number self, java.lang.Number to, Closure closure)
      Iterates from this number down to the given number, inclusive, decrementing by one each time.
      static void downto​(java.math.BigDecimal self, java.lang.Number to, Closure closure)
      Iterates from this number down to the given number, inclusive, decrementing by one each time.
      static void downto​(java.math.BigInteger self, java.lang.Number to, Closure closure)
      Iterates from this number down to the given number, inclusive, decrementing by one each time.
      static java.lang.CharSequence drop​(java.lang.CharSequence self, int num)
      Drops the given number of chars from the head of this CharSequence if they are available.
      static <T> java.util.List<T> drop​(java.lang.Iterable<T> self, int num)
      Drops the given number of elements from the head of this Iterable.
      static <T> java.util.Iterator<T> drop​(java.util.Iterator<T> self, int num)
      Drops the given number of elements from the head of this iterator if they are available.
      static <T> java.util.List<T> drop​(java.util.List<T> self, int num)
      Drops the given number of elements from the head of this list if they are available.
      static <K,​V>
      java.util.Map<K,​V>
      drop​(java.util.Map<K,​V> self, int num)
      Drops the given number of key/value pairs from the head of this map if they are available.
      static <T> T[] drop​(T[] self, int num)
      Drops the given number of elements from the head of this array if they are available.
      static <T> java.util.List<T> dropWhile​(java.lang.Iterable<T> self, Closure<?> condition)
      Returns a suffix of this Iterable where elements are dropped from the front while the given closure evaluates to true.
      static <T> java.util.Iterator<T> dropWhile​(java.util.Iterator<T> self, Closure<?> condition)
      Creates an Iterator that returns a suffix of the elements from an original Iterator.
      static <T> java.util.List<T> dropWhile​(java.util.List<T> self, Closure<?> condition)
      Returns a suffix of this List where elements are dropped from the front while the given Closure evaluates to true.
      static <K,​V>
      java.util.Map<K,​V>
      dropWhile​(java.util.Map<K,​V> self, Closure<?> condition)
      Create a suffix of the given Map by dropping as many entries as possible from the front of the original Map such that calling the given closure condition evaluates to true when passed each of the dropped entries (or key/value pairs).
      static <T> T[] dropWhile​(T[] self, Closure<?> condition)
      Create a suffix of the given array by dropping as many elements as possible from the front of the original array such that calling the given closure condition evaluates to true when passed each of the dropped elements.
      static java.lang.String dump​(java.lang.Object self)
      Generates a detailed dump string of an object showing its class, hashCode and fields.
      static <K,​V>
      java.util.Map<K,​V>
      each​(java.util.Map<K,​V> self, Closure closure)
      Allows a Map to be iterated through using a closure.
      static <T> T each​(T self, Closure closure)
      Iterates through an aggregate type or data structure, passing each item to the given closure.
      static void eachByte​(byte[] self, Closure closure)
      Traverse through each byte of this byte array.
      static void eachByte​(java.io.File self, int bufferLen, Closure closure)
      Traverse through the bytes of this File, bufferLen bytes at a time.
      static void eachByte​(java.io.File self, Closure closure)
      Traverse through each byte of this File
      static void eachByte​(java.io.InputStream is, int bufferLen, Closure closure)
      Traverse through each the specified stream reading bytes into a buffer and calling the 2 parameter closure with this buffer and the number of bytes.
      static void eachByte​(java.io.InputStream is, Closure closure)
      Traverse through each byte of the specified stream.
      static void eachByte​(java.lang.Byte[] self, Closure closure)
      Traverse through each byte of this Byte array.
      static void eachByte​(java.net.URL url, int bufferLen, Closure closure)
      Reads the InputStream from this URL, passing a byte[] and a number of bytes to the given closure.
      static void eachByte​(java.net.URL url, Closure closure)
      Reads the InputStream from this URL, passing each byte to the given closure.
      static void eachDir​(java.io.File self, Closure closure)
      Invokes the closure for each subdirectory in this directory, ignoring regular files.
      static void eachDirMatch​(java.io.File self, java.lang.Object nameFilter, Closure closure)
      Invokes the closure for each subdirectory whose name (dir.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs.
      static void eachDirRecurse​(java.io.File self, Closure closure)
      Invokes the closure for each descendant directory of this directory.
      static void eachFile​(java.io.File self, FileType fileType, Closure closure)
      Invokes the closure for each 'child' file in this 'parent' folder/directory.
      static void eachFile​(java.io.File self, Closure closure)
      Invokes the closure for each 'child' file in this 'parent' folder/directory.
      static void eachFileMatch​(java.io.File self, FileType fileType, java.lang.Object nameFilter, Closure closure)
      Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs.
      static void eachFileMatch​(java.io.File self, java.lang.Object nameFilter, Closure closure)
      Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs.
      static void eachFileRecurse​(java.io.File self, FileType fileType, Closure closure)
      Invokes the closure for each descendant file in this directory.
      static void eachFileRecurse​(java.io.File self, Closure closure)
      Invokes the closure for each descendant file in this directory.
      static <T> T eachLine​(java.io.File self, int firstLine, Closure<T> closure)
      Iterates through this file line by line.
      static <T> T eachLine​(java.io.File self, Closure<T> closure)
      Iterates through this file line by line.
      static <T> T eachLine​(java.io.File self, java.lang.String charset, int firstLine, Closure<T> closure)
      Iterates through this file line by line.
      static <T> T eachLine​(java.io.File self, java.lang.String charset, Closure<T> closure)
      Iterates through this file line by line.
      static <T> T eachLine​(java.io.InputStream stream, int firstLine, Closure<T> closure)
      Iterates through this stream, passing each line to the given 1 or 2 arg closure.
      static <T> T eachLine​(java.io.InputStream stream, Closure<T> closure)
      Iterates through this stream, passing each line to the given 1 or 2 arg closure.
      static <T> T eachLine​(java.io.InputStream stream, java.lang.String charset, int firstLine, Closure<T> closure)
      Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure.
      static <T> T eachLine​(java.io.InputStream stream, java.lang.String charset, Closure<T> closure)
      Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure.
      static <T> T eachLine​(java.io.Reader self, int firstLine, Closure<T> closure)
      Iterates through the given reader line by line.
      static <T> T eachLine​(java.io.Reader self, Closure<T> closure)
      Iterates through the given reader line by line.
      static <T> T eachLine​(java.lang.CharSequence self, int firstLine, Closure<T> closure)
      Iterates through this CharSequence line by line.
      static <T> T eachLine​(java.lang.CharSequence self, Closure<T> closure)
      Iterates through this CharSequence line by line.
      static <T> T eachLine​(java.lang.String self, int firstLine, Closure<T> closure)
      Iterates through this String line by line.
      static <T> T eachLine​(java.lang.String self, Closure<T> closure)
      Iterates through this String line by line.
      static <T> T eachLine​(java.net.URL url, int firstLine, Closure<T> closure)
      Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.
      static <T> T eachLine​(java.net.URL url, Closure<T> closure)
      Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.
      static <T> T eachLine​(java.net.URL url, java.lang.String charset, int firstLine, Closure<T> closure)
      Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.
      static <T> T eachLine​(java.net.URL url, java.lang.String charset, Closure<T> closure)
      Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure.
      static java.lang.String eachMatch​(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
      Process each regex group matched substring of the given CharSequence.
      static java.lang.String eachMatch​(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
      Process each regex group matched substring of the given pattern.
      static java.lang.String eachMatch​(java.lang.String self, java.lang.String regex, Closure closure)
      Process each regex group matched substring of the given string.
      static java.lang.String eachMatch​(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
      Process each regex group matched substring of the given pattern.
      static void eachObject​(java.io.File self, Closure closure)
      Iterates through the given file object by object.
      static void eachObject​(java.io.ObjectInputStream ois, Closure closure)
      Iterates through the given object stream object by object.
      static <T> java.util.Iterator<java.util.List<T>> eachPermutation​(java.util.Collection<T> self, Closure closure)
      Iterates over all permutations of a collection, running a closure for each iteration.
      static <K,​V>
      java.util.Map<K,​V>
      eachWithIndex​(java.util.Map<K,​V> self, Closure closure)
      Allows a Map to be iterated through using a closure.
      static <T> T eachWithIndex​(T self, Closure closure)
      Iterates through an aggregate type or data structure, passing each item and the item's index (a counter starting at zero) to the given closure.
      static boolean equals​(int[] left, int[] right)
      Compare the contents of this array to the contents of the given array.
      static boolean equals​(java.lang.Object[] left, java.util.List right)
      Determines if the contents of this array are equal to the contents of the given list, in the same order.
      static boolean equals​(java.util.List left, java.lang.Object[] right)
      Determines if the contents of this list are equal to the contents of the given array in the same order.
      static boolean equals​(java.util.List left, java.util.List right)
      Compare the contents of two Lists.
      static boolean equals​(java.util.Map self, java.util.Map other)
      Compares two Maps treating coerced numerical values as identical.
      static <T> boolean equals​(java.util.Set<T> self, java.util.Set<T> other)
      Compare the contents of two Sets for equality using Groovy's coercion rules.
      static boolean every​(java.lang.Object self)
      Iterates over every element of a collection, and checks whether all elements are true according to the Groovy Truth.
      static boolean every​(java.lang.Object self, Closure closure)
      Used to determine if the given predicate closure is valid (i.e.&nsbp;returns true for all items in this data structure).
      static <K,​V>
      boolean
      every​(java.util.Map<K,​V> self, Closure closure)
      Iterates over the entries of a map, and checks whether a predicate is valid for all entries.
      static java.lang.Process execute​(java.lang.String self)
      Executes the command specified by self as a command-line process.
      static java.lang.Process execute​(java.lang.String[] commandArray)
      Executes the command specified by the given String array.
      static java.lang.Process execute​(java.lang.String[] commandArray, java.lang.String[] envp, java.io.File dir)
      Executes the command specified by the String array given in the first parameter, with the environment defined by envp and under the working directory dir.
      static java.lang.Process execute​(java.lang.String[] commandArray, java.util.List envp, java.io.File dir)
      Executes the command specified by the String array given in the first parameter, with the environment defined by envp and under the working directory dir.
      static java.lang.Process execute​(java.lang.String self, java.lang.String[] envp, java.io.File dir)
      Executes the command specified by self with environment defined by envp and under the working directory dir.
      static java.lang.Process execute​(java.lang.String self, java.util.List envp, java.io.File dir)
      Executes the command specified by self with environment defined by envp and under the working directory dir.
      static java.lang.Process execute​(java.util.List commands)
      Executes the command specified by the given list.
      static java.lang.Process execute​(java.util.List commands, java.lang.String[] envp, java.io.File dir)
      Executes the command specified by the given list, with the environment defined by envp and under the working directory dir.
      static java.lang.Process execute​(java.util.List commands, java.util.List envp, java.io.File dir)
      Executes the command specified by the given list, with the environment defined by envp and under the working directory dir.
      static java.lang.CharSequence expand​(java.lang.CharSequence self)
      Expands all tabs into spaces with tabStops of size 8.
      static java.lang.CharSequence expand​(java.lang.CharSequence self, int tabStop)
      Expands all tabs into spaces.
      static java.lang.String expand​(java.lang.String self)
      Expands all tabs into spaces with tabStops of size 8.
      static java.lang.String expand​(java.lang.String self, int tabStop)
      Expands all tabs into spaces.
      static java.lang.CharSequence expandLine​(java.lang.CharSequence self, int tabStop)
      Expands all tabs into spaces.
      static java.lang.String expandLine​(java.lang.String self, int tabStop)
      Expands all tabs into spaces.
      static Writable filterLine​(java.io.File self, Closure closure)
      Filters the lines of a File and creates a Writable in return to stream the filtered lines.
      static void filterLine​(java.io.File self, java.io.Writer writer, Closure closure)
      Filter the lines from this File, and write them to the given writer based on the given closure predicate.
      static void filterLine​(java.io.File self, java.io.Writer writer, java.lang.String charset, Closure closure)
      Filter the lines from this File, and write them to the given writer based on the given closure predicate.
      static Writable filterLine​(java.io.File self, java.lang.String charset, Closure closure)
      Filters the lines of a File and creates a Writable in return to stream the filtered lines.
      static Writable filterLine​(java.io.InputStream self, Closure predicate)
      Filter lines from an input stream using a closure predicate.
      static void filterLine​(java.io.InputStream self, java.io.Writer writer, Closure predicate)
      Uses a closure to filter lines from this InputStream and pass them to the given writer.
      static void filterLine​(java.io.InputStream self, java.io.Writer writer, java.lang.String charset, Closure predicate)
      Uses a closure to filter lines from this InputStream and pass them to the given writer.
      static Writable filterLine​(java.io.InputStream self, java.lang.String charset, Closure predicate)
      Filter lines from an input stream using a closure predicate.
      static Writable filterLine​(java.io.Reader reader, Closure closure)
      Filter the lines from this Reader, and return a Writable which can be used to stream the filtered lines to a destination.
      static void filterLine​(java.io.Reader reader, java.io.Writer writer, Closure closure)
      Filter the lines from a reader and write them on the writer, according to a closure which returns true if the line should be included.
      static Writable filterLine​(java.net.URL self, Closure predicate)
      Filter lines from a URL using a closure predicate.
      static void filterLine​(java.net.URL self, java.io.Writer writer, Closure predicate)
      Uses a closure to filter lines from this URL and pass them to the given writer.
      static void filterLine​(java.net.URL self, java.io.Writer writer, java.lang.String charset, Closure predicate)
      Uses a closure to filter lines from this URL and pass them to the given writer.
      static Writable filterLine​(java.net.URL self, java.lang.String charset, Closure predicate)
      Filter lines from a URL using a closure predicate.
      static java.lang.CharSequence find​(java.lang.CharSequence self, java.lang.CharSequence regex)
      Finds the first occurrence of a regular expression CharSequence within a CharSequence.
      static java.lang.CharSequence find​(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
      Returns the result of calling a closure with the first occurrence of a regular expression found within a CharSequence.
      static java.lang.CharSequence find​(java.lang.CharSequence self, java.util.regex.Pattern pattern)
      Finds the first occurrence of a compiled regular expression Pattern within a CharSequence.
      static java.lang.CharSequence find​(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)  
      static java.lang.Object find​(java.lang.Object self)
      Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).
      static java.lang.Object find​(java.lang.Object self, Closure closure)
      Finds the first value matching the closure condition
      static java.lang.String find​(java.lang.String self, java.lang.String regex)
      Finds the first occurrence of a regular expression String within a String.
      static java.lang.String find​(java.lang.String self, java.lang.String regex, Closure closure)
      Returns the result of calling a closure with the first occurrence of a regular expression found within a String.
      static java.lang.String find​(java.lang.String self, java.util.regex.Pattern pattern)
      Finds the first occurrence of a compiled regular expression Pattern within a String.
      static java.lang.String find​(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
      Returns the result of calling a closure with the first occurrence of a compiled regular expression found within a String.
      static <T> T find​(java.util.Collection<T> self)
      Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).
      static <T> T find​(java.util.Collection<T> self, Closure closure)
      Finds the first value matching the closure condition.
      static <K,​V>
      java.util.Map.Entry<K,​V>
      find​(java.util.Map<K,​V> self, Closure<?> closure)
      Finds the first entry matching the closure condition.
      static java.util.List<java.lang.CharSequence> findAll​(java.lang.CharSequence self, java.lang.CharSequence regex)
      Returns a (possibly empty) list of all occurrences of a regular expression (in CharSequence format) found within a CharSequence.
      static <T> java.util.List<T> findAll​(java.lang.CharSequence self, java.lang.CharSequence regex, Closure<T> closure)
      Finds all occurrences of a capturing regular expression CharSequence within a CharSequence.
      static java.util.List<java.lang.CharSequence> findAll​(java.lang.CharSequence self, java.util.regex.Pattern pattern)
      Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a CharSequence.
      static <T> java.util.List<T> findAll​(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure<T> closure)
      Finds all occurrences of a compiled regular expression Pattern within a CharSequence.
      static java.util.Collection findAll​(java.lang.Object self)
      Finds all items matching the IDENTITY Closure (i.e. matching Groovy truth).
      static java.util.Collection findAll​(java.lang.Object self, Closure closure)
      Finds all items matching the closure condition.
      static java.util.List<java.lang.String> findAll​(java.lang.String self, java.lang.String regex)
      Returns a (possibly empty) list of all occurrences of a regular expression (in String format) found within a String.
      static <T> java.util.List<T> findAll​(java.lang.String self, java.lang.String regex, Closure<T> closure)
      Finds all occurrences of a regular expression string within a String.
      static java.util.List<java.lang.String> findAll​(java.lang.String self, java.util.regex.Pattern pattern)
      Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a String.
      static <T> java.util.List<T> findAll​(java.lang.String self, java.util.regex.Pattern pattern, Closure<T> closure)
      Finds all occurrences of a compiled regular expression Pattern within a String.
      static <T> java.util.Collection<T> findAll​(java.util.Collection<T> self)
      Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).
      static <T> java.util.Collection<T> findAll​(java.util.Collection<T> self, Closure closure)
      Finds all values matching the closure condition.
      static <K,​V>
      java.util.Map<K,​V>
      findAll​(java.util.Map<K,​V> self, Closure closure)
      Finds all entries matching the closure condition.
      static int findIndexOf​(java.lang.Object self, int startIndex, Closure closure)
      Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index of the first item that matches the condition specified in the closure.
      static int findIndexOf​(java.lang.Object self, Closure closure)
      Iterates over the elements of an iterable collection of items and returns the index of the first item that matches the condition specified in the closure.
      static java.util.List<java.lang.Number> findIndexValues​(java.lang.Object self, Closure closure)
      Iterates over the elements of an iterable collection of items and returns the index values of the items that match the condition specified in the closure.
      static java.util.List<java.lang.Number> findIndexValues​(java.lang.Object self, java.lang.Number startIndex, Closure closure)
      Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index values of the items that match the condition specified in the closure.
      static int findLastIndexOf​(java.lang.Object self, int startIndex, Closure closure)
      Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index of the last item that matches the condition specified in the closure.
      static int findLastIndexOf​(java.lang.Object self, Closure closure)
      Iterates over the elements of an iterable collection of items and returns the index of the last item that matches the condition specified in the closure.
      static java.lang.Object findResult​(java.lang.Object self, Closure closure)
      Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns null.
      static java.lang.Object findResult​(java.lang.Object self, java.lang.Object defaultResult, Closure closure)
      Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns the defaultResult.
      static <T> T findResult​(java.util.Collection<?> self, Closure<T> closure)
      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 results are null, null is returned.
      static <T,​U extends T,​V extends T>
      T
      findResult​(java.util.Collection<?> self, U defaultResult, Closure<V> closure)
      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.
      static <T> T findResult​(java.util.Map<?,​?> self, Closure<T> closure)
      Returns the first non-null closure result found by passing each map entry to the closure, otherwise null is returned.
      static <T,​U extends T,​V extends T>
      T
      findResult​(java.util.Map<?,​?> self, U defaultResult, Closure<V> closure)
      Returns the first non-null closure result found by passing each map entry to the closure, otherwise the defaultResult is returned.
      static <T> java.util.Collection<T> findResults​(java.util.Collection<?> self, Closure<T> filteringTransform)
      Iterates through the collection transforming items using the supplied closure and collecting any non-null results.
      static <T> java.util.Collection<T> findResults​(java.util.Map<?,​?> self, Closure<T> filteringTransform)
      Iterates through the map transforming items using the supplied closure and collecting any non-null results.
      static <T> T first​(java.lang.Iterable<T> self)
      Returns the first item from the Iterable.
      static <T> T first​(java.util.List<T> self)
      Returns the first item from the List.
      static <T> T first​(T[] self)
      Returns the first item from the array.
      static java.util.Collection flatten​(boolean[] self)
      Flatten an array.
      static java.util.Collection flatten​(byte[] self)
      Flatten an array.
      static java.util.Collection flatten​(char[] self)
      Flatten an array.
      static java.util.Collection flatten​(double[] self)
      Flatten an array.
      static java.util.Collection flatten​(float[] self)
      Flatten an array.
      static java.util.Collection flatten​(int[] self)
      Flatten an array.
      static java.util.Collection flatten​(long[] self)
      Flatten an array.
      static java.util.Collection flatten​(short[] self)
      Flatten an array.
      static java.util.Collection flatten​(java.lang.Object[] self)
      Flatten an array.
      static java.util.Collection<?> flatten​(java.util.Collection<?> self)
      Flatten a collection.
      static <T> java.util.Collection<T> flatten​(java.util.Collection<T> self, Closure<? extends T> flattenUsing)
      Flatten a collection.
      static <K,​V>
      V
      get​(java.util.Map<K,​V> map, K key, V defaultValue)
      Looks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that.
      static java.util.List<java.lang.Boolean> getAt​(boolean[] array, IntRange range)
      Support the subscript operator with an IntRange for a boolean array
      static java.util.List<java.lang.Boolean> getAt​(boolean[] array, ObjectRange range)
      Support the subscript operator with an ObjectRange for a byte array
      static java.util.List<java.lang.Boolean> getAt​(boolean[] array, Range range)
      Support the subscript operator with a range for a boolean array
      static java.util.List<java.lang.Boolean> getAt​(boolean[] array, java.util.Collection indices)
      Support the subscript operator with a collection for a boolean array
      static java.util.List<java.lang.Byte> getAt​(byte[] array, IntRange range)
      Support the subscript operator with an IntRange for a byte array
      static java.util.List<java.lang.Byte> getAt​(byte[] array, ObjectRange range)
      Support the subscript operator with an ObjectRange for a byte array
      static java.util.List<java.lang.Byte> getAt​(byte[] array, Range range)
      Support the subscript operator with a range for a byte array
      static java.util.List<java.lang.Byte> getAt​(byte[] array, java.util.Collection indices)
      Support the subscript operator with a collection for a byte array
      static java.util.List<java.lang.Character> getAt​(char[] array, IntRange range)
      Support the subscript operator with an IntRange for a char array
      static java.util.List<java.lang.Character> getAt​(char[] array, ObjectRange range)
      Support the subscript operator with an ObjectRange for a char array
      static java.util.List<java.lang.Character> getAt​(char[] array, Range range)
      Support the subscript operator with a range for a char array
      static java.util.List<java.lang.Character> getAt​(char[] array, java.util.Collection indices)
      Support the subscript operator with a collection for a char array
      static java.util.List<java.lang.Double> getAt​(double[] array, IntRange range)
      Support the subscript operator with an IntRange for a double array
      static java.util.List<java.lang.Double> getAt​(double[] array, ObjectRange range)
      Support the subscript operator with an ObjectRange for a double array
      static java.util.List<java.lang.Double> getAt​(double[] array, Range range)
      Support the subscript operator with a range for a double array
      static java.util.List<java.lang.Double> getAt​(double[] array, java.util.Collection indices)
      Support the subscript operator with a collection for a double array
      static java.util.List<java.lang.Float> getAt​(float[] array, IntRange range)
      Support the subscript operator with an IntRange for a float array
      static java.util.List<java.lang.Float> getAt​(float[] array, ObjectRange range)
      Support the subscript operator with an ObjectRange for a float array
      static java.util.List<java.lang.Float> getAt​(float[] array, Range range)
      Support the subscript operator with a range for a float array
      static java.util.List<java.lang.Float> getAt​(float[] array, java.util.Collection indices)
      Support the subscript operator with a collection for a float array
      static java.util.List<java.lang.Integer> getAt​(int[] array, IntRange range)
      Support the subscript operator with an IntRange for an int array
      static java.util.List<java.lang.Integer> getAt​(int[] array, ObjectRange range)
      Support the subscript operator with an ObjectRange for an int array
      static java.util.List<java.lang.Integer> getAt​(int[] array, Range range)
      Support the subscript operator with a range for an int array
      static java.util.List<java.lang.Integer> getAt​(int[] array, java.util.Collection indices)
      Support the subscript operator with a collection for an int array
      static java.util.List<java.lang.Long> getAt​(long[] array, IntRange range)
      Support the subscript operator with an IntRange for a long array
      static java.util.List<java.lang.Long> getAt​(long[] array, ObjectRange range)
      Support the subscript operator with an ObjectRange for a long array
      static java.util.List<java.lang.Long> getAt​(long[] array, Range range)
      Support the subscript operator with a range for a long array
      static java.util.List<java.lang.Long> getAt​(long[] array, java.util.Collection indices)
      Support the subscript operator with a collection for a long array
      static java.util.List<java.lang.Short> getAt​(short[] array, IntRange range)
      Support the subscript operator with an IntRange for a short array
      static java.util.List<java.lang.Short> getAt​(short[] array, ObjectRange range)
      Support the subscript operator with an ObjectRange for a short array
      static java.util.List<java.lang.Short> getAt​(short[] array, Range range)
      Support the subscript operator with a range for a short array
      static java.util.List<java.lang.Short> getAt​(short[] array, java.util.Collection indices)
      Support the subscript operator with a collection for a short array
      static java.lang.CharSequence getAt​(java.lang.CharSequence text, int index)
      Support the subscript operator for CharSequence.
      static java.lang.CharSequence getAt​(java.lang.CharSequence text, EmptyRange range)
      Support the range subscript operator for CharSequence or StringBuffer with EmptyRange
      static java.lang.CharSequence getAt​(java.lang.CharSequence text, IntRange range)
      Support the range subscript operator for CharSequence or StringBuffer with IntRange
      static java.lang.CharSequence getAt​(java.lang.CharSequence text, Range range)
      Support the range subscript operator for CharSequence
      static java.lang.CharSequence getAt​(java.lang.CharSequence self, java.util.Collection indices)
      Select a List of characters from a CharSequence using a Collection to identify the indices to be selected.
      static java.lang.Object getAt​(java.lang.Object self, java.lang.String property)
      Allows the subscript operator to be used to lookup dynamic property values.
      static java.lang.String getAt​(java.lang.String text, int index)
      Support the subscript operator for String.
      static java.lang.String getAt​(java.lang.String text, EmptyRange range)
      Support the range subscript operator for String with EmptyRange
      static java.lang.String getAt​(java.lang.String text, IntRange range)
      Support the range subscript operator for String with IntRange
      static java.lang.String getAt​(java.lang.String text, Range range)
      Support the range subscript operator for String
      static java.lang.String getAt​(java.lang.String self, java.util.Collection indices)
      Select a List of characters from a String using a Collection to identify the indices to be selected.
      static boolean getAt​(java.util.BitSet self, int index)
      Support the subscript operator for a Bitset
      static java.util.BitSet getAt​(java.util.BitSet self, IntRange range)
      Support retrieving a subset of a BitSet using a Range
      static java.util.List getAt​(java.util.Collection coll, java.lang.String property)
      Support the subscript operator for Collection.
      static <T> T getAt​(java.util.Iterator<T> self, int idx)
      Support the subscript operator for an Iterator.
      static <T> T getAt​(java.util.List<T> self, int idx)
      Support the subscript operator for a List.
      static <T> java.util.List<T> getAt​(java.util.List<T> self, EmptyRange range)
      Support the range subscript operator for a List.
      static <T> java.util.List<T> getAt​(java.util.List<T> self, Range range)
      Support the range subscript operator for a List.
      static <T> java.util.List<T> getAt​(java.util.List<T> self, java.util.Collection indices)
      Select a List of items from a List using a Collection to identify the indices to be selected.
      static <K,​V>
      V
      getAt​(java.util.Map<K,​V> self, K key)
      Support the subscript operator for a Map.
      static java.lang.Object getAt​(java.util.regex.Matcher matcher, int idx)
      Support the subscript operator, e.g. matcher[index], for a regex Matcher.
      static java.util.List getAt​(java.util.regex.Matcher self, java.util.Collection indices)
      Select a List of values from a Matcher using a Collection to identify the indices to be selected.
      static <T> java.util.List<T> getAt​(T[] array, EmptyRange range)  
      static <T> java.util.List<T> getAt​(T[] array, IntRange range)  
      static <T> java.util.List<T> getAt​(T[] array, ObjectRange range)  
      static <T> java.util.List<T> getAt​(T[] array, Range range)
      Support the range subscript operator for an Array
      static <T> java.util.List<T> getAt​(T[] self, java.util.Collection indices)
      Select a List of items from an Object array using a Collection to identify the indices to be selected.
      static byte[] getBytes​(java.io.File file)
      Read the content of the File and returns it as a byte[].
      static byte[] getBytes​(java.io.InputStream is)
      Read the content of this InputStream and return it as a byte[].
      static byte[] getBytes​(java.net.URL url)
      Read the content of this URL and returns it as a byte[].
      static char[] getChars​(java.lang.CharSequence self)
      Converts the given CharSequence into an array of characters.
      static char[] getChars​(java.lang.String self)
      Converts the given String into an array of characters.
      static int getCount​(java.util.regex.Matcher matcher)
      Find the number of Strings matched to the given Matcher.
      static MetaClass getMetaClass​(GroovyObject obj)
      Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself.
      static MetaClass getMetaClass​(java.lang.Class c)
      Adds a "metaClass" property to all class objects so you can use the syntax String.metaClass.myMethod = { println "foo" }
      static MetaClass getMetaClass​(java.lang.Object obj)
      Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself.
      static java.util.List<PropertyValue> getMetaPropertyValues​(java.lang.Object self)
      Retrieves the list of MetaProperty objects for 'self' and wraps it in a list of PropertyValue objects that additionally provide the value for each property of 'self'.
      static java.util.Map getProperties​(java.lang.Object self)
      Convenience method that calls getMetaPropertyValues(java.lang.Object)(self) and provides the data in form of simple key/value pairs, i.e.&nsbp;without type() information.
      static java.lang.ClassLoader getRootLoader​(java.lang.ClassLoader self)
      Iterates through the classloader parents until it finds a loader with a class named "org.codehaus.groovy.tools.RootLoader".
      protected static java.util.List getSubList​(java.util.List self, java.util.List splice)  
      static java.lang.String getText​(java.io.BufferedReader reader)
      Read the content of the BufferedReader and return it as a String.
      static java.lang.String getText​(java.io.File file)
      Read the content of the File and returns it as a String.
      static java.lang.String getText​(java.io.File file, java.lang.String charset)
      Read the content of the File using the specified encoding and return it as a String.
      static java.lang.String getText​(java.io.InputStream is)
      Read the content of this InputStream and return it as a String.
      static java.lang.String getText​(java.io.InputStream is, java.lang.String charset)
      Read the content of this InputStream using specified charset and return it as a String.
      static java.lang.String getText​(java.io.Reader reader)
      Read the content of the Reader and return it as a String.
      static java.lang.String getText​(java.net.URL url)
      Read the content of this URL and returns it as a String.
      static java.lang.String getText​(java.net.URL url, java.lang.String charset)
      Read the data from this URL and return it as a String.
      static java.lang.String getText​(java.net.URL url, java.util.Map parameters)
      Read the content of this URL and returns it as a String.
      static java.lang.String getText​(java.net.URL url, java.util.Map parameters, java.lang.String charset)
      Read the data from this URL and return it as a String.
      static java.util.Collection grep​(java.lang.Object self)
      Iterates over the collection of items which this Object represents and returns each item that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.
      static java.util.Collection grep​(java.lang.Object self, java.lang.Object filter)
      Iterates over the collection of items which this Object represents and returns each item that matches the given filter - calling the isCase(java.lang.Object, java.lang.Object) method used by switch statements.
      protected static <K,​T>
      void
      groupAnswer​(java.util.Map<K,​java.util.List<T>> answer, T element, K value)
      Groups the current element according to the value
      static <K,​T>
      java.util.Map<K,​java.util.List<T>>
      groupBy​(java.util.Collection<T> self, Closure<K> closure)
      Sorts all collection members into groups determined by the supplied mapping closure.
      static java.util.Map groupBy​(java.util.Collection self, java.lang.Object... closures)
      Sorts all collection members into (sub)groups determined by the supplied mapping closures.
      static java.util.Map groupBy​(java.util.Collection self, java.util.List<Closure> closures)
      Sorts all collection members into (sub)groups determined by the supplied mapping closures.
      static <G,​K,​V>
      java.util.Map<G,​java.util.Map<K,​V>>
      groupBy​(java.util.Map<K,​V> self, Closure<G> closure)
      Groups the members of a map into sub maps determined by the supplied mapping closure.
      static java.util.Map<java.lang.Object,​java.util.Map> groupBy​(java.util.Map self, java.lang.Object... closures)
      Groups the members of a map into sub maps determined by the supplied mapping closures.
      static java.util.Map<java.lang.Object,​java.util.Map> groupBy​(java.util.Map self, java.util.List<Closure> closures)
      Groups the members of a map into sub maps determined by the supplied mapping closures.
      static <G,​K,​V>
      java.util.Map<G,​java.util.List<java.util.Map.Entry<K,​V>>>
      groupEntriesBy​(java.util.Map<K,​V> self, Closure<G> closure)
      Groups all map entries into groups determined by the supplied mapping closure.
      static boolean hasGroup​(java.util.regex.Matcher matcher)
      Check whether a Matcher contains a group or not.
      static MetaProperty hasProperty​(java.lang.Object self, java.lang.String name)
      Returns true of the implementing MetaClass has a property of the given name
      static <T> T head​(java.util.List<T> self)
      Returns the first item from the List.
      static <T> T head​(T[] self)
      Returns the first item from the Object array.
      static <T> T identity​(java.lang.Object self, Closure<T> closure)
      Allows the closure to be called for the object reference self.
      static java.lang.Boolean implies​(java.lang.Boolean left, java.lang.Boolean right)
      Logical implication of two boolean operators
      static <T,​V extends T>
      T
      inject​(java.lang.Object[] self, Closure<V> closure)
      Iterates through the given array as with inject(Object[],initialValue,closure), but using the first element of the array as the initialValue, and then iterating the remaining elements of the array.
      static <T,​U extends T,​V extends T>
      T
      inject​(java.lang.Object[] self, U initialValue, Closure<V> closure)
      Iterates through the given array, passing in the initial value to the closure along with the first item.
      static <T,​V extends T>
      T
      inject​(java.lang.Object self, Closure<V> closure)
      Iterates through the given Object, passing in the first value to the closure along with the first item.
      static <T,​U extends T,​V extends T>
      T
      inject​(java.lang.Object self, U initialValue, Closure<V> closure)
      Iterates through the given Object, passing in the initial value to the closure along with the first item.
      static <T,​V extends T>
      T
      inject​(java.util.Collection<T> self, Closure<V> closure)
      Performs the same function as the version of inject that takes an initial value, but uses the head of the Collection as the initial value, and iterates over the tail.
      static <T,​U extends T,​V extends T>
      T
      inject​(java.util.Collection self, U initialValue, Closure<V> closure)
      Iterates through the given Collection, passing in the initial value to the 2-arg closure along with the first item.
      static <T,​U extends T,​V extends T>
      T
      inject​(java.util.Iterator self, U initialValue, Closure<V> closure)
      Iterates through the given Iterator, passing in the initial value to the closure along with the first item.
      static <T,​U extends T,​V extends T>
      T
      inject​(java.util.Map<?,​?> self, U initialValue, Closure<V> closure)
      Iterates through the given Map, passing in the initial value to the 2-arg Closure along with the first item (or 3-arg Closure along with the first key and value).
      static java.lang.String inspect​(java.lang.Object self)
      Inspects returns the String that matches what would be typed into a terminal to create this object.
      static java.lang.Number intdiv​(java.lang.Character left, java.lang.Character right)
      Integer Divide two Characters.
      static java.lang.Number intdiv​(java.lang.Character left, java.lang.Number right)
      Integer Divide a Character by a Number.
      static java.lang.Number intdiv​(java.lang.Number left, java.lang.Character right)
      Integer Divide a Number by a Character.
      static java.lang.Number intdiv​(java.lang.Number left, java.lang.Number right)
      Integer Divide two Numbers.
      static <T> java.util.Collection<T> intersect​(java.util.Collection<T> left, java.util.Collection<T> right)
      Create a Collection composed of the intersection of both collections.
      static <K,​V>
      java.util.Map<K,​V>
      intersect​(java.util.Map<K,​V> left, java.util.Map<K,​V> right)
      Create a Map composed of the intersection of both maps.
      static java.lang.Object invokeMethod​(java.lang.Object object, java.lang.String method, java.lang.Object arguments)
      Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily.
      static boolean is​(java.lang.Object self, java.lang.Object other)
      Identity check.
      static boolean isAllWhitespace​(java.lang.CharSequence self)
      True if a CharSequence only contains whitespace characters.
      static boolean isAllWhitespace​(java.lang.String self)
      True if a String only contains whitespace characters.
      static boolean isBigDecimal​(java.lang.CharSequence self)
      Determine if a CharSequence can be parsed as a BigDecimal.
      static boolean isBigDecimal​(java.lang.String self)
      Determine if a String can be parsed into a BigDecimal.
      static boolean isBigInteger​(java.lang.CharSequence self)
      Determine if a CharSequence can be parsed as a BigInteger.
      static boolean isBigInteger​(java.lang.String self)
      Determine if a String can be parsed into a BigInteger.
      static boolean isCase​(GString caseValue, java.lang.Object switchValue)
      'Case' implementation for a GString, which simply calls the equivalent method for String.
      static boolean isCase​(java.lang.CharSequence caseValue, java.lang.Object switchValue)
      'Case' implementation for a CharSequence, which simply calls the equivalent method for String.
      static boolean isCase​(java.lang.Class caseValue, java.lang.Object switchValue)
      Special 'Case' implementation for Class, which allows testing for a certain class in a switch statement.
      static boolean isCase​(java.lang.Number caseValue, java.lang.Number switchValue)
      Special 'case' implementation for all numbers, which delegates to the compareTo() method for comparing numbers of different types.
      static boolean isCase​(java.lang.Object caseValue, java.lang.Object switchValue)
      Method for overloading the behavior of the 'case' method in switch statements.
      static boolean isCase​(java.lang.String caseValue, java.lang.Object switchValue)
      'Case' implementation for a String, which uses String#equals(Object) in order to allow Strings to be used in switch statements.
      static boolean isCase​(java.util.Collection caseValue, java.lang.Object switchValue)
      'Case' implementation for collections which tests if the 'switch' operand is contained in any of the 'case' values.
      static boolean isCase​(java.util.Map caseValue, java.lang.Object switchValue)
      'Case' implementation for maps which tests the groovy truth value obtained using the 'switch' operand as key.
      static boolean isCase​(java.util.regex.Pattern caseValue, java.lang.Object switchValue)
      'Case' implementation for the Pattern class, which allows testing a String against a number of regular expressions.
      static boolean isDigit​(java.lang.Character self)
      Determines if a character is a digit.
      static boolean isDouble​(java.lang.CharSequence self)
      Determine if a CharSequence can be parsed as a Double.
      static boolean isDouble​(java.lang.String self)
      Determine if a String can be parsed into a Double.
      static boolean isFloat​(java.lang.CharSequence self)
      Determine if a CharSequence can be parsed as a Float.
      static boolean isFloat​(java.lang.String self)
      Determine if a String can be parsed into a Float.
      static boolean isInteger​(java.lang.CharSequence self)
      Determine if a CharSequence can be parsed as an Integer.
      static boolean isInteger​(java.lang.String self)
      Determine if a String can be parsed into an Integer.
      static boolean isLetter​(java.lang.Character self)
      Determines if a character is a letter.
      static boolean isLetterOrDigit​(java.lang.Character self)
      Determines if a character is a letter or digit.
      static boolean isLong​(java.lang.CharSequence self)
      Determine if a CharSequence can be parsed as a Long.
      static boolean isLong​(java.lang.String self)
      Determine if a String can be parsed into a Long.
      static boolean isLowerCase​(java.lang.Character self)
      Determine if a Character is lowercase.
      static boolean isNumber​(java.lang.CharSequence self)
      Determine if a CharSequence can be parsed as a Number.
      static boolean isNumber​(java.lang.String self)
      Determine if a String can be parsed into a Number.
      static boolean isUpperCase​(java.lang.Character self)
      Determine if a Character is uppercase.
      static boolean isWhitespace​(java.lang.Character self)
      Determines if a character is a whitespace character.
      static java.util.Iterator<java.lang.Byte> iterator​(java.io.DataInputStream self)
      Standard iterator for a data input stream which iterates through the stream content a Byte at a time.
      static java.util.Iterator<java.lang.Byte> iterator​(java.io.InputStream self)
      Standard iterator for a input stream which iterates through the stream content in a byte-based fashion.
      static java.util.Iterator<java.lang.String> iterator​(java.io.Reader self)
      Creates an iterator which will traverse through the reader a line at a time.
      static java.util.Iterator iterator​(java.lang.Object o)
      Attempts to create an Iterator for the given object by first converting it to a Collection.
      static <T> java.util.Iterator<T> iterator​(java.util.Enumeration<T> enumeration)
      Allows an Enumeration to behave like an Iterator.
      static <T> java.util.Iterator<T> iterator​(java.util.Iterator<T> self)
      An identity function for iterators, supporting 'duck-typing' when trying to get an iterator for each object within a collection, some of which may already be iterators.
      static java.util.Iterator iterator​(java.util.regex.Matcher matcher)
      Returns an Iterator which traverses each match.
      static <T> java.util.Iterator<T> iterator​(T[] a)
      Attempts to create an Iterator for the given object by first converting it to a Collection.
      static java.lang.String join​(java.lang.Object[] self, java.lang.String separator)
      Concatenates the toString() representation of each items in this array, with the given String as a separator between each item.
      static java.lang.String join​(java.util.Collection self, java.lang.String separator)
      Concatenates the toString() representation of each item in this collection, with the given String as a separator between each item.
      static java.lang.String join​(java.util.Iterator<java.lang.Object> self, java.lang.String separator)
      Concatenates the toString() representation of each item from the iterator, with the given String as a separator between each item.
      static <T> T last​(java.lang.Iterable<T> self)
      Returns the last item from the Iterable.
      static <T> T last​(java.util.List<T> self)
      Returns the last item from the List.
      static <T> T last​(T[] self)
      Returns the last item from the array.
      static java.io.File leftShift​(java.io.File file, byte[] bytes)
      Write bytes to a File.
      static java.io.File leftShift​(java.io.File file, java.io.InputStream data)
      Append binary data to the file.
      static java.io.File leftShift​(java.io.File file, java.lang.Object text)
      Write the text to the File.
      static void leftShift​(java.io.ObjectOutputStream self, java.lang.Object value)
      Overloads the leftShift operator to add objects to an ObjectOutputStream.
      static java.io.OutputStream leftShift​(java.io.OutputStream self, byte[] value)
      Overloads the leftShift operator to provide an append mechanism to add bytes to a stream.
      static java.io.OutputStream leftShift​(java.io.OutputStream self, java.io.InputStream in)
      Pipe an InputStream into an OutputStream for efficient stream copying.
      static java.io.Writer leftShift​(java.io.OutputStream self, java.lang.Object value)
      Overloads the leftShift operator to provide an append mechanism to add values to a stream.
      static java.io.Writer leftShift​(java.io.Writer self, java.lang.Object value)
      Overloads the left shift operator to provide a mechanism to append values to a writer.
      static java.lang.StringBuilder leftShift​(java.lang.CharSequence self, java.lang.Object value)
      Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a CharSequence.
      static java.lang.Number leftShift​(java.lang.Number self, java.lang.Number operand)
      Implementation of the left shift operator for integral types.
      static java.lang.StringBuffer leftShift​(java.lang.StringBuffer self, java.lang.Object value)
      Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuffer.
      static java.lang.StringBuilder leftShift​(java.lang.StringBuilder self, java.lang.Object value)
      Overloads the left shift operator to provide syntactic sugar for appending to a StringBuilder.
      static java.lang.StringBuffer leftShift​(java.lang.String self, java.lang.Object value)
      Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String.
      static java.io.OutputStream leftShift​(java.net.Socket self, byte[] value)
      Overloads the left shift operator to provide an append mechanism to add bytes to the output stream of a socket
      static java.io.Writer leftShift​(java.net.Socket self, java.lang.Object value)
      Overloads the left shift operator to provide an append mechanism to add things to the output stream of a socket
      static <T> java.util.Collection<T> leftShift​(java.util.Collection<T> self, T value)
      Overloads the left shift operator to provide an easy way to append objects to a Collection.
      static <T> java.util.concurrent.BlockingQueue<T> leftShift​(java.util.concurrent.BlockingQueue<T> self, T value)
      Overloads the left shift operator to provide an easy way to append objects to a BlockingQueue.
      static <K,​V>
      java.util.Map<K,​V>
      leftShift​(java.util.Map<K,​V> self, java.util.Map.Entry<K,​V> entry)
      Overloads the left shift operator to provide an easy way to append Map.Entry values to a Map.
      static <K,​V>
      java.util.Map<K,​V>
      leftShift​(java.util.Map<K,​V> self, java.util.Map<K,​V> other)
      Overloads the left shift operator to provide an easy way to put one maps entries into another map.
      static boolean matches​(java.lang.CharSequence self, java.util.regex.Pattern pattern)
      Tells whether or not a CharSequence matches the given compiled regular expression Pattern.
      static boolean matches​(java.lang.String self, java.util.regex.Pattern pattern)
      Tells whether or not self matches the given compiled regular expression Pattern.
      static <T> T max​(java.util.Collection<T> self)
      Adds max() method to Collection objects.
      static <T> T max​(java.util.Collection<T> self, Closure closure)
      Selects an item in the collection having the maximum value as determined by the supplied closure.
      static <T> T max​(java.util.Collection<T> self, java.util.Comparator<T> comparator)
      Selects the maximum value found in the collection using the given comparator.
      static <T> T max​(java.util.Iterator<T> self)
      Adds max() method to Iterator objects.
      static <T> T max​(java.util.Iterator<T> self, Closure closure)
      Selects the maximum value found from the Iterator using the closure to determine the correct ordering.
      static <T> T max​(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
      Selects the maximum value found from the Iterator using the given comparator.
      static <K,​V>
      java.util.Map.Entry<K,​V>
      max​(java.util.Map<K,​V> self, Closure closure)
      Selects an entry in the map having the maximum calculated value as determined by the supplied closure.
      static <T> T max​(T[] self)
      Adds max() method to Object arrays.
      static <T> T max​(T[] self, Closure closure)
      Selects the maximum value found from the Object array using the closure to determine the correct ordering.
      static <T> T max​(T[] self, java.util.Comparator<T> comparator)
      Selects the maximum value found from the Object array using the given comparator.
      static MetaClass metaClass​(java.lang.Class self, Closure closure)
      Sets/updates the metaclass for a given class to a closure.
      static MetaClass metaClass​(java.lang.Object self, Closure closure)
      Sets/updates the metaclass for a given object to a closure.
      static <T> T min​(java.util.Collection<T> self)
      Adds min() method to Collection objects.
      static <T> T min​(java.util.Collection<T> self, Closure closure)
      Selects an item in the collection having the minimum value as determined by the supplied closure.
      static <T> T min​(java.util.Collection<T> self, java.util.Comparator<T> comparator)
      Selects the minimum value found in the collection using the given comparator.
      static <T> T min​(java.util.Iterator<T> self)
      Adds min() method to Iterator objects.
      static <T> T min​(java.util.Iterator<T> self, Closure closure)
      Selects the minimum value found from the Iterator using the closure to determine the correct ordering.
      static <T> T min​(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
      Selects the minimum value found from the Iterator using the given comparator.
      static <K,​V>
      java.util.Map.Entry<K,​V>
      min​(java.util.Map<K,​V> self, Closure closure)
      Selects an entry in the map having the minimum calculated value as determined by the supplied closure.
      static <T> T min​(T[] self)
      Adds min() method to Object arrays.
      static <T> T min​(T[] self, Closure closure)
      Selects the minimum value found from the Object array using the closure to determine the correct ordering.
      static <T> T min​(T[] self, java.util.Comparator<T> comparator)
      Selects the minimum value found from the Object array using the given comparator.
      static java.lang.Number minus​(java.lang.Character left, java.lang.Character right)
      Subtract one Character from another.
      static java.lang.Number minus​(java.lang.Character left, java.lang.Number right)
      Subtract a Number from a Character.
      static java.lang.CharSequence minus​(java.lang.CharSequence self, java.lang.Object target)
      Remove a part of a CharSequence by replacing the first occurrence of target within self with '' and returns the result.
      static java.lang.Number minus​(java.lang.Number left, java.lang.Character right)
      Subtract a Character from a Number.
      static java.lang.String minus​(java.lang.String self, java.lang.Object target)
      Remove a part of a String.
      static <T> java.util.List<T> minus​(java.util.List<T> self, java.lang.Iterable<?> removeMe)
      Create a List composed of the elements of the first list minus every occurrence of elements of the given Iterable.
      static <T> java.util.List<T> minus​(java.util.List<T> self, java.lang.Object removeMe)
      Create a new List composed of the elements of the first list minus every occurrence of the given element to remove.
      static <T> java.util.List<T> minus​(java.util.List<T> self, java.util.Collection<?> removeMe)
      Create a List composed of the elements of the first list minus every occurrence of elements of the given Collection.
      static <K,​V>
      java.util.Map<K,​V>
      minus​(java.util.Map<K,​V> self, java.util.Map removeMe)
      Create a Map composed of the entries of the first map minus the entries of the given map.
      static <T> java.util.Set<T> minus​(java.util.Set<T> self, java.lang.Iterable<?> removeMe)
      Create a Set composed of the elements of the first Set minus the elements from the given Iterable.
      static <T> java.util.Set<T> minus​(java.util.Set<T> self, java.lang.Object removeMe)
      Create a Set composed of the elements of the first Set minus the given element.
      static <T> java.util.Set<T> minus​(java.util.Set<T> self, java.util.Collection<?> removeMe)
      Create a Set composed of the elements of the first Set minus the elements of the given Collection.
      static <T> T[] minus​(T[] self, java.lang.Iterable removeMe)
      Create an array composed of the elements of the first array minus the elements of the given Iterable.
      static <T> T[] minus​(T[] self, java.lang.Object removeMe)
      Create a new object array composed of the elements of the first array minus the element to remove.
      static <T> T[] minus​(T[] self, java.lang.Object[] removeMe)
      Create an array composed of the elements of the first array minus the elements of the given array.
      static void mixin​(MetaClass self, java.lang.Class categoryClass)
      Extend class globally with category methods.
      static void mixin​(MetaClass self, java.lang.Class[] categoryClass)
      Extend class globally with category methods.
      static void mixin​(MetaClass self, java.util.List<java.lang.Class> categoryClasses)
      Extend object with category methods.
      static void mixin​(java.lang.Class self, java.lang.Class categoryClass)
      Extend class globally with category methods.
      static void mixin​(java.lang.Class self, java.lang.Class[] categoryClass)
      Extend class globally with category methods.
      static void mixin​(java.lang.Class self, java.util.List<java.lang.Class> categoryClasses)
      Extend class globally with category methods.
      static java.lang.Number mod​(java.lang.Number left, java.lang.Number right)
      Performs a division modulus operation.
      static java.lang.Number multiply​(java.lang.Character left, java.lang.Character right)
      Multiply two Characters.
      static java.lang.Number multiply​(java.lang.Character left, java.lang.Number right)
      Multiply a Character by a Number.
      static java.lang.CharSequence multiply​(java.lang.CharSequence self, java.lang.Number factor)
      Repeat a CharSequence a certain number of times.
      static java.lang.Number multiply​(java.lang.Number left, java.lang.Character right)
      Multiply a Number by a Character.
      static java.lang.String multiply​(java.lang.String self, java.lang.Number factor)
      Repeat a String a certain number of times.
      static java.lang.Number multiply​(java.math.BigDecimal left, java.lang.Double right)
      Multiply a BigDecimal and a Double.
      static java.lang.Number multiply​(java.math.BigDecimal left, java.math.BigInteger right)
      Multiply a BigDecimal and a BigInteger.
      static <T> java.util.List<T> multiply​(java.util.Collection<T> self, java.lang.Number factor)
      Create a List composed of the elements of this list, repeated a certain number of times.
      static java.io.DataInputStream newDataInputStream​(java.io.File file)
      Create a data input stream for this file
      static java.io.DataOutputStream newDataOutputStream​(java.io.File file)
      Creates a new data output stream for this file.
      static java.io.BufferedInputStream newInputStream​(java.io.File file)
      Creates a buffered input stream for this file.
      static java.io.BufferedInputStream newInputStream​(java.net.URL url)
      Creates a buffered input stream for this URL.
      static java.io.BufferedInputStream newInputStream​(java.net.URL url, java.util.Map parameters)
      Creates a buffered input stream for this URL.
      static <T> T newInstance​(java.lang.Class<T> c)
      Convenience method to dynamically create a new instance of this class.
      static <T> T newInstance​(java.lang.Class<T> c, java.lang.Object[] args)
      Helper to construct a new instance from the given arguments.
      static java.io.ObjectInputStream newObjectInputStream​(java.io.File file)
      Create an object input stream for this file.
      static java.io.ObjectInputStream newObjectInputStream​(java.io.File file, java.lang.ClassLoader classLoader)
      Create an object input stream for this file using the given class loader.
      static java.io.ObjectInputStream newObjectInputStream​(java.io.InputStream inputStream)
      Create an object input stream for this input stream.
      static java.io.ObjectInputStream newObjectInputStream​(java.io.InputStream inputStream, java.lang.ClassLoader classLoader)
      Create an object input stream for this input stream using the given class loader.
      static java.io.ObjectOutputStream newObjectOutputStream​(java.io.File file)
      Create an object output stream for this file.
      static java.io.ObjectOutputStream newObjectOutputStream​(java.io.OutputStream outputStream)
      Create an object output stream for this output stream.
      static java.io.BufferedOutputStream newOutputStream​(java.io.File file)
      Create a buffered output stream for this file.
      static java.io.PrintWriter newPrintWriter​(java.io.File file)
      Create a new PrintWriter for this file.
      static java.io.PrintWriter newPrintWriter​(java.io.File file, java.lang.String charset)
      Create a new PrintWriter for this file, using specified charset.
      static java.io.PrintWriter newPrintWriter​(java.io.Writer writer)
      Create a new PrintWriter for this file, using specified charset.
      static java.io.BufferedReader newReader​(java.io.File file)
      Create a buffered reader for this file.
      static java.io.BufferedReader newReader​(java.io.File file, java.lang.String charset)
      Create a buffered reader for this file, using the specified charset as the encoding.
      static java.io.BufferedReader newReader​(java.io.InputStream self)
      Creates a reader for this input stream.
      static java.io.BufferedReader newReader​(java.io.InputStream self, java.lang.String charset)
      Creates a reader for this input stream, using the specified charset as the encoding.
      static java.io.BufferedReader newReader​(java.net.URL url)
      Creates a buffered reader for this URL.
      static java.io.BufferedReader newReader​(java.net.URL url, java.lang.String charset)
      Creates a buffered reader for this URL using the given encoding.
      static java.io.BufferedReader newReader​(java.net.URL url, java.util.Map parameters)
      Creates a buffered reader for this URL.
      static java.io.BufferedReader newReader​(java.net.URL url, java.util.Map parameters, java.lang.String charset)
      Creates a buffered reader for this URL using the given encoding.
      static java.io.BufferedWriter newWriter​(java.io.File file)
      Create a buffered writer for this file.
      static java.io.BufferedWriter newWriter​(java.io.File file, boolean append)
      Creates a buffered writer for this file, optionally appending to the existing file content.
      static java.io.BufferedWriter newWriter​(java.io.File file, java.lang.String charset)
      Creates a buffered writer for this file, writing data using the given encoding.
      static java.io.BufferedWriter newWriter​(java.io.File file, java.lang.String charset, boolean append)
      Helper method to create a buffered writer for a file.
      static java.lang.Character next​(java.lang.Character self)
      Increment a Character by one.
      static java.lang.CharSequence next​(java.lang.CharSequence self)
      This method is called by the ++ operator for the class CharSequence.
      static java.lang.Number next​(java.lang.Number self)
      Increment a Number by one.
      static java.lang.String next​(java.lang.String self)
      This method is called by the ++ operator for the class String.
      static java.lang.CharSequence normalize​(java.lang.CharSequence self)
      Return a CharSequence with linefeeds and carriage returns normalized to linefeeds.
      static java.lang.String normalize​(java.lang.String self)
      Return a String with linefeeds and carriage returns normalized to linefeeds.
      static int numberAwareCompareTo​(java.lang.Comparable self, java.lang.Comparable other)
      Provides a method that compares two comparables using Groovy's default number aware comparator.
      static java.lang.Boolean or​(java.lang.Boolean left, java.lang.Boolean right)
      Logical disjunction of two boolean operators
      static java.lang.Number or​(java.lang.Number left, java.lang.Number right)
      Bitwise OR together two numbers.
      static java.util.BitSet or​(java.util.BitSet left, java.util.BitSet right)
      Bitwise OR together two BitSets.
      static java.lang.CharSequence padLeft​(java.lang.CharSequence self, java.lang.Number numberOfChars)
      Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character to the left as many times as needed.
      static java.lang.CharSequence padLeft​(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
      Pad a CharSequence to a minimum length specified by numberOfChars, adding the supplied padding CharSequence as many times as needed to the left.
      static java.lang.String padLeft​(java.lang.String self, java.lang.Number numberOfChars)
      Pad a String to a minimum length specified by numberOfChars by adding the space character to the left as many times as needed.
      static java.lang.String padLeft​(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
      Pad a String to a minimum length specified by numberOfChars, adding the supplied padding String as many times as needed to the left.
      static java.lang.CharSequence padRight​(java.lang.CharSequence self, java.lang.Number numberOfChars)
      Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character to the right as many times as needed.
      static java.lang.CharSequence padRight​(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
      Pad a CharSequence to a minimum length specified by numberOfChars, adding the supplied padding CharSequence as many times as needed to the right.
      static java.lang.String padRight​(java.lang.String self, java.lang.Number numberOfChars)
      Pad a String to a minimum length specified by numberOfChars by adding the space character to the right as many times as needed.
      static java.lang.String padRight​(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
      Pad a String to a minimum length specified by numberOfChars, adding the supplied padding String as many times as needed to the right.
      static <T> java.util.Set<java.util.List<T>> permutations​(java.util.List<T> self)
      Finds all permutations of a collection.
      static java.lang.Number plus​(java.lang.Character left, java.lang.Character right)
      Add one Character to another.
      static java.lang.Number plus​(java.lang.Character left, java.lang.Number right)
      Add a Character and a Number.
      static java.lang.CharSequence plus​(java.lang.CharSequence left, java.lang.Object value)
      Appends the String representation of the given operand to this string.
      static java.lang.Number plus​(java.lang.Number left, java.lang.Character right)
      Add a Number and a Character.
      static java.lang.String plus​(java.lang.Number value, java.lang.String right)
      Appends a String to the string representation of this number.
      static java.lang.String plus​(java.lang.StringBuffer left, java.lang.String value)
      Appends a String to this StringBuffer.
      static java.lang.String plus​(java.lang.String left, java.lang.Object value)
      Appends the String representation of the given operand to this string.
      static <T> java.util.Collection<T> plus​(java.util.Collection<T> left, java.lang.Iterable<T> right)
      Create a Collection as a union of a Collection and an Iterable.
      static <T> java.util.Collection<T> plus​(java.util.Collection<T> left, java.util.Collection<T> right)
      Create a Collection as a union of two collections.
      static <T> java.util.Collection<T> plus​(java.util.Collection<T> left, T right)
      Create a collection as a union of a Collection and an Object.
      static <T> java.util.List<T> plus​(java.util.List<T> self, int index, java.lang.Iterable<T> 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.
      static <T> java.util.List<T> plus​(java.util.List<T> self, int index, java.util.List<T> additions)
      Creates a new List by inserting all of the elements in the given additions List to the elements from the original List at the specified index.
      static <T> java.util.List<T> plus​(java.util.List<T> self, int index, T[] items)
      Creates a new List by inserting all of the elements in the specified array to the elements from the original List at the specified index.
      static <K,​V>
      java.util.Map<K,​V>
      plus​(java.util.Map<K,​V> self, java.util.Collection<java.util.Map.Entry<K,​V>> entries)
      Returns a new Map containing all entries from self and entries, giving precedence to entries.
      static <K,​V>
      java.util.Map<K,​V>
      plus​(java.util.Map<K,​V> left, java.util.Map<K,​V> right)
      Returns a new Map containing all entries from left and right, giving precedence to right.
      static <T> T[] plus​(T[] left, java.lang.Iterable<T> right)
      Create an array containing elements from an original array plus those from an Iterable.
      static <T> T[] plus​(T[] left, java.util.Collection<T> right)
      Create an array containing elements from an original array plus those from a Collection.
      static <T> T[] plus​(T[] left, T right)
      Create an array containing elements from an original array plus an additional appended element.
      static <T> T[] plus​(T[] left, T[] right)
      Create an array as a union of two arrays.
      static <T> T pop​(java.util.List<T> self)
      Removes the last item from the List.
      static java.lang.Number power​(java.lang.Integer self, java.lang.Integer exponent)
      Power of an integer to an integer certain exponent.
      static java.lang.Number power​(java.lang.Long self, java.lang.Integer exponent)
      Power of a long to an integer certain exponent.
      static java.lang.Number power​(java.lang.Number self, java.lang.Number exponent)
      Power of a Number to a certain exponent.
      static java.lang.Number power​(java.math.BigDecimal self, java.lang.Integer exponent)
      Power of a BigDecimal to an integer certain exponent.
      static java.lang.Number power​(java.math.BigInteger self, java.lang.Integer exponent)
      Power of a BigInteger to an integer certain exponent.
      static java.lang.Character previous​(java.lang.Character self)
      Decrement a Character by one.
      static java.lang.CharSequence previous​(java.lang.CharSequence self)
      This method is called by the -- operator for the class CharSequence.
      static java.lang.Number previous​(java.lang.Number self)
      Decrement a Number by one.
      static java.lang.String previous​(java.lang.String self)
      This method is called by the -- operator for the class String.
      protected static java.lang.Object primitiveArrayGet​(java.lang.Object self, int idx)
      Implements the getAt(int) method for primitive type arrays.
      protected static java.util.List primitiveArrayGet​(java.lang.Object self, Range range)
      Implements the getAt(Range) method for primitive type arrays.
      protected static java.util.List primitiveArrayGet​(java.lang.Object self, java.util.Collection indices)
      Implements the getAt(Collection) method for primitive type arrays.
      protected static java.lang.Object primitiveArrayPut​(java.lang.Object self, int idx, java.lang.Object newValue)
      Implements the setAt(int idx) method for primitive type arrays.
      static void print​(Closure self, java.lang.Object value)
      Print a value to the standard output stream.
      static void print​(java.io.PrintStream self, java.lang.Object value)
      Print a value formatted Groovy style to the print stream.
      static void print​(java.io.PrintWriter self, java.lang.Object value)
      Print a value formatted Groovy style to the print writer.
      static void print​(java.lang.Object self, java.io.PrintWriter out)
      Print to a console in interactive format.
      static void print​(java.lang.Object self, java.lang.Object value)
      Print a value formatted Groovy style to self if it is a Writer, otherwise to the standard output stream.
      static void printf​(java.lang.Object self, java.lang.String format, java.lang.Object arg)
      Prints a formatted string using the specified format string and arguments.
      static void printf​(java.lang.Object self, java.lang.String format, java.lang.Object[] values)
      Printf to a console (Only works with JDK1.5 or later).
      static void println​(Closure self)
      Print a linebreak to the standard output stream.
      static void println​(Closure self, java.lang.Object value)
      Print a value (followed by a newline) to the standard output stream.
      static void println​(java.io.PrintStream self, java.lang.Object value)
      Print a value formatted Groovy style (followed by a newline) to the print stream.
      static void println​(java.io.PrintWriter self, java.lang.Object value)
      Print a value formatted Groovy style (followed by a newline) to the print writer.
      static void println​(java.lang.Object self)
      Print a linebreak to the standard output stream.
      static void println​(java.lang.Object self, java.io.PrintWriter out)
      Print to a console in interactive format.
      static void println​(java.lang.Object self, java.lang.Object value)
      Print a value formatted Groovy style (followed by a newline) to self if it is a Writer, otherwise to the standard output stream.
      static <T> boolean push​(java.util.List<T> self, T value)
      Appends an item to the List.
      static <K,​V>
      java.util.Map<K,​V>
      putAll​(java.util.Map<K,​V> self, java.util.Collection<java.util.Map.Entry<K,​V>> entries)
      Provides an easy way to append multiple Map.Entry values to a Map.
      static void putAt​(java.lang.Object self, java.lang.String property, java.lang.Object newValue)
      Allows the subscript operator to be used to set dynamically named property values.
      static void putAt​(java.lang.StringBuffer self, EmptyRange range, java.lang.Object value)
      Support the range subscript operator for StringBuffer.
      static void putAt​(java.lang.StringBuffer self, IntRange range, java.lang.Object value)
      Support the range subscript operator for StringBuffer.
      static void putAt​(java.util.BitSet self, int index, boolean value)
      Support subscript-style assignment for a BitSet.
      static void putAt​(java.util.BitSet self, IntRange range, boolean value)
      Support assigning a range of values with a single assignment statement.
      static <T> void putAt​(java.util.List<T> self, int idx, T value)
      A helper method to allow lists to work with subscript operators.
      static void putAt​(java.util.List self, EmptyRange range, java.lang.Object value)
      A helper method to allow lists to work with subscript operators.
      static void putAt​(java.util.List self, EmptyRange range, java.util.Collection value)
      A helper method to allow lists to work with subscript operators.
      static void putAt​(java.util.List self, IntRange range, java.lang.Object value)
      List subscript assignment operator when given a range as the index.
      static void putAt​(java.util.List self, IntRange range, java.util.Collection col)
      List subscript assignment operator when given a range as the index and the assignment operand is a collection.
      static void putAt​(java.util.List self, java.util.List splice, java.lang.Object value)
      A helper method to allow lists to work with subscript operators.
      static void putAt​(java.util.List self, java.util.List splice, java.util.List values)
      A helper method to allow lists to work with subscript operators.
      static <K,​V>
      V
      putAt​(java.util.Map<K,​V> self, K key, V value)
      A helper method to allow maps to work with subscript operators
      static byte[] readBytes​(java.io.File file)
      Reads the content of the file into a byte array.
      static java.lang.String readLine​(java.io.Reader self)
      Read a single, whole line from the given Reader.
      static java.util.List<java.lang.String> readLines​(java.io.File file)
      Reads the file into a list of Strings, with one item for each line.
      static java.util.List<java.lang.String> readLines​(java.io.File file, java.lang.String charset)
      Reads the file into a list of Strings, with one item for each line.
      static java.util.List<java.lang.String> readLines​(java.io.InputStream stream)
      Reads the stream into a list, with one element for each line.
      static java.util.List<java.lang.String> readLines​(java.io.InputStream stream, java.lang.String charset)
      Reads the stream into a list, with one element for each line.
      static java.util.List<java.lang.String> readLines​(java.io.Reader reader)
      Reads the reader into a list of Strings, with one entry for each line.
      static java.util.List<java.lang.CharSequence> readLines​(java.lang.CharSequence self)
      Return the lines of a CharSequence as a List of CharSequence.
      static java.util.List<java.lang.String> readLines​(java.lang.String self)
      Return the lines of a String as a List of Strings.
      static java.util.List<java.lang.String> readLines​(java.net.URL self)
      Reads the URL contents into a list, with one element for each line.
      static java.util.List<java.lang.String> readLines​(java.net.URL self, java.lang.String charset)
      Reads the URL contents into a list, with one element for each line.
      static boolean removeAll​(java.util.Collection self, Closure condition)
      Modifies this collection by removing the elements that are matched according to the specified closure condition.
      static boolean removeAll​(java.util.Collection self, java.lang.Object[] items)
      Modifies this collection by removing its elements that are contained within the specified object array.
      static boolean renameTo​(java.io.File self, java.lang.String newPathName)
      Renames the file.
      static java.lang.CharSequence replaceAll​(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
      Replaces all occurrences of a captured group by the result of a closure on that text.
      static java.lang.CharSequence replaceAll​(java.lang.CharSequence self, java.lang.CharSequence regex, java.lang.CharSequence replacement)
      Replaces each substring of this CharSequence that matches the given regular expression with the given replacement.
      static java.lang.String replaceAll​(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
      Replaces all occurrences of a captured group by the result of a closure call on that text.
      static java.lang.CharSequence replaceAll​(java.lang.CharSequence self, java.util.regex.Pattern pattern, java.lang.CharSequence replacement)
      Replaces all substrings of a CharSequence that match the given compiled regular expression with the given replacement.
      static java.lang.String replaceAll​(java.lang.String self, java.lang.String regex, Closure closure)
      Replaces all occurrences of a captured group by the result of a closure on that text.
      static java.lang.String replaceAll​(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
      Replaces all occurrences of a captured group by the result of a closure call on that text.
      static java.lang.String replaceAll​(java.lang.String self, java.util.regex.Pattern pattern, java.lang.String replacement)
      Replaces all substrings of a String that match the given compiled regular expression with the given replacement.
      static java.lang.String replaceFirst​(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
      Replaces the first occurrence of a captured group by the result of a closure call on that text.
      static java.lang.String replaceFirst​(java.lang.CharSequence self, java.lang.CharSequence regex, java.lang.CharSequence replacement)
      Replaces the first substring of this CharSequence that matches the given regular expression with the given replacement.
      static java.lang.String replaceFirst​(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
      Replaces the first occurrence of a captured group by the result of a closure call on that text.
      static java.lang.CharSequence replaceFirst​(java.lang.CharSequence self, java.util.regex.Pattern pattern, java.lang.CharSequence replacement)
      Replaces the first substring of a CharSequence that matches the given compiled regular expression with the given replacement.
      static java.lang.String replaceFirst​(java.lang.String self, java.lang.String regex, Closure closure)
      Replaces the first occurrence of a captured group by the result of a closure call on that text.
      static java.lang.String replaceFirst​(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
      Replaces the first occurrence of a captured group by the result of a closure call on that text.
      static java.lang.String replaceFirst​(java.lang.String self, java.util.regex.Pattern pattern, java.lang.String replacement)
      Replaces the first substring of a String that matches the given compiled regular expression with the given replacement.
      static java.util.List<MetaMethod> respondsTo​(java.lang.Object self, java.lang.String name)
      Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of the arguments.
      static java.util.List<MetaMethod> respondsTo​(java.lang.Object self, java.lang.String name, java.lang.Object[] argTypes)
      Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.
      static boolean retainAll​(java.util.Collection self, Closure condition)
      Modifies this collection so that it retains only its elements that are matched according to the specified closure condition.
      static boolean retainAll​(java.util.Collection self, java.lang.Object[] items)
      Modifies this collection so that it retains only its elements that are contained in the specified array.
      static java.lang.CharSequence reverse​(java.lang.CharSequence self)
      Creates a new CharSequence which is the reverse (backwards) of this string
      static java.lang.String reverse​(java.lang.String self)
      Creates a new string which is the reverse (backwards) of this string
      static <T> java.util.Iterator<T> reverse​(java.util.Iterator<T> self)
      Reverses the iterator.
      static <T> java.util.List<T> reverse​(java.util.List<T> self)
      Creates a new List with the identical contents to this list but in reverse order.
      static <T> java.util.List<T> reverse​(java.util.List<T> self, boolean mutate)
      Reverses the elements in a list.
      static <T> T[] reverse​(T[] self)
      Creates a new array containing items which are the same as this array but in reverse order.
      static <T> T[] reverse​(T[] self, boolean mutate)
      Reverse the items in an array.
      static <T> java.util.List<T> reverseEach​(java.util.List<T> self, Closure closure)
      Iterate over each element of the list in the reverse order.
      static <K,​V>
      java.util.Map<K,​V>
      reverseEach​(java.util.Map<K,​V> self, Closure closure)
      Allows a Map to be iterated through in reverse order using a closure.
      static <T> T[] reverseEach​(T[] self, Closure closure)
      Iterate over each element of the array in the reverse order.
      static java.lang.Number rightShift​(java.lang.Number self, java.lang.Number operand)
      Implementation of the right shift operator for integral types.
      static java.lang.Number rightShiftUnsigned​(java.lang.Number self, java.lang.Number operand)
      Implementation of the right shift (unsigned) operator for integral types.
      static long round​(java.lang.Double number)
      Round the value
      static double round​(java.lang.Double number, int precision)
      Round the value
      static int round​(java.lang.Float number)
      Round the value
      static float round​(java.lang.Float number, int precision)
      Round the value
      static java.util.TimerTask runAfter​(java.util.Timer timer, int delay, Closure closure)
      Allows a simple syntax for using timers.
      static void setBytes​(java.io.File file, byte[] bytes)
      Write the bytes from the byte array to the File.
      static void setBytes​(java.io.OutputStream os, byte[] bytes)
      Write the byte[] to the output stream.
      static void setIndex​(java.util.regex.Matcher matcher, int idx)
      Set the position of the given Matcher to the given index.
      static void setMetaClass​(java.lang.Class self, MetaClass metaClass)
      Sets the metaclass for a given class.
      static void setMetaClass​(java.lang.Object self, MetaClass metaClass)
      Set the metaclass for an object
      static void setText​(java.io.File file, java.lang.String text)
      Synonym for write(text) allowing file.text = 'foo'.
      static void setText​(java.io.File file, java.lang.String text, java.lang.String charset)
      Synonym for write(text, charset) allowing:
      static int size​(boolean[] array)
      Allows arrays to behave similar to collections.
      static int size​(byte[] array)
      Allows arrays to behave similar to collections.
      static int size​(char[] array)
      Allows arrays to behave similar to collections.
      static int size​(double[] array)
      Allows arrays to behave similar to collections.
      static int size​(float[] array)
      Allows arrays to behave similar to collections.
      static int size​(int[] array)
      Allows arrays to behave similar to collections.
      static int size​(long[] array)
      Allows arrays to behave similar to collections.
      static int size​(short[] array)
      Allows arrays to behave similar to collections.
      static long size​(java.io.File self)
      Provide the standard Groovy size() method for File.
      static int size​(java.lang.CharSequence text)
      Provide the standard Groovy size() method for CharSequence.
      static int size​(java.lang.Object[] self)
      Provide the standard Groovy size() method for an array.
      static int size​(java.lang.String text)
      Provide the standard Groovy size() method for String.
      static int size​(java.lang.StringBuffer buffer)
      Provide the standard Groovy size() method for StringBuffer.
      static int size​(java.util.Iterator self)
      Provide the standard Groovy size() method for Iterator.
      static long size​(java.util.regex.Matcher self)
      Provide the standard Groovy size() method for Matcher.
      static <T> java.util.List<T> sort​(java.util.Collection<T> self)
      Sorts the Collection.
      static <T> java.util.List<T> sort​(java.util.Collection<T> self, boolean mutate)
      Sorts the Collection.
      static <T> java.util.List<T> sort​(java.util.Collection<T> self, boolean mutate, Closure closure)
      Sorts this Collection using the given Closure to determine the correct ordering.
      static <T> java.util.List<T> sort​(java.util.Collection<T> self, boolean mutate, java.util.Comparator<T> comparator)
      Sorts the Collection using the given Comparator.
      static <T> java.util.List<T> sort​(java.util.Collection<T> self, Closure closure)
      Sorts this Collection using the given Closure to determine the correct ordering.
      static <T> java.util.List<T> sort​(java.util.Collection<T> self, java.util.Comparator<T> comparator)
      Sorts the Collection using the given Comparator.
      static <T> java.util.Iterator<T> sort​(java.util.Iterator<T> self)
      Sorts the given iterator items into a sorted iterator.
      static <T> java.util.Iterator<T> sort​(java.util.Iterator<T> self, Closure closure)
      Sorts the given iterator items into a sorted iterator using the Closure to determine the correct ordering.
      static <T> java.util.Iterator<T> sort​(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
      Sorts the given iterator items into a sorted iterator using the comparator.
      static <K,​V>
      java.util.Map<K,​V>
      sort​(java.util.Map<K,​V> self)
      Sorts the elements from the given map into a new ordered Map using the natural ordering of the keys to determine the ordering.
      static <K,​V>
      java.util.Map<K,​V>
      sort​(java.util.Map<K,​V> self, Closure closure)
      Sorts the elements from the given map into a new ordered map using the closure as a comparator to determine the ordering.
      static <K,​V>
      java.util.Map<K,​V>
      sort​(java.util.Map<K,​V> self, java.util.Comparator<K> comparator)
      Sorts the elements from the given map into a new ordered Map using the specified key comparator to determine the ordering.
      static <K,​V>
      java.util.SortedMap<K,​V>
      sort​(java.util.SortedMap<K,​V> self)
      Avoids doing unnecessary work when sorting an already sorted map (i.e.
      static <T> java.util.SortedSet<T> sort​(java.util.SortedSet<T> self)
      Avoids doing unnecessary work when sorting an already sorted set (i.e.
      static <T> T[] sort​(T[] self)
      Modifies this array so that its elements are in sorted order.
      static <T> T[] sort​(T[] self, boolean mutate)
      Sorts the given array into sorted order.
      static <T> T[] sort​(T[] self, boolean mutate, Closure closure)
      Modifies this array so that its elements are in sorted order using the Closure to determine the correct ordering.
      static <T> T[] sort​(T[] self, boolean mutate, java.util.Comparator<T> comparator)
      Modifies this array so that its elements are in sorted order as determined by the given comparator.
      static <T> T[] sort​(T[] self, Closure closure)
      Sorts the elements from this array into a newly created array using the Closure to determine the correct ordering.
      static <T> T[] sort​(T[] self, java.util.Comparator<T> comparator)
      Sorts the given array into sorted order using the given comparator.
      static java.lang.String[] split​(GString self)
      Convenience method to split a GString (with whitespace as delimiter).
      static java.lang.CharSequence[] split​(java.lang.CharSequence self)
      Convenience method to split a CharSequence (with whitespace as delimiter).
      static java.util.Collection split​(java.lang.Object self, Closure closure)
      Splits all items into two lists based on the closure condition.
      static java.lang.String[] split​(java.lang.String self)
      Convenience method to split a string (with whitespace as delimiter) Like tokenize, but returns an Array of Strings instead of a List
      static <T> java.util.Collection<java.util.Collection<T>> split​(java.util.Collection<T> self, Closure closure)
      Splits all items into two collections based on the closure condition.
      static <T> T splitEachLine​(java.io.File self, java.lang.String regex, Closure<T> closure)
      Iterates through this file line by line, splitting each line using the given regex separator.
      static <T> T splitEachLine​(java.io.File self, java.lang.String regex, java.lang.String charset, Closure<T> closure)
      Iterates through this file line by line, splitting each line using the given regex separator.
      static <T> T splitEachLine​(java.io.File self, java.util.regex.Pattern pattern, Closure<T> closure)
      Iterates through this file line by line, splitting each line using the given separator Pattern.
      static <T> T splitEachLine​(java.io.File self, java.util.regex.Pattern pattern, java.lang.String charset, Closure<T> closure)
      Iterates through this file line by line, splitting each line using the given regex separator Pattern.
      static <T> T splitEachLine​(java.io.InputStream stream, java.lang.String regex, Closure<T> closure)
      Iterates through the given InputStream line by line, splitting each line using the given separator.
      static <T> T splitEachLine​(java.io.InputStream stream, java.lang.String regex, java.lang.String charset, Closure<T> closure)
      Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator.
      static <T> T splitEachLine​(java.io.InputStream stream, java.util.regex.Pattern pattern, Closure<T> closure)
      Iterates through the given InputStream line by line, splitting each line using the given separator Pattern.
      static <T> T splitEachLine​(java.io.InputStream stream, java.util.regex.Pattern pattern, java.lang.String charset, Closure<T> closure)
      Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator Pattern.
      static <T> T splitEachLine​(java.io.Reader self, java.lang.String regex, Closure<T> closure)
      Iterates through the given reader line by line, splitting each line using the given regex separator.
      static <T> T splitEachLine​(java.io.Reader self, java.util.regex.Pattern pattern, Closure<T> closure)
      Iterates through the given reader line by line, splitting each line using the given regex separator Pattern.
      static <T> T splitEachLine​(java.lang.CharSequence self, java.lang.CharSequence regex, Closure<T> closure)
      Iterates through the given CharSequence line by line, splitting each line using the given separator.
      static <T> T splitEachLine​(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure<T> closure)
      Iterates through the given CharSequence line by line, splitting each line using the given separator Pattern.
      static <T> T splitEachLine​(java.lang.String self, java.lang.String regex, Closure<T> closure)
      Iterates through the given String line by line, splitting each line using the given separator.
      static <T> T splitEachLine​(java.lang.String self, java.util.regex.Pattern pattern, Closure<T> closure)
      Iterates through the given String line by line, splitting each line using the given separator Pattern.
      static <T> T splitEachLine​(java.net.URL self, java.lang.String regex, Closure<T> closure)
      Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator.
      static <T> T splitEachLine​(java.net.URL self, java.lang.String regex, java.lang.String charset, Closure<T> closure)
      Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator.
      static <T> T splitEachLine​(java.net.URL self, java.util.regex.Pattern pattern, Closure<T> closure)
      Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern.
      static <T> T splitEachLine​(java.net.URL self, java.util.regex.Pattern pattern, java.lang.String charset, Closure<T> closure)
      Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern.
      static SpreadMap spread​(java.util.Map self)
      static java.lang.String sprintf​(java.lang.Object self, java.lang.String format, java.lang.Object arg)
      Returns a formatted string using the specified format string and arguments.
      static java.lang.String sprintf​(java.lang.Object self, java.lang.String format, java.lang.Object[] values)
      Sprintf to a string (Only works with JDK1.5 or later).
      static void step​(java.lang.Number self, java.lang.Number to, java.lang.Number stepNumber, Closure closure)
      Iterates from this number up to the given number using a step increment.
      static java.lang.CharSequence stripIndent​(java.lang.CharSequence self)
      Strip leading spaces from every line in a CharSequence.
      static java.lang.CharSequence stripIndent​(java.lang.CharSequence self, int numChars)
      Strip numChar leading characters from every line in a CharSequence.
      static java.lang.String stripIndent​(java.lang.String self)
      Strip leading spaces from every line in a String.
      static java.lang.String stripIndent​(java.lang.String self, int numChars)
      Strip numChar leading characters from every line in a String.
      static java.lang.CharSequence stripMargin​(java.lang.CharSequence self)
      Strip leading whitespace/control characters followed by '|' from every line in a CharSequence.
      static java.lang.CharSequence stripMargin​(java.lang.CharSequence self, char marginChar)
      Strip leading whitespace/control characters followed by marginChar from every line in a String.
      static java.lang.String stripMargin​(java.lang.CharSequence self, java.lang.CharSequence marginChar)
      Strip leading whitespace/control characters followed by marginChar from every line in a CharSequence.
      static java.lang.String stripMargin​(java.lang.String self)
      Strip leading whitespace/control characters followed by '|' from every line in a String.
      static java.lang.String stripMargin​(java.lang.String self, char marginChar)
      Strip leading whitespace/control characters followed by marginChar from every line in a String.
      static java.lang.String stripMargin​(java.lang.String self, java.lang.String marginChar)
      Strip leading whitespace/control characters followed by marginChar from every line in a String.
      static <K,​V>
      java.util.Map<K,​V>
      subMap​(java.util.Map<K,​V> map, java.util.Collection<K> keys)
      Creates a sub-Map containing the given keys.
      static <T> java.util.Set<java.util.List<T>> subsequences​(java.util.List<T> self)
      Finds all non-null subsequences of a list.
      static java.lang.Object sum​(java.lang.Object[] self)
      Sums the items in an array.
      static java.lang.Object sum​(java.lang.Object[] self, Closure closure)
      Sums the result of apply a closure to each item of an array.
      static java.lang.Object sum​(java.lang.Object[] self, java.lang.Object initialValue)
      Sums the items in an array, adding the result to some initial value.
      static java.lang.Object sum​(java.lang.Object[] self, java.lang.Object initialValue, Closure closure)
      Sums the result of applying a closure to each item of an array to some initial value.
      static java.lang.Object sum​(java.util.Collection self)
      Sums the items in a collection.
      static java.lang.Object sum​(java.util.Collection self, Closure closure)
      Sums the result of apply a closure to each item of a collection.
      static java.lang.Object sum​(java.util.Collection self, java.lang.Object initialValue)
      Sums the items in a collection, adding the result to some initial value.
      static java.lang.Object sum​(java.util.Collection self, java.lang.Object initialValue, Closure closure)
      Sums the result of applying a closure to each item of a collection to some initial value.
      static java.lang.Object sum​(java.util.Iterator<java.lang.Object> self)
      Sums the items from an Iterator.
      static java.lang.Object sum​(java.util.Iterator<java.lang.Object> self, Closure closure)
      Sums the result of apply a closure to each item returned from an iterator.
      static java.lang.Object sum​(java.util.Iterator<java.lang.Object> self, java.lang.Object initialValue)
      Sums the items from an Iterator, adding the result to some initial value.
      static java.lang.Object sum​(java.util.Iterator<java.lang.Object> self, java.lang.Object initialValue, Closure closure)
      Sums the result of applying a closure to each item of an Iterator to some initial value.
      static <T> java.util.List<T> tail​(java.util.List<T> self)
      Returns the items from the List excluding the first item.
      static <T> T[] tail​(T[] self)
      Returns the items from the Object array excluding the first item.
      static java.lang.CharSequence take​(java.lang.CharSequence self, int num)
      Returns the first num elements from this CharSequence.
      static <T> java.util.List<T> take​(java.lang.Iterable<T> self, int num)
      Returns the first num elements from the head of this Iterable.
      static <T> java.util.Iterator<T> take​(java.util.Iterator<T> self, int num)
      Returns an iterator of up to the first num elements from this iterator.
      static <T> java.util.List<T> take​(java.util.List<T> self, int num)
      Returns the first num elements from the head of this list.
      static <K,​V>
      java.util.Map<K,​V>
      take​(java.util.Map<K,​V> self, int num)
      Returns a new map containing the first num elements from the head of this map.
      static <T> T[] take​(T[] self, int num)
      Returns the first num elements from the head of this array.
      static java.lang.CharSequence takeWhile​(java.lang.CharSequence self, Closure closure)
      Returns the longest prefix of this CharSequence where each element passed to the given closure evalutes to true.
      static <T> java.util.List<T> takeWhile​(java.lang.Iterable<T> self, Closure condition)
      Returns a List containing the longest prefix of the elements from this Iterable where each element passed to the given closure evaluates to true.
      static <T> java.util.Iterator<T> takeWhile​(java.util.Iterator<T> self, Closure condition)
      Returns the longest prefix of elements in this iterator where each element passed to the given condition closure evaluates to true.
      static <T> java.util.List<T> takeWhile​(java.util.List<T> self, Closure condition)
      Returns the longest prefix of this list where each element passed to the given closure condition evaluates to true.
      static <K,​V>
      java.util.Map<K,​V>
      takeWhile​(java.util.Map<K,​V> self, Closure<?> condition)
      Returns the longest prefix of this Map where each entry (or key/value pair) when passed to the given closure evaluates to true.
      static <T> T[] takeWhile​(T[] self, Closure condition)
      Returns the longest prefix of this array where each element passed to the given closure evaluates to true.
      static void times​(java.lang.Number self, Closure closure)
      Executes the closure this many times, starting from zero.
      static java.lang.String toArrayString​(java.lang.Object[] self)
      Returns the string representation of the given array.
      static java.math.BigDecimal toBigDecimal​(java.lang.CharSequence self)
      Parse a CharSequence into a BigDecimal
      static java.math.BigDecimal toBigDecimal​(java.lang.Number self)
      Transform a Number into a BigDecimal
      static java.math.BigDecimal toBigDecimal​(java.lang.String self)
      Parse a String into a BigDecimal
      static java.math.BigInteger toBigInteger​(java.lang.CharSequence self)
      Parse a CharSequence into a BigInteger
      static java.math.BigInteger toBigInteger​(java.lang.Number self)
      Transform this Number into a BigInteger.
      static java.math.BigInteger toBigInteger​(java.lang.String self)
      Parse a String into a BigInteger
      static java.lang.Boolean toBoolean​(java.lang.Boolean self)
      Identity conversion which returns Boolean.TRUE for a true Boolean and Boolean.FALSE for a false Boolean.
      static java.lang.Boolean toBoolean​(java.lang.String self)
      Converts the given string into a Boolean object.
      static java.lang.Character toCharacter​(java.lang.String self)
      Converts the given string into a Character object using the first character in the string.
      static java.lang.Double toDouble​(java.lang.CharSequence self)
      Parse a CharSequence into a Double
      static java.lang.Double toDouble​(java.lang.Number self)
      Transform a Number into a Double
      static java.lang.Double toDouble​(java.lang.String self)
      Parse a String into a Double
      static java.lang.Float toFloat​(java.lang.CharSequence self)
      Parse a CharSequence into a Float
      static java.lang.Float toFloat​(java.lang.Number self)
      Transform a Number into a Float
      static java.lang.Float toFloat​(java.lang.String self)
      Parse a String into a Float
      static java.lang.Integer toInteger​(java.lang.CharSequence self)
      Parse a CharSequence into an Integer
      static java.lang.Integer toInteger​(java.lang.Number self)
      Transform a Number into an Integer
      static java.lang.Integer toInteger​(java.lang.String self)
      Parse a String into an Integer
      static java.util.List<java.lang.CharSequence> tokenize​(java.lang.CharSequence self)
      Tokenize a CharSequence (with a whitespace as the delimiter).
      static java.util.List<java.lang.CharSequence> tokenize​(java.lang.CharSequence self, java.lang.Character token)
      Tokenize a CharSequence based on the given character delimiter.
      static java.util.List<java.lang.CharSequence> tokenize​(java.lang.CharSequence self, java.lang.CharSequence token)
      Tokenize a CharSequence based on the given CharSequence delimiter.
      static java.util.List<java.lang.String> tokenize​(java.lang.String self)
      Tokenize a String (with a whitespace as the delimiter).
      static java.util.List<java.lang.String> tokenize​(java.lang.String self, java.lang.Character token)
      Tokenize a String based on the given character delimiter.
      static java.util.List<java.lang.String> tokenize​(java.lang.String self, java.lang.String token)
      Tokenize a String based on the given string delimiter.
      static java.util.List<java.lang.Boolean> toList​(boolean[] array)
      Converts this array to a List of the same size, with each element added to the list.
      static java.util.List<java.lang.Byte> toList​(byte[] array)
      Converts this array to a List of the same size, with each element added to the list.
      static java.util.List<java.lang.Character> toList​(char[] array)
      Converts this array to a List of the same size, with each element added to the list.
      static java.util.List<java.lang.Double> toList​(double[] array)
      Converts this array to a List of the same size, with each element added to the list.
      static java.util.List<java.lang.Float> toList​(float[] array)
      Converts this array to a List of the same size, with each element added to the list.
      static java.util.List<java.lang.Integer> toList​(int[] array)
      Converts this array to a List of the same size, with each element added to the list.
      static java.util.List<java.lang.Long> toList​(long[] array)
      Converts this array to a List of the same size, with each element added to the list.
      static java.util.List<java.lang.Short> toList​(short[] array)
      Converts this array to a List of the same size, with each element added to the list.
      static java.util.List<java.lang.CharSequence> toList​(java.lang.CharSequence self)
      Converts the given CharSequence into a List of CharSequence of one character.
      static <T> java.util.List<T> toList​(java.lang.Iterable<T> self)
      Convert an Iterable to a List.
      static java.util.List<java.lang.String> toList​(java.lang.String self)
      Converts the given String into a List of strings of one character.
      static <T> java.util.List<T> toList​(java.util.Collection<T> self)
      Convert a Collection to a List.
      static <T> java.util.List<T> toList​(java.util.Enumeration<T> self)
      Convert an enumeration to a List.
      static <T> java.util.List<T> toList​(java.util.Iterator<T> self)
      Convert an iterator to a List.
      static <T> java.util.List<T> toList​(T[] array)
      Allows conversion of arrays into a mutable List.
      static java.lang.String toListString​(java.util.Collection self)
      Returns the string representation of the given list.
      static java.lang.String toListString​(java.util.Collection self, int maxSize)
      Returns the string representation of the given list.
      static java.lang.Long toLong​(java.lang.CharSequence self)
      Parse a CharSequence into a Long
      static java.lang.Long toLong​(java.lang.Number self)
      Transform a Number into a Long
      static java.lang.Long toLong​(java.lang.String self)
      Parse a String into a Long
      static char toLowerCase​(java.lang.Character self)
      Converts the character to lowercase.
      static java.lang.String toMapString​(java.util.Map self)
      Returns the string representation of this map.
      static java.lang.String toMapString​(java.util.Map self, int maxSize)
      Returns the string representation of this map.
      static java.util.Set<java.lang.Boolean> toSet​(boolean[] array)
      Converts this array to a Set, with each unique element added to the set.
      static java.util.Set<java.lang.Byte> toSet​(byte[] array)
      Converts this array to a Set, with each unique element added to the set.
      static java.util.Set<java.lang.Character> toSet​(char[] array)
      Converts this array to a Set, with each unique element added to the set.
      static java.util.Set<java.lang.Double> toSet​(double[] array)
      Converts this array to a Set, with each unique element added to the set.
      static java.util.Set<java.lang.Float> toSet​(float[] array)
      Converts this array to a Set, with each unique element added to the set.
      static java.util.Set<java.lang.Integer> toSet​(int[] array)
      Converts this array to a Set, with each unique element added to the set.
      static java.util.Set<java.lang.Long> toSet​(long[] array)
      Converts this array to a Set, with each unique element added to the set.
      static java.util.Set<java.lang.Short> toSet​(short[] array)
      Converts this array to a Set, with each unique element added to the set.
      static java.util.Set<java.lang.CharSequence> toSet​(java.lang.CharSequence self)
      Converts the given CharSequence into a Set of unique CharSequence of one character.
      static java.util.Set<java.lang.String> toSet​(java.lang.String self)
      Converts the given String into a Set of unique strings of one character.
      static <T> java.util.Set<T> toSet​(java.util.Collection<T> self)
      Convert a Collection to a Set.
      static <T> java.util.Set<T> toSet​(java.util.Enumeration<T> self)
      Convert an enumeration to a Set.
      static <T> java.util.Set<T> toSet​(java.util.Iterator<T> self)
      Convert an iterator to a Set.
      static java.lang.Short toShort​(java.lang.CharSequence self)
      Parse a CharSequence into a Short
      static java.lang.Short toShort​(java.lang.String self)
      Parse a String into a Short
      static SpreadMap toSpreadMap​(java.lang.Object[] self)
      Creates a spreadable map from this array.
      static SpreadMap toSpreadMap​(java.util.List self)
      Creates a spreadable map from this list.
      static SpreadMap toSpreadMap​(java.util.Map self)
      Returns a new SpreadMap from this map.
      static java.lang.String toString​(boolean[] self)
      Returns the string representation of the given array.
      static java.lang.String toString​(byte[] self)
      Returns the string representation of the given array.
      static java.lang.String toString​(char[] self)
      Returns the string representation of the given array.
      static java.lang.String toString​(double[] self)
      Returns the string representation of the given array.
      static java.lang.String toString​(float[] self)
      Returns the string representation of the given array.
      static java.lang.String toString​(int[] self)
      Returns the string representation of the given array.
      static java.lang.String toString​(long[] self)
      Returns the string representation of the given array.
      static java.lang.String toString​(short[] self)
      Returns the string representation of the given array.
      static java.lang.String toString​(java.lang.Object value)
      Create a String representation of this object.
      static java.lang.String toString​(java.lang.Object[] self)
      Returns the string representation of this array's contents.
      static java.lang.String toString​(java.util.AbstractCollection self)
      Returns the string representation of the given collection.
      static java.lang.String toString​(java.util.AbstractMap self)
      Returns the string representation of the given map.
      static char toUpperCase​(java.lang.Character self)
      Converts the character to uppercase.
      static java.net.URI toURI​(java.lang.CharSequence self)
      Transforms a CharSequence representing a URI into a URI object.
      static java.net.URI toURI​(java.lang.String self)
      Transforms a String representing a URI into a URI object.
      static java.net.URL toURL​(java.lang.CharSequence self)
      Transforms a CharSequence representing a URL into a URL object.
      static java.net.URL toURL​(java.lang.String self)
      Transforms a String representing a URL into a URL object.
      static java.lang.CharSequence tr​(java.lang.CharSequence self, java.lang.CharSequence sourceSet, java.lang.CharSequence replacementSet)
      Translates a string by replacing characters from the sourceSet with characters from replacementSet.
      static java.lang.String tr​(java.lang.String self, java.lang.String sourceSet, java.lang.String replacementSet)
      Translates a string by replacing characters from the sourceSet with characters from replacementSet.
      static void transformChar​(java.io.Reader self, java.io.Writer writer, Closure closure)
      Transforms each character from this reader by passing it to the given closure.
      static void transformLine​(java.io.Reader reader, java.io.Writer writer, Closure closure)
      Transforms the lines from a reader with a Closure and write them to a writer.
      static java.util.List transpose​(java.util.List self)
      Adds GroovyCollections#transpose(List) as a method on lists.
      static void traverse​(java.io.File self, Closure closure)
      Invokes the closure for each descendant file in this directory tree.
      static void traverse​(java.io.File self, java.util.Map<java.lang.String,​java.lang.Object> options)
      Invokes the closure specified with key 'visit' in the options Map for each descendant file in this directory tree.
      static void traverse​(java.io.File self, java.util.Map<java.lang.String,​java.lang.Object> options, Closure closure)
      Invokes closure for each descendant file in this directory tree.
      static double trunc​(java.lang.Double number)
      Truncate the value
      static double trunc​(java.lang.Double number, int precision)
      Truncate the value
      static float trunc​(java.lang.Float number)
      Truncate the value
      static float trunc​(java.lang.Float number, int precision)
      Truncate the value
      static java.lang.Number unaryMinus​(java.lang.Number left)
      Negates the number.
      static java.lang.CharSequence unexpand​(java.lang.CharSequence self)
      Replaces sequences of whitespaces with tabs using tabStops of size 8.
      static java.lang.CharSequence unexpand​(java.lang.CharSequence self, int tabStop)
      Replaces sequences of whitespaces with tabs.
      static java.lang.String unexpand​(java.lang.String self)
      Replaces sequences of whitespaces with tabs using tabStops of size 8.
      static java.lang.String unexpand​(java.lang.String self, int tabStop)
      Replaces sequences of whitespaces with tabs.
      static java.lang.CharSequence unexpandLine​(java.lang.CharSequence self, int tabStop)
      Replaces sequences of whitespaces with tabs within a line.
      static java.lang.String unexpandLine​(java.lang.String self, int tabStop)
      Replaces sequences of whitespaces with tabs within a line.
      static <T> java.util.Collection<T> unique​(java.util.Collection<T> self)
      Modifies this collection to remove all duplicated items, using the default comparator.
      static <T> java.util.Collection<T> unique​(java.util.Collection<T> self, boolean mutate)
      Remove all duplicates from a given Collection using the default comparator.
      static <T> java.util.Collection<T> unique​(java.util.Collection<T> self, boolean mutate, Closure closure)
      A convenience method for making a collection unique using a Closure to determine duplicate (equal) items.
      static <T> java.util.Collection<T> unique​(java.util.Collection<T> self, boolean mutate, java.util.Comparator<T> comparator)
      Remove all duplicates from a given Collection.
      static <T> java.util.Collection<T> unique​(java.util.Collection<T> self, Closure closure)
      A convenience method for making a collection unique using a Closure to determine duplicate (equal) items.
      static <T> java.util.Collection<T> unique​(java.util.Collection<T> self, java.util.Comparator<T> comparator)
      Remove all duplicates from a given Collection.
      static <T> java.util.Iterator<T> unique​(java.util.Iterator<T> self)
      Returns an iterator equivalent to this iterator all duplicated items removed by using the default comparator.
      static <T> java.util.Iterator<T> unique​(java.util.Iterator<T> self, Closure closure)
      Returns an iterator equivalent to this iterator but with all duplicated items removed by using a Closure to determine duplicate (equal) items.
      static <T> java.util.Iterator<T> unique​(java.util.Iterator<T> self, java.util.Comparator<T> comparator)
      Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator.
      static void upto​(double self, java.lang.Number to, Closure closure)
      Iterates from this number up to the given number, inclusive, incrementing by one each time.
      static void upto​(float self, java.lang.Number to, Closure closure)
      Iterates from this number up to the given number, inclusive, incrementing by one each time.
      static void upto​(long self, java.lang.Number to, Closure closure)
      Iterates from this number up to the given number, inclusive, incrementing by one each time.
      static void upto​(java.lang.Double self, java.lang.Number to, Closure closure)
      Iterates from this number up to the given number, inclusive, incrementing by one each time.
      static void upto​(java.lang.Float self, java.lang.Number to, Closure closure)
      Iterates from this number up to the given number, inclusive, incrementing by one each time.
      static void upto​(java.lang.Long self, java.lang.Number to, Closure closure)
      Iterates from this number up to the given number, inclusive, incrementing by one each time.
      static void upto​(java.lang.Number self, java.lang.Number to, Closure closure)
      Iterates from this number up to the given number, inclusive, incrementing by one each time.
      static void upto​(java.math.BigDecimal self, java.lang.Number to, Closure closure)
      Iterates from this number up to the given number, inclusive, incrementing by one each time.
      static void upto​(java.math.BigInteger self, java.lang.Number to, Closure closure)
      Iterates from this number up to the given number, inclusive, incrementing by one each time.
      static <T> T use​(java.lang.Object self, java.lang.Class categoryClass, Closure<T> closure)
      Scoped use method
      static java.lang.Object use​(java.lang.Object self, java.lang.Object[] array)
      Allows you to use a list of categories, specifying the list as varargs.
      static <T> T use​(java.lang.Object self, java.util.List<java.lang.Class> categoryClassList, Closure<T> closure)
      Scoped use method with list of categories.
      static <T> T with​(java.lang.Object self, Closure<T> closure)
      Allows the closure to be called for the object reference self.
      static <T> T withDataInputStream​(java.io.File file, Closure<T> closure)
      Create a new DataInputStream for this file and passes it into the closure.
      static <T> T withDataOutputStream​(java.io.File file, Closure<T> closure)
      Create a new DataOutputStream for this file and passes it into the closure.
      static <T> java.util.List<T> withDefault​(java.util.List<T> self, Closure init)
      An alias for withLazyDefault which decorates a list allowing it to grow when called with index values outside the normal list bounds.
      static <K,​V>
      java.util.Map<K,​V>
      withDefault​(java.util.Map<K,​V> self, Closure init)
      Wraps a map using the decorator pattern with a wrapper that intercepts all calls to get(key).
      static <T> java.util.List<T> withEagerDefault​(java.util.List<T> self, Closure init)
      Decorates a list allowing it to grow when called with a non-existent index value.
      static java.lang.Object withInputStream​(java.io.File file, Closure closure)
      Create a new InputStream for this file and passes it into the closure.
      static <T> T withInputStream​(java.net.URL url, Closure<T> closure)
      Creates a new InputStream for this URL and passes it into the closure.
      static <T> java.util.List<T> withLazyDefault​(java.util.List<T> self, Closure init)
      Decorates a list allowing it to grow when called with a non-existent index value.
      static <T> T withObjectInputStream​(java.io.File file, Closure<T> closure)
      Create a new ObjectInputStream for this file and pass it to the closure.
      static <T> T withObjectInputStream​(java.io.File file, java.lang.ClassLoader classLoader, Closure<T> closure)
      Create a new ObjectInputStream for this file associated with the given class loader and pass it to the closure.
      static <T> T withObjectInputStream​(java.io.InputStream inputStream, Closure<T> closure)
      Create a new ObjectInputStream for this file and pass it to the closure.
      static <T> T withObjectInputStream​(java.io.InputStream inputStream, java.lang.ClassLoader classLoader, Closure<T> closure)
      Create a new ObjectInputStream for this file and pass it to the closure.
      static <T> T withObjectOutputStream​(java.io.File file, Closure<T> closure)
      Create a new ObjectOutputStream for this file and then pass it to the closure.
      static <T> T withObjectOutputStream​(java.io.OutputStream outputStream, Closure<T> closure)
      Create a new ObjectOutputStream for this output stream and then pass it to the closure.
      static <T> T withObjectStreams​(java.net.Socket socket, Closure<T> closure)
      Creates an InputObjectStream and an OutputObjectStream from a Socket, and passes them to the closure.
      static java.lang.Object withOutputStream​(java.io.File file, Closure closure)
      Creates a new OutputStream for this file and passes it into the closure.
      static <T> T withPrintWriter​(java.io.File file, Closure<T> closure)
      Create a new PrintWriter for this file which is then passed it into the given closure.
      static <T> T withPrintWriter​(java.io.File file, java.lang.String charset, Closure<T> closure)
      Create a new PrintWriter with a specified charset for this file.
      static <T> T withPrintWriter​(java.io.Writer writer, Closure<T> closure)
      Create a new PrintWriter with a specified charset for this file.
      static <T> T withReader​(java.io.File file, Closure<T> closure)
      Create a new BufferedReader for this file and then passes it into the closure, ensuring the reader is closed after the closure returns.
      static <T> T withReader​(java.io.File file, java.lang.String charset, Closure<T> closure)
      Create a new BufferedReader for this file using the specified charset and then passes it into the closure, ensuring the reader is closed after the closure returns.
      static <T> T withReader​(java.io.InputStream in, Closure<T> closure)
      Helper method to create a new Reader for a stream and then passes it into the closure.
      static <T> T withReader​(java.io.InputStream in, java.lang.String charset, Closure<T> closure)
      Helper method to create a new Reader for a stream and then passes it into the closure.
      static <T> T withReader​(java.io.Reader reader, Closure<T> closure)
      Allows this reader to be used within the closure, ensuring that it is closed before this method returns.
      static <T> T withReader​(java.net.URL url, Closure<T> closure)
      Helper method to create a new BufferedReader for a URL and then passes it to the closure.
      static <T> T withReader​(java.net.URL url, java.lang.String charset, Closure<T> closure)
      Helper method to create a new Reader for a URL and then passes it to the closure.
      static <T> T withStream​(java.io.InputStream stream, Closure<T> closure)
      Allows this input stream to be used within the closure, ensuring that it is flushed and closed before this method returns.
      static <T> T withStream​(java.io.OutputStream os, Closure<T> closure)
      Passes this OutputStream to the closure, ensuring that the stream is closed after the closure returns, regardless of errors.
      static <T> T withStreams​(java.net.Socket socket, Closure<T> closure)
      Passes the Socket's InputStream and OutputStream to the closure.
      static <T> T withWriter​(java.io.File file, Closure<T> closure)
      Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns.
      static <T> T withWriter​(java.io.File file, java.lang.String charset, Closure<T> closure)
      Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns.
      static <T> T withWriter​(java.io.OutputStream stream, Closure<T> closure)
      Creates a writer from this stream, passing it to the given closure.
      static <T> T withWriter​(java.io.OutputStream stream, java.lang.String charset, Closure<T> closure)
      Creates a writer from this stream, passing it to the given closure.
      static <T> T withWriter​(java.io.Writer writer, Closure<T> closure)
      Allows this writer to be used within the closure, ensuring that it is flushed and closed before this method returns.
      static <T> T withWriterAppend​(java.io.File file, Closure<T> closure)
      Create a new BufferedWriter for this file in append mode.
      static <T> T withWriterAppend​(java.io.File file, java.lang.String charset, Closure<T> closure)
      Create a new BufferedWriter which will append to this file.
      static void write​(java.io.File file, java.lang.String text)
      Write the text to the File.
      static void write​(java.io.File file, java.lang.String text, java.lang.String charset)
      Write the text to the File, using the specified encoding.
      static void write​(java.io.Writer self, Writable writable)
      A helper method so that dynamic dispatch of the writer.write(object) method will always use the more efficient Writable.writeTo(writer) mechanism if the object implements the Writable interface.
      static void writeLine​(java.io.BufferedWriter writer, java.lang.String line)
      Write the text and append a newline (using the platform's line-ending).
      static java.lang.Boolean xor​(java.lang.Boolean left, java.lang.Boolean right)
      Exclusive disjunction of two boolean operators
      static java.lang.Number xor​(java.lang.Number left, java.lang.Number right)
      Bitwise XOR together two Numbers.
      static java.util.BitSet xor​(java.util.BitSet left, java.util.BitSet right)
      Bitwise XOR together two BitSets.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • additionals

        public static final java.lang.Class[] additionals
    • Constructor Detail

      • DefaultGroovyMethods

        public DefaultGroovyMethods()
    • Method Detail

      • is

        public static boolean is​(java.lang.Object self,
                                 java.lang.Object other)
        Identity check. Since == is overridden in Groovy with the meaning of equality we need some fallback to check for object identity. Invoke using the 'is' method, like so: def same = this.is(that)
        Parameters:
        self - an object
        other - an object to compare identity with
        Returns:
        true if self and other are both references to the same instance, false otherwise
        Since:
        1.0
      • identity

        public static <T> T identity​(java.lang.Object self,
                                     Closure<T> closure)
        Allows the closure to be called for the object reference self. Synonym for 'with()'.
        Parameters:
        self - the object to have a closure act upon
        closure - the closure to call on the object
        Returns:
        result of calling the closure
        Since:
        1.0
      • with

        public static <T> T with​(java.lang.Object self,
                                 Closure<T> closure)
        Allows the closure to be called for the object reference self.

        Any method invoked inside the closure will first be invoked on the self reference. For instance, the following method calls to the append() method are invoked on the StringBuilder instance:
         def b = new StringBuilder().with {
           append('foo')
           append('bar')
           return it
         }
         assert b.toString() == 'foobar'
         
        This is commonly used to simplify object creation, such as this example:
         def p = new Person().with {
           firstName = 'John'
           lastName = 'Doe'
           return it
         }
         
        Parameters:
        self - the object to have a closure act upon
        closure - the closure to call on the object
        Returns:
        result of calling the closure
        Since:
        1.5.0
      • getAt

        public static java.lang.Object getAt​(java.lang.Object self,
                                             java.lang.String property)
        Allows the subscript operator to be used to lookup dynamic property values. bean[somePropertyNameExpression]. The normal property notation of groovy is neater and more concise but only works with compile-time known property names.
        Parameters:
        self - the object to act upon
        property - the property name of interest
        Returns:
        the property value
        Since:
        1.0
      • putAt

        public static void putAt​(java.lang.Object self,
                                 java.lang.String property,
                                 java.lang.Object newValue)
        Allows the subscript operator to be used to set dynamically named property values. bean[somePropertyNameExpression] = foo. The normal property notation of groovy is neater and more concise but only works with property names which are known at compile time.
        Parameters:
        self - the object to act upon
        property - the name of the property to set
        newValue - the value to set
        Since:
        1.0
      • dump

        public static java.lang.String dump​(java.lang.Object self)
        Generates a detailed dump string of an object showing its class, hashCode and fields.
        Parameters:
        self - an object
        Returns:
        the dump representation
        Since:
        1.0
      • getMetaPropertyValues

        public static java.util.List<PropertyValue> getMetaPropertyValues​(java.lang.Object self)
        Retrieves the list of MetaProperty objects for 'self' and wraps it in a list of PropertyValue objects that additionally provide the value for each property of 'self'.
        Parameters:
        self - the receiver object
        Returns:
        list of PropertyValue objects
        Since:
        1.0
        See Also:
        Expando.getMetaPropertyValues()
      • getProperties

        public static java.util.Map getProperties​(java.lang.Object self)
        Convenience method that calls getMetaPropertyValues(java.lang.Object)(self) and provides the data in form of simple key/value pairs, i.e.&nsbp;without type() information.
        Parameters:
        self - the receiver object
        Returns:
        meta properties as Map of key/value pairs
        Since:
        1.0
      • use

        public static <T> T use​(java.lang.Object self,
                                java.lang.Class categoryClass,
                                Closure<T> closure)
        Scoped use method
        Parameters:
        self - any Object
        categoryClass - a category class to use
        closure - the closure to invoke with the category in place
        Returns:
        the value returned from the closure
        Since:
        1.0
      • mixin

        public static void mixin​(MetaClass self,
                                 java.util.List<java.lang.Class> categoryClasses)
        Extend object with category methods. All methods for given class and all super classes will be added to the object.
        Parameters:
        self - any Class
        categoryClasses - a category classes to use
        Since:
        1.6.0
      • mixin

        public static void mixin​(java.lang.Class self,
                                 java.util.List<java.lang.Class> categoryClasses)
        Extend class globally with category methods. All methods for given class and all super classes will be added to the class.
        Parameters:
        self - any Class
        categoryClasses - a category classes to use
        Since:
        1.6.0
      • mixin

        public static void mixin​(java.lang.Class self,
                                 java.lang.Class categoryClass)
        Extend class globally with category methods.
        Parameters:
        self - any Class
        categoryClass - a category class to use
        Since:
        1.6.0
      • mixin

        public static void mixin​(java.lang.Class self,
                                 java.lang.Class[] categoryClass)
        Extend class globally with category methods.
        Parameters:
        self - any Class
        categoryClass - a category class to use
        Since:
        1.6.0
      • mixin

        public static void mixin​(MetaClass self,
                                 java.lang.Class categoryClass)
        Extend class globally with category methods.
        Parameters:
        self - any Class
        categoryClass - a category class to use
        Since:
        1.6.0
      • mixin

        public static void mixin​(MetaClass self,
                                 java.lang.Class[] categoryClass)
        Extend class globally with category methods.
        Parameters:
        self - any Class
        categoryClass - a category class to use
        Since:
        1.6.0
      • use

        public static <T> T use​(java.lang.Object self,
                                java.util.List<java.lang.Class> categoryClassList,
                                Closure<T> closure)
        Scoped use method with list of categories.
        Parameters:
        self - any Object
        categoryClassList - a list of category classes
        closure - the closure to invoke with the categories in place
        Returns:
        the value returned from the closure
        Since:
        1.0
      • addShutdownHook

        public static void addShutdownHook​(java.lang.Object self,
                                           Closure closure)
        Allows the usage of addShutdownHook without getting the runtime first.
        Parameters:
        self - the object the method is called on (ignored)
        closure - the shutdown hook action
        Since:
        1.5.0
      • use

        public static java.lang.Object use​(java.lang.Object self,
                                           java.lang.Object[] array)
        Allows you to use a list of categories, specifying the list as varargs. use(CategoryClass1, CategoryClass2) { ... } This method saves having to wrap the the category classes in a list.
        Parameters:
        self - any Object
        array - a list of category classes and a Closure
        Returns:
        the value returned from the closure
        Since:
        1.0
      • print

        public static void print​(java.lang.Object self,
                                 java.lang.Object value)
        Print a value formatted Groovy style to self if it is a Writer, otherwise to the standard output stream.
        Parameters:
        self - any Object
        value - the value to print
        Since:
        1.0
      • print

        public static void print​(java.io.PrintWriter self,
                                 java.lang.Object value)
        Print a value formatted Groovy style to the print writer.
        Parameters:
        self - a PrintWriter
        value - the value to print
        Since:
        1.0
      • print

        public static void print​(java.io.PrintStream self,
                                 java.lang.Object value)
        Print a value formatted Groovy style to the print stream.
        Parameters:
        self - a PrintStream
        value - the value to print
        Since:
        1.6.0
      • print

        public static void print​(Closure self,
                                 java.lang.Object value)
        Print a value to the standard output stream. This method delegates to the owner to execute the method.
        Parameters:
        self - a generated closure
        value - the value to print
        Since:
        1.0
      • println

        public static void println​(java.lang.Object self)
        Print a linebreak to the standard output stream.
        Parameters:
        self - any Object
        Since:
        1.0
      • println

        public static void println​(Closure self)
        Print a linebreak to the standard output stream. This method delegates to the owner to execute the method.
        Parameters:
        self - a closure
        Since:
        1.0
      • println

        public static void println​(java.lang.Object self,
                                   java.lang.Object value)
        Print a value formatted Groovy style (followed by a newline) to self if it is a Writer, otherwise to the standard output stream.
        Parameters:
        self - any Object
        value - the value to print
        Since:
        1.0
      • println

        public static void println​(java.io.PrintWriter self,
                                   java.lang.Object value)
        Print a value formatted Groovy style (followed by a newline) to the print writer.
        Parameters:
        self - a PrintWriter
        value - the value to print
        Since:
        1.0
      • println

        public static void println​(java.io.PrintStream self,
                                   java.lang.Object value)
        Print a value formatted Groovy style (followed by a newline) to the print stream.
        Parameters:
        self - any Object
        value - the value to print
        Since:
        1.6.0
      • println

        public static void println​(Closure self,
                                   java.lang.Object value)
        Print a value (followed by a newline) to the standard output stream. This method delegates to the owner to execute the method.
        Parameters:
        self - a closure
        value - the value to print
        Since:
        1.0
      • printf

        public static void printf​(java.lang.Object self,
                                  java.lang.String format,
                                  java.lang.Object[] values)
        Printf to a console (Only works with JDK1.5 or later).
        Parameters:
        self - any Object
        format - a format string
        values - values referenced by the format specifiers in the format string.
        Since:
        1.0
      • sprintf

        public static java.lang.String sprintf​(java.lang.Object self,
                                               java.lang.String format,
                                               java.lang.Object[] values)
        Sprintf to a string (Only works with JDK1.5 or later).
        Parameters:
        self - any Object
        format - a format string
        values - values referenced by the format specifiers in the format string.
        Returns:
        the resulting formatted string
        Since:
        1.5.0
      • printf

        public static void printf​(java.lang.Object self,
                                  java.lang.String format,
                                  java.lang.Object arg)
        Prints a formatted string using the specified format string and arguments.

        For examples,

             printf ( "Hello, %s!\n" , [ "world" ] as String[] )
             printf ( "Hello, %s!\n" , [ "Groovy" ])
             printf ( "%d + %d = %d\n" , [ 1 , 2 , 1+2 ] as Integer[] )
             printf ( "%d + %d = %d\n" , [ 3 , 3 , 3+3 ])
         

        ( 1..5 ).each { printf ( "-- %d\n" , [ it ] as Integer[] ) } ( 1..5 ).each { printf ( "-- %d\n" , [ it ] as int[] ) } ( 0x41..0x45 ).each { printf ( "-- %c\n" , [ it ] as char[] ) } ( 07..011 ).each { printf ( "-- %d\n" , [ it ] as byte[] ) } ( 7..11 ).each { printf ( "-- %d\n" , [ it ] as short[] ) } ( 7..11 ).each { printf ( "-- %d\n" , [ it ] as long[] ) } ( 7..11 ).each { printf ( "-- %5.2f\n" , [ it ] as float[] ) } ( 7..11 ).each { printf ( "-- %5.2g\n" , [ it ] as double[] ) }

        Parameters:
        self - any Object
        format - A format string
        arg - Argument which is referenced by the format specifiers in the format string. The type of arg should be one of Object[], List, int[], short[], byte[], char[], boolean[], long[], float[], or double[].
        Since:
        1.0
      • sprintf

        public static java.lang.String sprintf​(java.lang.Object self,
                                               java.lang.String format,
                                               java.lang.Object arg)
        Returns a formatted string using the specified format string and arguments.

        Parameters:
        self - any Object
        format - A format string
        arg - Argument which is referenced by the format specifiers in the format string. The type of arg should be one of Object[], List, int[], short[], byte[], char[], boolean[], long[], float[], or double[].
        Returns:
        the resulting printf'd string
        Since:
        1.5.0
      • inspect

        public static java.lang.String inspect​(java.lang.Object self)
        Inspects returns the String that matches what would be typed into a terminal to create this object.
        Parameters:
        self - any Object
        Returns:
        a String that matches what would be typed into a terminal to create this object. e.g. [1, 'hello'].inspect() -> [1, "hello"]
        Since:
        1.0
      • print

        public static void print​(java.lang.Object self,
                                 java.io.PrintWriter out)
        Print to a console in interactive format.
        Parameters:
        self - any Object
        out - the PrintWriter used for printing
        Since:
        1.0
      • println

        public static void println​(java.lang.Object self,
                                   java.io.PrintWriter out)
        Print to a console in interactive format.
        Parameters:
        self - any Object
        out - the PrintWriter used for printing
        Since:
        1.0
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.Object object,
                                                    java.lang.String method,
                                                    java.lang.Object arguments)
        Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily.
        Parameters:
        object - any Object
        method - the name of the method to call
        arguments - the arguments to use
        Returns:
        the result of the method call
        Since:
        1.0
      • isCase

        public static boolean isCase​(java.lang.Object caseValue,
                                     java.lang.Object 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:
         switch( a ) {
           case b: //some code
         }
        "some code" is called when b.isCase( a ) returns true.
        Parameters:
        caseValue - the case value
        switchValue - the switch value
        Returns:
        true if the switchValue is deemed to be equal to the caseValue
        Since:
        1.0
      • isCase

        public static boolean isCase​(java.lang.String caseValue,
                                     java.lang.Object switchValue)
        'Case' implementation for a String, which uses String#equals(Object) in order to allow Strings to be used in switch statements. For example:
        switch( str ) {
           case 'one' :
           // etc...
         }
        Note that this returns true for the case where both the 'switch' and 'case' operand is null.
        Parameters:
        caseValue - the case value
        switchValue - the switch value
        Returns:
        true if the switchValue's toString() equals the caseValue
        Since:
        1.0
      • isCase

        public static boolean isCase​(java.lang.CharSequence caseValue,
                                     java.lang.Object switchValue)
        'Case' implementation for a CharSequence, which simply calls the equivalent method for String.
        Parameters:
        caseValue - the case value
        switchValue - the switch value
        Returns:
        true if the switchValue's toString() equals the caseValue
        Since:
        1.8.2
      • isCase

        public static boolean isCase​(GString caseValue,
                                     java.lang.Object switchValue)
        'Case' implementation for a GString, which simply calls the equivalent method for String.
        Parameters:
        caseValue - the case value
        switchValue - the switch value
        Returns:
        true if the switchValue's toString() equals the caseValue
        Since:
        1.6.0
      • isCase

        public static boolean isCase​(java.lang.Class caseValue,
                                     java.lang.Object switchValue)
        Special 'Case' implementation for Class, which allows testing for a certain class in a switch statement. For example:
        switch( obj ) {
           case List :
             // obj is a list
             break;
           case Set :
             // etc
         }
        Parameters:
        caseValue - the case value
        switchValue - the switch value
        Returns:
        true if the switchValue is deemed to be assignable from the given class
        Since:
        1.0
      • isCase

        public static boolean isCase​(java.util.Collection caseValue,
                                     java.lang.Object switchValue)
        'Case' implementation for collections which tests if the 'switch' operand is contained in any of the 'case' values. For example:
        switch( 3 ) {
           case [1,3,5]:
             assert true
             break
           default:
             assert false
         }
        Parameters:
        caseValue - the case value
        switchValue - the switch value
        Returns:
        true if the caseValue is deemed to contain the switchValue
        Since:
        1.0
        See Also:
        Collection.contains(java.lang.Object)
      • isCase

        public static boolean isCase​(java.util.Map caseValue,
                                     java.lang.Object switchValue)
        'Case' implementation for maps which tests the groovy truth value obtained using the 'switch' operand as key. For example:
        switch( 'foo' ) {
           case [foo:true, bar:false]:
             assert true
             break
           default:
             assert false
         }
        Parameters:
        caseValue - the case value
        switchValue - the switch value
        Returns:
        the groovy truth value from caseValue corresponding to the switchValue key
        Since:
        1.7.6
      • isCase

        public static boolean isCase​(java.util.regex.Pattern caseValue,
                                     java.lang.Object switchValue)
        'Case' implementation for the Pattern class, which allows testing a String against a number of regular expressions. For example:
        switch( str ) {
           case ~/one/ :
             // the regex 'one' matches the value of str
         }
         
        Note that this returns true for the case where both the pattern and the 'switch' values are null.
        Parameters:
        caseValue - the case value
        switchValue - the switch value
        Returns:
        true if the switchValue is deemed to match the caseValue
        Since:
        1.0
      • isCase

        public static boolean isCase​(java.lang.Number caseValue,
                                     java.lang.Number switchValue)
        Special 'case' implementation for all numbers, which delegates to the compareTo() method for comparing numbers of different types.
        Parameters:
        caseValue - the case value
        switchValue - the switch value
        Returns:
        true if the numbers are deemed equal
        Since:
        1.5.0
      • unique

        public static <T> java.util.Iterator<T> unique​(java.util.Iterator<T> self)
        Returns an iterator equivalent to this iterator all duplicated items removed by using the default comparator. The original iterator will become exhausted of elements after determining the unique values. A new iterator for the unique values will be returned.
        Parameters:
        self - an Iterator
        Returns:
        the modified Iterator
        Since:
        1.5.5
      • unique

        public static <T> java.util.Collection<T> unique​(java.util.Collection<T> self)
        Modifies this collection to remove all duplicated items, using the default comparator.
        assert [1,3] == [1,3,3].unique()
        Parameters:
        self - a collection
        Returns:
        the now modified collection
        Since:
        1.0
        See Also:
        unique(Collection, boolean)
      • unique

        public static <T> java.util.Collection<T> unique​(java.util.Collection<T> self,
                                                         boolean mutate)
        Remove all duplicates from a given Collection using the default comparator. If mutate is true, it works by modifying the original object (and also returning it). If mutate is false, a new collection is returned leaving the original unchanged.
         assert [1,3] == [1,3,3].unique()
         
         def orig = [1, 3, 2, 3]
         def uniq = orig.unique(false)
         assert orig == [1, 3, 2, 3]
         assert uniq == [1, 3, 2]
         
        Parameters:
        self - a collection
        mutate - false will cause a new list containing unique items from the collection to be created, true will mutate collections in place
        Returns:
        the now modified collection
        Since:
        1.8.1
      • numberAwareCompareTo

        public static int numberAwareCompareTo​(java.lang.Comparable self,
                                               java.lang.Comparable other)
        Provides a method that compares two comparables using Groovy's default number aware comparator.
        Parameters:
        self - a Comparable
        other - another Comparable
        Returns:
        a -ve number, 0 or a +ve number according to Groovy's compareTo contract
        Since:
        1.6.0
      • unique

        public static <T> java.util.Iterator<T> unique​(java.util.Iterator<T> self,
                                                       Closure closure)
        Returns an iterator equivalent to this iterator but with all duplicated items removed by using a Closure to determine duplicate (equal) items. The original iterator will be fully processed after the call.

        If the closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using Comparable.compareTo(java.lang.Object) or Object.equals(java.lang.Object)). If the closure takes two parameters, two items from the Iterator will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).
        Parameters:
        self - an Iterator
        closure - a Closure used to determine unique items
        Returns:
        the modified Iterator
        Since:
        1.5.5
      • unique

        public static <T> java.util.Collection<T> unique​(java.util.Collection<T> self,
                                                         Closure closure)
        A convenience method for making a collection unique using a Closure to determine duplicate (equal) items.

        If the closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using Comparable.compareTo(java.lang.Object) or Object.equals(java.lang.Object)). If the closure takes two parameters, two items from the collection will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).
        assert [1,4] == [1,3,4,5].unique { it % 2 }
        assert [2,3,4] == [2,3,3,4].unique { a, b -> a <=> b }
        Parameters:
        self - a Collection
        closure - a 1 or 2 arg Closure used to determine unique items
        Returns:
        self without any duplicates
        Since:
        1.0
        See Also:
        unique(Collection, boolean, Closure)
      • unique

        public static <T> java.util.Collection<T> unique​(java.util.Collection<T> self,
                                                         boolean mutate,
                                                         Closure closure)
        A convenience method for making a collection unique using a Closure to determine duplicate (equal) items. If mutate is true, it works on the receiver object and returns it. If mutate is false, a new collection is returned.

        If the closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using Comparable.compareTo(java.lang.Object) or Object.equals(java.lang.Object)). If the closure takes two parameters, two items from the collection will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).
         def orig = [1, 3, 4, 5]
         def uniq = orig.unique(false) { it % 2 }
         assert orig == [1, 3, 4, 5]
         assert uniq == [1, 4]
         
         def orig = [2, 3, 3, 4]
         def uniq = orig.unique(false) { a, b -> a <=> b }
         assert orig == [2, 3, 3, 4]
         assert uniq == [2, 3, 4]
         
        Parameters:
        self - a Collection
        mutate - false will always cause a new list to be created, true will mutate lists in place
        closure - a 1 or 2 arg Closure used to determine unique items
        Returns:
        self without any duplicates
        Since:
        1.8.1
      • unique

        public static <T> java.util.Iterator<T> unique​(java.util.Iterator<T> self,
                                                       java.util.Comparator<T> comparator)
        Returns an iterator equivalent to this iterator with all duplicated items removed by using the supplied comparator.
        Parameters:
        self - an Iterator
        comparator - a Comparator
        Returns:
        the modified Iterator
        Since:
        1.5.5
      • unique

        public static <T> java.util.Collection<T> unique​(java.util.Collection<T> self,
                                                         java.util.Comparator<T> comparator)
        Remove all duplicates from a given Collection. Works on the original object (and also returns it). The order of members in the Collection are compared by the given Comparator. For each duplicate, the first member which is returned by the given Collection's iterator is retained, but all other ones are removed. The given Collection's original order is preserved.

             class Person {
                 def fname, lname
                 String toString() {
                     return fname + " " + lname
                 }
             }
        
             class PersonComparator implements Comparator {
                 int compare(Object o1, Object o2) {
                     Person p1 = (Person) o1
                     Person p2 = (Person) o2
                     if (p1.lname != p2.lname)
                         return p1.lname.compareTo(p2.lname)
                     else
                         return p1.fname.compareTo(p2.fname)
                 }
        
                 boolean equals(Object obj) {
                     return this.equals(obj)
                 }
             }
        
             Person a = new Person(fname:"John", lname:"Taylor")
             Person b = new Person(fname:"Clark", lname:"Taylor")
             Person c = new Person(fname:"Tom", lname:"Cruz")
             Person d = new Person(fname:"Clark", lname:"Taylor")
        
             def list = [a, b, c, d]
             List list2 = list.unique(new PersonComparator())
             assert( list2 == list && list == [a, b, c] )
         
        Parameters:
        self - a Collection
        comparator - a Comparator
        Returns:
        self the now modified collection without duplicates
        Since:
        1.0
        See Also:
        unique(java.util.Collection, boolean, java.util.Comparator)
      • unique

        public static <T> java.util.Collection<T> unique​(java.util.Collection<T> self,
                                                         boolean mutate,
                                                         java.util.Comparator<T> comparator)
        Remove all duplicates from a given Collection. If mutate is true, it works on the original object (and also returns it). If mutate is false, a new collection is returned. The order of members in the Collection are compared by the given Comparator. For each duplicate, the first member which is returned by the given Collection's iterator is retained, but all other ones are removed. The given Collection's original order is preserved.

             class Person {
                 def fname, lname
                 String toString() {
                     return fname + " " + lname
                 }
             }
        
             class PersonComparator implements Comparator {
                 int compare(Object o1, Object o2) {
                     Person p1 = (Person) o1
                     Person p2 = (Person) o2
                     if (p1.lname != p2.lname)
                         return p1.lname.compareTo(p2.lname)
                     else
                         return p1.fname.compareTo(p2.fname)
                 }
        
                 boolean equals(Object obj) {
                     return this.equals(obj)
                 }
             }
        
             Person a = new Person(fname:"John", lname:"Taylor")
             Person b = new Person(fname:"Clark", lname:"Taylor")
             Person c = new Person(fname:"Tom", lname:"Cruz")
             Person d = new Person(fname:"Clark", lname:"Taylor")
        
             def list = [a, b, c, d]
             List list2 = list.unique(false, new PersonComparator())
             assert( list2 != list && list2 == [a, b, c] )
         
        Parameters:
        self - a Collection
        mutate - false will always cause a new collection to be created, true will mutate collections in place
        comparator - a Comparator
        Returns:
        self the collection without duplicates
        Since:
        1.8.1
      • each

        public static <T> T each​(T self,
                                 Closure closure)
        Iterates through an aggregate type or data structure, passing each item to the given closure. Custom types may utilize this method by simply providing an "iterator()" method. The items returned from the resulting iterator will be passed to the closure.
        Parameters:
        self - the object over which we iterate
        closure - the closure applied on each element found
        Returns:
        the self Object
        Since:
        1.0
      • eachWithIndex

        public static <T> T eachWithIndex​(T self,
                                          Closure closure)
        Iterates through an aggregate type or data structure, passing each item and the item's index (a counter starting at zero) to the given closure.
        Parameters:
        self - an Object
        closure - a Closure to operate on each item
        Returns:
        the self Object
        Since:
        1.0
      • each

        public static <K,​V> java.util.Map<K,​V> each​(java.util.Map<K,​V> self,
                                                                Closure closure)
        Allows a Map to be iterated through using a closure. If the closure takes one parameter then it will be passed the Map.Entry otherwise if the closure takes two parameters then it will be passed the key and the value.
        def result = ""
         [a:1, b:3].each { key, value -> result += "$key$value" }
         assert result == "a1b3"
        def result = ""
         [a:1, b:3].each { entry -> result += entry }
         assert result == "a=1b=3"
        In general, the order in which the map contents are processed cannot be guaranteed. In practise, specialized forms of Map, e.g. a TreeMap will have its contents processed according to the natural ordering of the map.
        Parameters:
        self - the map over which we iterate
        closure - the 1 or 2 arg closure applied on each entry of the map
        Returns:
        returns the self parameter
        Since:
        1.5.0
      • reverseEach

        public static <K,​V> java.util.Map<K,​V> reverseEach​(java.util.Map<K,​V> self,
                                                                       Closure closure)
        Allows a Map to be iterated through in reverse order using a closure. In general, the order in which the map contents are processed cannot be guaranteed. In practise, specialized forms of Map, e.g. a TreeMap will have its contents processed according to the reverse of the natural ordering of the map.
        Parameters:
        self - the map over which we iterate
        closure - the 1 or 2 arg closure applied on each entry of the map
        Returns:
        returns the self parameter
        Since:
        1.7.2
        See Also:
        each(Map, Closure)
      • eachWithIndex

        public static <K,​V> java.util.Map<K,​V> eachWithIndex​(java.util.Map<K,​V> self,
                                                                         Closure closure)
        Allows a Map to be iterated through using a closure. If the closure takes two parameters then it will be passed the Map.Entry and the item's index (a counter starting at zero) otherwise if the closure takes three parameters then it will be passed the key, the value, and the index.
        def result = ""
         [a:1, b:3].eachWithIndex { key, value, index -> result += "$index($key$value)" }
         assert result == "0(a1)1(b3)"
        def result = ""
         [a:1, b:3].eachWithIndex { entry, index -> result += "$index($entry)" }
         assert result == "0(a=1)1(b=3)"
        Parameters:
        self - the map over which we iterate
        closure - a 2 or 3 arg Closure to operate on each item
        Returns:
        the self Object
        Since:
        1.5.0
      • reverseEach

        public static <T> java.util.List<T> reverseEach​(java.util.List<T> self,
                                                        Closure closure)
        Iterate over each element of the list in the reverse order.
        def result = []
         [1,2,3].reverseEach { result << it }
         assert result == [3,2,1]
        Parameters:
        self - a List
        closure - a closure to which each item is passed.
        Returns:
        the original list
        Since:
        1.5.0
      • reverseEach

        public static <T> T[] reverseEach​(T[] self,
                                          Closure closure)
        Iterate over each element of the array in the reverse order.
        Parameters:
        self - an Object array
        closure - a closure to which each item is passed
        Returns:
        the original array
        Since:
        1.5.2
      • every

        public static boolean every​(java.lang.Object self,
                                    Closure closure)
        Used to determine if the given predicate closure is valid (i.e.&nsbp;returns true for all items in this data structure). A simple example for a list:
        def list = [3,4,5]
         def greaterThanTwo = list.every { it > 2 }
         
        Parameters:
        self - the object over which we iterate
        closure - the closure predicate used for matching
        Returns:
        true if every iteration of the object matches the closure predicate
        Since:
        1.0
      • every

        public static <K,​V> boolean every​(java.util.Map<K,​V> self,
                                                Closure closure)
        Iterates over the entries of a map, and checks whether a predicate is valid for all entries. If the closure takes one parameter then it will be passed the Map.Entry otherwise if the closure takes two parameters then it will be passed the key and the value.
        def map = [a:1, b:2.0, c:2L]
         assert !map.every { key, value -> value instanceof Integer }
         assert map.every { entry -> entry.value instanceof Number }
        Parameters:
        self - the map over which we iterate
        closure - the 1 or 2 arg Closure predicate used for matching
        Returns:
        true if every entry of the map matches the closure predicate
        Since:
        1.5.0
      • every

        public static boolean every​(java.lang.Object self)
        Iterates over every element of a collection, and checks whether all elements are true according to the Groovy Truth. Equivalent to self.every({element -> element})
        Parameters:
        self - the object over which we iterate
        Returns:
        true if every item in the collection matches the closure predicate
        Since:
        1.5.0
      • any

        public static boolean any​(java.lang.Object self,
                                  Closure closure)
        Iterates over the contents of an object or collection, and checks whether a predicate is valid for at least one element.
        Parameters:
        self - the object over which we iterate
        closure - the closure predicate used for matching
        Returns:
        true if any iteration for the object matches the closure predicate
        Since:
        1.0
      • any

        public static <K,​V> boolean any​(java.util.Map<K,​V> self,
                                              Closure<?> closure)
        Iterates over the entries of a map, and checks whether a predicate is valid for at least one entry. If the closure takes one parameter then it will be passed the Map.Entry otherwise if the closure takes two parameters then it will be passed the key and the value.
         assert [2:3, 4:5, 5:10].any { key, value -> key * 2 == value }
         assert ![2:3, 4:5, 5:10].any { entry -> entry.key == entry.value * 2 }
         
        Parameters:
        self - the map over which we iterate
        closure - the 1 or 2 arg closure predicate used for matching
        Returns:
        true if any entry in the map matches the closure predicate
        Since:
        1.5.0
      • any

        public static boolean any​(java.lang.Object self)
        Iterates over the elements of a collection, and checks whether at least one element is true according to the Groovy Truth. Equivalent to self.any({element -> element})
        Parameters:
        self - the object over which we iterate
        Returns:
        true if any item in the collection matches the closure predicate
        Since:
        1.5.0
      • grep

        public static java.util.Collection grep​(java.lang.Object self,
                                                java.lang.Object filter)
        Iterates over the collection of items which this Object represents and returns each item that matches the given filter - calling the isCase(java.lang.Object, java.lang.Object) method used by switch statements. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Example:
         def list = ['a', 'b', 'aa', 'bc', 3, 4.5]
         assert list.grep( ~/a+/ )  == ['a', 'aa']
         assert list.grep( ~/../ )  == ['aa', 'bc']
         assert list.grep( Number ) == [ 3, 4.5 ]
         assert list.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]
         
        Parameters:
        self - the object over which we iterate
        filter - the filter to perform on the object (using the isCase(java.lang.Object, java.lang.Object) method)
        Returns:
        a collection of objects which match the filter
        Since:
        1.5.6
      • grep

        public static java.util.Collection grep​(java.lang.Object self)
        Iterates over the collection of items which this Object represents and returns each item that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.

        Example:

         def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null]
         assert items.grep() == [1, 2, true, 'foo', [4, 5]]
         
        Parameters:
        self - the object over which we iterate
        Returns:
        a collection of objects which match the filter
        Since:
        1.8.1
        See Also:
        Closure.IDENTITY
      • count

        public static java.lang.Number count​(java.util.Iterator self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value from the items within this Iterator. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ). The iterator will become exhausted of elements after determining the count value.
        Parameters:
        self - the Iterator from which we count the number of matching occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.5.0
      • count

        public static java.lang.Number count​(java.util.Iterator self,
                                             Closure closure)
        Counts the number of occurrences which satisfy the given closure from the items within this Iterator. The iterator will become exhausted of elements after determining the count value.

        Example usage:

        assert [2,4,2,1,3,5,2,4,3].toSet().iterator().count{ it % 2 == 0 } == 2
        Parameters:
        self - the Iterator from which we count the number of matching occurrences
        closure - a closure condition
        Returns:
        the number of occurrences
        Since:
        1.8.0
      • count

        public static java.lang.Number count​(java.util.Collection self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value inside this collection. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).

        Example usage:

        assert [2,4,2,1,3,5,2,4,3].count(4) == 2
        Parameters:
        self - the collection within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.0
      • count

        public static java.lang.Number count​(java.util.Collection self,
                                             Closure closure)
        Counts the number of occurrences which satisfy the given closure from inside this collection.

        Example usage:

        assert [2,4,2,1,3,5,2,4,3].count{ it % 2 == 0 } == 5
        Parameters:
        self - the collection within which we count the number of occurrences
        closure - a closure condition
        Returns:
        the number of occurrences
        Since:
        1.8.0
      • count

        public static java.lang.Number count​(java.util.Map self,
                                             Closure<?> closure)
        Counts the number of occurrences which satisfy the given closure from inside this map. If the closure takes one parameter then it will be passed the Map.Entry. Otherwise, the closure should take two parameters and will be passed the key and value.

        Example usage:

        assert [a:1, b:1, c:2, d:2].count{ k,v -> k == 'a' || v == 2 } == 3
        Parameters:
        self - the map within which we count the number of occurrences
        closure - a 1 or 2 arg Closure condition applying on the entries
        Returns:
        the number of occurrences
        Since:
        1.8.0
      • count

        public static java.lang.Number count​(java.lang.Object[] self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).
        Parameters:
        self - the array within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.6.4
      • count

        public static java.lang.Number count​(java.lang.Object[] self,
                                             Closure closure)
        Counts the number of occurrences which satisfy the given closure from inside this array.
        Parameters:
        self - the array within which we count the number of occurrences
        closure - a closure condition
        Returns:
        the number of occurrences
        Since:
        1.8.0
      • count

        public static java.lang.Number count​(int[] self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).
        Parameters:
        self - the array within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.6.4
      • count

        public static java.lang.Number count​(long[] self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).
        Parameters:
        self - the array within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.6.4
      • count

        public static java.lang.Number count​(short[] self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).
        Parameters:
        self - the array within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.6.4
      • count

        public static java.lang.Number count​(char[] self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).
        Parameters:
        self - the array within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.6.4
      • count

        public static java.lang.Number count​(boolean[] self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).
        Parameters:
        self - the array within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.6.4
      • count

        public static java.lang.Number count​(double[] self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).
        Parameters:
        self - the array within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.6.4
      • count

        public static java.lang.Number count​(float[] self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).
        Parameters:
        self - the array within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.6.4
      • count

        public static java.lang.Number count​(byte[] self,
                                             java.lang.Object value)
        Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using compareTo(value) == 0 or equals(value) ).
        Parameters:
        self - the array within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.6.4
      • toList

        public static <T> java.util.List<T> toList​(java.util.Collection<T> self)
        Convert a Collection to a List. Always returns a new List even if the Collection is already a List.

        Example usage:

        def x = [1,2,3] as HashSet
         assert x.class == HashSet
         assert x.toList() instanceof List
        Parameters:
        self - a collection
        Returns:
        a List
        Since:
        1.0
      • toList

        public static <T> java.util.List<T> toList​(java.util.Iterator<T> self)
        Convert an iterator to a List. The iterator will become exhausted of elements after making this conversion.
        Parameters:
        self - an iterator
        Returns:
        a List
        Since:
        1.5.0
      • toList

        public static <T> java.util.List<T> toList​(java.lang.Iterable<T> self)
        Convert an Iterable to a List. The Iterable's iterator will become exhausted of elements after making this conversion.
        Parameters:
        self - an Iterable
        Returns:
        a List
        Since:
        1.8.7
      • toList

        public static <T> java.util.List<T> toList​(java.util.Enumeration<T> self)
        Convert an enumeration to a List.
        Parameters:
        self - an enumeration
        Returns:
        a List
        Since:
        1.5.0
      • collate

        public static <T> java.util.List<java.util.List<T>> collate​(java.util.List<T> self,
                                                                    int size)
        Collates this list into sub-lists of length size. Example:
        def list = [ 1, 2, 3, 4, 5, 6, 7 ]
         def coll = list.collate( 3 )
         assert coll == [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7 ] ]
        Parameters:
        self - a List
        size - the length of each sub-list in the returned list
        Returns:
        a List containing the data collated into sub-lists
        Since:
        1.8.6
      • collate

        public static <T> java.util.List<java.util.List<T>> collate​(java.util.List<T> self,
                                                                    int size,
                                                                    int step)
        Collates this list into sub-lists of length size stepping through the code step elements for each subList. Example:
        def list = [ 1, 2, 3, 4 ]
         def coll = list.collate( 3, 1 )
         assert coll == [ [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4 ], [ 4 ] ]
        Parameters:
        self - a List
        size - the length of each sub-list in the returned list
        step - the number of elements to step through for each sub-list
        Returns:
        a List containing the data collated into sub-lists
        Since:
        1.8.6
      • collate

        public static <T> java.util.List<java.util.List<T>> collate​(java.util.List<T> self,
                                                                    int size,
                                                                    boolean keepRemainder)
        Collates this list into sub-lists of length size. Any remaining elements in the list after the subdivision will be dropped if keepRemainder is false. Example:
        def list = [ 1, 2, 3, 4, 5, 6, 7 ]
         def coll = list.collate( 3, false )
         assert coll == [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
        Parameters:
        self - a List
        size - the length of each sub-list in the returned list
        keepRemainder - if true, any rmeaining elements are returned as sub-lists. Otherwise they are discarded
        Returns:
        a List containing the data collated into sub-lists
        Since:
        1.8.6
      • collate

        public static <T> java.util.List<java.util.List<T>> collate​(java.util.List<T> self,
                                                                    int size,
                                                                    int step,
                                                                    boolean keepRemainder)
        Collates this list into sub-lists of length size stepping through the code step elements for each sub-list. Any remaining elements in the list after the subdivision will be dropped if keepRemainder is false. Example:
        def list = [ 1, 2, 3, 4 ]
         assert list.collate( 3, 1, true  ) == [ [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4 ], [ 4 ] ]
         assert list.collate( 3, 1, false ) == [ [ 1, 2, 3 ], [ 2, 3, 4 ] ]
        Parameters:
        self - a List
        size - the length of each sub-list in the returned list
        step - the number of elements to step through for each sub-list
        keepRemainder - if true, any rmeaining elements are returned as sub-lists. Otherwise they are discarded
        Returns:
        a List containing the data collated into sub-lists
        Since:
        1.8.6
      • collect

        public static <T> java.util.List<T> collect​(java.lang.Object self,
                                                    Closure<T> transform)
        Iterates through this aggregate Object transforming each item into a new value using the transform closure, returning a list of transformed values. Example:
        def list = [1, 'a', 1.23, true ]
         def types = list.collect { it.class }
         assert types == [Integer, String, BigDecimal, Boolean]
        Parameters:
        self - an aggregate Object with an Iterator returning its items
        transform - the closure used to transform each item of the aggregate object
        Returns:
        a List of the transformed values
        Since:
        1.0
      • collect

        public static java.util.Collection collect​(java.lang.Object self)
        Iterates through this aggregate Object transforming each item into a new value using Closure.IDENTITY as a transformer, basically returning a list of items copied from the original object.
        assert [1,2,3] == [1,2,3].iterator().collect()
        Parameters:
        self - an aggregate Object with an Iterator returning its items
        Returns:
        a List of the transformed values
        Since:
        1.8.5
        See Also:
        Closure.IDENTITY
      • collect

        public static <T> java.util.Collection<T> collect​(java.lang.Object self,
                                                          java.util.Collection<T> collector,
                                                          Closure<? extends T> transform)
        Iterates through this aggregate Object transforming each item into a new value using the transform closure and adding it to the supplied collector.
        Parameters:
        self - an aggregate Object with an Iterator returning its items
        collector - the Collection to which the transformed values are added
        transform - the closure used to transform each item of the aggregate object
        Returns:
        the collector with all transformed values added to it
        Since:
        1.0
      • collect

        public static <T> java.util.List<T> collect​(java.util.Collection<?> self,
                                                    Closure<T> transform)
        Iterates through this collection transforming each entry into a new value using the transform closure returning a list of transformed values.
        assert [2,4,6] == [1,2,3].collect { it * 2 }
        Parameters:
        self - a collection
        transform - the closure used to transform each item of the collection
        Returns:
        a List of the transformed values
        Since:
        1.0
      • collect

        public static <T> java.util.List<T> collect​(java.util.Collection<T> self)
        Iterates through this collection transforming each entry into a new value using Closure.IDENTITY as a transformer, basically returning a list of items copied from the original collection.
        assert [1,2,3] == [1,2,3].collect()
        Parameters:
        self - a collection
        Returns:
        a List of the transformed values
        Since:
        1.8.5
        See Also:
        Closure.IDENTITY
      • collect

        public static <T> java.util.Collection<T> collect​(java.util.Collection<?> self,
                                                          java.util.Collection<T> collector,
                                                          Closure<? extends T> transform)
        Iterates through this collection transforming each value into a new value using the transform closure and adding it to the supplied collector.
        assert [1,2,3] as HashSet == [2,4,5,6].collect(new HashSet()) { (int)(it / 2) }
        Parameters:
        self - a collection
        collector - the Collection to which the transformed values are added
        transform - the closure used to transform each item of the collection
        Returns:
        the collector with all transformed values added to it
        Since:
        1.0
      • collectAll

        public static java.util.List collectAll​(java.util.Collection self,
                                                Closure transform)
        Deprecated.
        Use collectNested instead
        Deprecated alias for collectNested
        See Also:
        collectNested(Collection, Closure)
      • collectNested

        public static java.util.List collectNested​(java.util.Collection self,
                                                   Closure transform)
        Recursively iterates through this collection transforming each non-Collection value into a new value using the closure as a transformer. Returns a potentially nested list of transformed values.
         assert [2,[4,6],[8],[]] == [1,[2,3],[4],[]].collectNested { it * 2 }
         
        Parameters:
        self - a collection
        transform - the closure used to transform each item of the collection
        Returns:
        the resultant collection
        Since:
        1.8.1
      • collectAll

        public static java.util.Collection collectAll​(java.util.Collection self,
                                                      java.util.Collection collector,
                                                      Closure transform)
        Deprecated.
        Use collectNested instead
        Deprecated alias for collectNested
        See Also:
        collectNested(Collection, Collection, Closure)
      • collectNested

        public static java.util.Collection collectNested​(java.util.Collection self,
                                                         java.util.Collection collector,
                                                         Closure transform)
        Recursively iterates through this collection transforming each non-Collection value into a new value using the transform closure. Returns a potentially nested collection of transformed values.
        def x = [1,[2,3],[4],[]].collectNested(new Vector()) { it * 2 }
         assert x == [2,[4,6],[8],[]]
         assert x instanceof Vector
        Parameters:
        self - a collection
        collector - an initial Collection to which the transformed values are added
        transform - the closure used to transform each element of the collection
        Returns:
        the collector with all transformed values added to it
        Since:
        1.8.1
      • collectMany

        public static <T> java.util.List<T> collectMany​(java.util.Collection self,
                                                        Closure<java.util.Collection<? extends T>> projection)
        Projects each item from a source collection to a collection and concatenates (flattens) the resulting collections into a single list.

         def nums = 1..10
         def squaresAndCubesOfEvens = nums.collectMany{ it % 2 ? [] : [it**2, it**3] }
         assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216, 64, 512, 100, 1000]
        
         def animals = ['CAT', 'DOG', 'ELEPHANT'] as Set
         def smallAnimals = animals.collectMany{ it.size() > 3 ? [] : [it.toLowerCase()] }
         assert smallAnimals == ['cat', 'dog']
        
         def orig = nums as Set
         def origPlusIncrements = orig.collectMany{ [it, it+1] }
         assert origPlusIncrements.size() == orig.size() * 2
         assert origPlusIncrements.unique().size() == orig.size() + 1
         
        Parameters:
        self - a collection
        projection - a projecting Closure returning a collection of items
        Returns:
        a list created from the projected collections concatenated (flattened) together
        Since:
        1.8.1
        See Also:
        sum(java.util.Collection, groovy.lang.Closure)
      • collectMany

        public static <T> java.util.Collection<T> collectMany​(java.util.Collection self,
                                                              java.util.Collection<T> collector,
                                                              Closure<java.util.Collection<? extends T>> projection)
        Projects each item from a source collection to a result collection and concatenates (flattens) the resulting collections adding them into the collector.

         def animals = ['CAT', 'DOG', 'ELEPHANT'] as Set
         def smallAnimals = animals.collectMany(['ant', 'bee']){ it.size() > 3 ? [] : [it.toLowerCase()] }
         assert smallAnimals == ['ant', 'bee', 'cat', 'dog']
        
         def nums = 1..5
         def origPlusIncrements = nums.collectMany([] as Set){ [it, it+1] }
         assert origPlusIncrements.size() == nums.size() + 1
         
        Parameters:
        self - a collection
        collector - an initial collection to add the projected items to
        projection - a projecting Closure returning a collection of items
        Returns:
        the collector with the projected collections concatenated (flattened) to it
        Since:
        1.8.5
      • collectMany

        public static <T> java.util.Collection<T> collectMany​(java.util.Map<?,​?> self,
                                                              java.util.Collection<T> collector,
                                                              Closure<java.util.Collection<? extends T>> projection)
        Projects each item from a source map to a result collection and concatenates (flattens) the resulting collections adding them into the collector.

         def map = [bread:3, milk:5, butter:2]
         def result = map.collectMany(['x']){ k, v -> k.startsWith('b') ? k.toList() : [] }
         assert result == ['x', 'b', 'r', 'e', 'a', 'd', 'b', 'u', 't', 't', 'e', 'r']
         
        Parameters:
        self - a map
        collector - an initial collection to add the projected items to
        projection - a projecting Closure returning a collection of items
        Returns:
        the collector with the projected collections concatenated (flattened) to it
        Since:
        1.8.8
      • collectMany

        public static <T> java.util.Collection<T> collectMany​(java.util.Map<?,​?> self,
                                                              Closure<java.util.Collection<? extends T>> projection)
        Projects each item from a source map to a result collection and concatenates (flattens) the resulting collections adding them into a collection.

         def map = [bread:3, milk:5, butter:2]
         def result = map.collectMany{ k, v -> k.startsWith('b') ? k.toList() : [] }
         assert result == ['b', 'r', 'e', 'a', 'd', 'b', 'u', 't', 't', 'e', 'r']
         
        Parameters:
        self - a map
        projection - a projecting Closure returning a collection of items
        Returns:
        the collector with the projected collections concatenated (flattened) to it
        Since:
        1.8.8
      • collectMany

        public static <T> java.util.List<T> collectMany​(java.lang.Object[] self,
                                                        Closure<java.util.Collection<? extends T>> projection)
        Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.

         def nums = [1, 2, 3, 4, 5, 6] as Object[]
         def squaresAndCubesOfEvens = nums.collectMany{ it % 2 ? [] : [it**2, it**3] }
         assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216]
         
        Parameters:
        self - an object array
        projection - a projecting Closure returning a collection of items
        Returns:
        a list created from the projected collections concatenated (flattened) together
        Since:
        1.8.1
        See Also:
        sum(Object[], groovy.lang.Closure)
      • collectMany

        public static <T> java.util.List<T> collectMany​(java.util.Iterator<java.lang.Object> self,
                                                        Closure<java.util.Collection<? extends T>> projection)
        Projects each item from a source iterator to a collection and concatenates (flattens) the resulting collections into a single list.

         def numsIter = [1, 2, 3, 4, 5, 6].iterator()
         def squaresAndCubesOfEvens = numsIter.collectMany{ it % 2 ? [] : [it**2, it**3] }
         assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216]
         
        Parameters:
        self - an iterator
        projection - a projecting Closure returning a collection of items
        Returns:
        a list created from the projected collections concatenated (flattened) together
        Since:
        1.8.1
        See Also:
        sum(Iterator, groovy.lang.Closure)
      • collect

        public static <T> java.util.Collection<T> collect​(java.util.Map<?,​?> self,
                                                          java.util.Collection<T> collector,
                                                          Closure<? extends T> transform)
        Iterates through this Map transforming each map entry into a new value using the transform closure returning the collector with all transformed vakues added to it.
        assert [a:1, b:2].collect( [] as HashSet ) { key, value -> key*value } == ["a", "bb"] as Set
         assert [3:20, 2:30].collect( [] as HashSet ) { entry -> entry.key * entry.value } == [60] as Set
        Parameters:
        self - a Map
        collector - the Collection to which transformed values are added
        transform - the transformation closure which can take one (Map.Entry) or two (key, value) parameters
        Returns:
        the collector with all transformed values added to it
        Since:
        1.0
      • collect

        public static <T> java.util.List<T> collect​(java.util.Map self,
                                                    Closure<T> transform)
        Iterates through this Map transforming each map entry into a new value using the transform closure returning a list of transformed values.
        assert [a:1, b:2].collect { key, value -> key*value } == ["a", "bb"]
         assert [3:20, 2:30].collect { entry -> entry.key * entry.value } == [60, 60]
        Parameters:
        self - a Map
        transform - the transformation closure which can take one (Map.Entry) or two (key, value) parameters
        Returns:
        the resultant list of transformed values
        Since:
        1.0
      • collectEntries

        public static <K,​V> java.util.Map<K,​V> collectEntries​(java.util.Map<?,​?> self,
                                                                          java.util.Map<K,​V> collector,
                                                                          Closure<?> transform)
        Iterates through this Map transforming each map entry using the transform closure returning a map of the transformed entries.
         assert [a:1, b:2].collectEntries( [:] ) { k, v -> [v, k] } == [1:'a', 2:'b']
         assert [a:1, b:2].collectEntries( [30:'C'] ) { key, value ->
             [(value*10): key.toUpperCase()] } == [10:'A', 20:'B', 30:'C']
         
        Parameters:
        self - a Map
        collector - the Map into which the transformed entries are put
        transform - the closure used for transforming, which can take one (Map.Entry) or two (key, value) parameters and should return a Map.Entry, a Map or a two-element list containing the resulting key and value
        Returns:
        the collector with all transformed values added to it
        Since:
        1.7.9
        See Also:
        collect(Map, Collection, Closure)
      • collectEntries

        public static java.util.Map<?,​?> collectEntries​(java.util.Map<?,​?> self,
                                                              Closure<?> transform)
        Iterates through this Map transforming each entry using the transform closure and returning a map of the transformed entries.
         assert [a:1, b:2].collectEntries { key, value -> [value, key] } == [1:'a', 2:'b']
         assert [a:1, b:2].collectEntries { key, value ->
             [(value*10): key.toUpperCase()] } == [10:'A', 20:'B']
         
        Parameters:
        self - a Map
        transform - the closure used for transforming, which can take one (Map.Entry) or two (key, value) parameters and should return a Map.Entry, a Map or a two-element list containing the resulting key and value
        Returns:
        a Map of the transformed entries
        Since:
        1.7.9
        See Also:
        collect(Map, Collection, Closure)
      • collectEntries

        public static <K,​V> java.util.Map<K,​V> collectEntries​(java.util.Collection<?> self,
                                                                          Closure<?> transform)
        Iterates through this Collection transforming each item using the transform closure and returning a map of the resulting transformed entries.
         def letters = "abc"
         // collect letters with index using list style
         assert (0..2).collectEntries { index -> [index, letters[index]] } == [0:'a', 1:'b', 2:'c']
         // collect letters with index using map style
         assert (0..2).collectEntries { index -> [(index): letters[index]] } == [0:'a', 1:'b', 2:'c']
         
        Parameters:
        self - a Collection
        transform - the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value
        Returns:
        a Map of the transformed entries
        Since:
        1.7.9
        See Also:
        collectEntries(Collection, Map, Closure)
      • collectEntries

        public static <K,​V> java.util.Map<K,​V> collectEntries​(java.util.Collection<?> self)
        A variant of collectEntries using the identity closure as the transform. The source collection should be a list of [key, value] tuples or a Map.Entry.
         def nums = [1, 10, 100, 1000]
         def tuples = nums.collect{ [it, it.toString().size()] }
         assert tuples == [[1, 1], [10, 2], [100, 3], [1000, 4]]
         def map = tuples.collectEntries()
         assert map == [1:1, 10:2, 100:3, 1000:4]
         
        Parameters:
        self - a Collection
        Returns:
        a Map of the transformed entries
        Since:
        1.8.5
        See Also:
        collectEntries(Collection, Closure)
      • collectEntries

        public static <K,​V> java.util.Map<K,​V> collectEntries​(java.util.Collection<?> self,
                                                                          java.util.Map<K,​V> collector,
                                                                          Closure<?> transform)
        Iterates through this Collection transforming each item using the closure as a transformer into a map entry, returning a map of the transformed entries.
         def letters = "abc"
         // collect letters with index
         assert (0..2).collectEntries( [:] ) { index -> [index, letters[index]] } == [0:'a', 1:'b', 2:'c']
         assert (0..2).collectEntries( [4:'d'] ) { index ->
             [(index+1): letters[index]] } == [1:'a', 2:'b', 3:'c', 4:'d']
         
        Parameters:
        self - a Collection
        collector - the Map into which the transformed entries are put
        transform - the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value
        Returns:
        the collector with all transformed values added to it
        Since:
        1.7.9
        See Also:
        collect(Map, Collection, Closure)
      • collectEntries

        public static <K,​V> java.util.Map<K,​V> collectEntries​(java.util.Collection<?> self,
                                                                          java.util.Map<K,​V> collector)
        A variant of collectEntries using the identity closure as the transform.
        Parameters:
        self - a Collection
        collector - the Map into which the transformed entries are put
        Returns:
        the collector with all transformed values added to it
        Since:
        1.8.5
        See Also:
        collectEntries(Collection, Map, Closure)
      • collectEntries

        public static <K,​V> java.util.Map<K,​V> collectEntries​(java.lang.Object[] self,
                                                                          java.util.Map<K,​V> collector,
                                                                          Closure<?> transform)
        Iterates through this array transforming each item using the transform closure and returning a map of the resulting transformed entries.
         def letters = "abc"
         def nums = [0, 1, 2] as Integer[]
         // collect letters with index
         assert nums.collectEntries( [:] ) { index -> [index, letters[index]] } == [0:'a', 1:'b', 2:'c']
         assert nums.collectEntries( [4:'d'] ) { index ->
             [(index+1): letters[index]] } == [1:'a', 2:'b', 3:'c', 4:'d']
         
        Parameters:
        self - an Object array
        collector - the Map into which the transformed entries are put
        transform - the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value
        Returns:
        the collector with all transformed values added to it
        Since:
        1.7.9
        See Also:
        collect(Map, Collection, Closure)
      • collectEntries

        public static <K,​V> java.util.Map<K,​V> collectEntries​(java.lang.Object[] self,
                                                                          java.util.Map<K,​V> collector)
        A variant of collectEntries using the identity closure as the transform.
        Parameters:
        self - an Object array
        collector - the Map into which the transformed entries are put
        Returns:
        the collector with all transformed values added to it
        Since:
        1.8.5
        See Also:
        collectEntries(Object[], Map, Closure)
      • collectEntries

        public static <K,​V> java.util.Map<K,​V> collectEntries​(java.lang.Object[] self,
                                                                          Closure<?> transform)
        Iterates through this array transforming each item using the transform closure and returning a map of the resulting transformed entries.
         def letters = "abc"
         def nums = [0, 1, 2] as Integer[]
         // collect letters with index using list style
         assert nums.collectEntries { index -> [index, letters[index]] } == [0:'a', 1:'b', 2:'c']
         // collect letters with index using map style
         assert nums.collectEntries { index -> [(index): letters[index]] } == [0:'a', 1:'b', 2:'c']
         
        Parameters:
        self - a Collection
        transform - the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value
        Returns:
        a Map of the transformed entries
        Since:
        1.7.9
        See Also:
        collectEntries(Collection, Map, Closure)
      • collectEntries

        public static <K,​V> java.util.Map<K,​V> collectEntries​(java.lang.Object[] self)
        A variant of collectEntries using the identity closure as the transform.
        Parameters:
        self - an Object array
        Returns:
        the collector with all transformed values added to it
        Since:
        1.8.5
        See Also:
        collectEntries(Object[], Closure)
      • find

        public static java.lang.Object find​(java.lang.Object self,
                                            Closure closure)
        Finds the first value matching the closure condition
        Parameters:
        self - an Object with an iterator returning its values
        closure - a closure condition
        Returns:
        the first Object found or null if none was found
        Since:
        1.0
      • find

        public static java.lang.Object find​(java.lang.Object self)
        Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).

        Example:

         def items = [null, 0, 0.0, false, '', [], 42, 43]
         assert items.find() == 42
         
        Parameters:
        self - an Object with an Iterator returning its values
        Returns:
        the first Object found or null if none was found
        Since:
        1.8.1
        See Also:
        Closure.IDENTITY
      • findResult

        public static java.lang.Object findResult​(java.lang.Object self,
                                                  java.lang.Object defaultResult,
                                                  Closure closure)
        Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns the defaultResult.
        Parameters:
        self - an Object with an iterator returning its values
        defaultResult - an Object that should be returned if all closure results are null
        closure - a closure that returns a non-null value when processing should stop
        Returns:
        the first non-null result of the closure, otherwise the default value
        Since:
        1.7.5
      • findResult

        public static java.lang.Object findResult​(java.lang.Object self,
                                                  Closure closure)
        Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns null.
        Parameters:
        self - an Object with an iterator returning its values
        closure - a closure that returns a non-null value when processing should stop
        Returns:
        the first non-null result of the closure
        Since:
        1.7.5
      • find

        public static <T> T find​(java.util.Collection<T> self,
                                 Closure closure)
        Finds the first value matching the closure condition. Example:
        def list = [1,2,3]
         assert 2 == list.find { it > 1 }
         
        Parameters:
        self - a Collection
        closure - a closure condition
        Returns:
        the first Object found
        Since:
        1.0
      • find

        public static <T> T find​(java.util.Collection<T> self)
        Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).

        Example:

         def items = [null, 0, 0.0, false, '', [], 42, 43]
         assert items.find() == 42
         
        Parameters:
        self - a Collection
        Returns:
        the first Object found or null if none was found
        Since:
        1.8.1
        See Also:
        Closure.IDENTITY
      • findResult

        public static <T,​U extends T,​V extends T> T findResult​(java.util.Collection<?> self,
                                                                           U defaultResult,
                                                                           Closure<V> closure)
        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.

        Examples:

         def list = [1,2,3]
         assert "Found 2" == list.findResult("default") { it > 1 ? "Found $it" : null }
         assert "default" == list.findResult("default") { it > 3 ? "Found $it" : null }
         
        Parameters:
        self - a Collection
        defaultResult - an Object that should be returned if all closure results are null
        closure - a closure that returns a non-null value when processing should stop and a value should be returned
        Returns:
        the first non-null result from calling the closure, or the defaultValue
        Since:
        1.7.5
      • findResult

        public static <T> T findResult​(java.util.Collection<?> self,
                                       Closure<T> closure)
        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 results are null, null is returned.

        Example:

         def list = [1,2,3]
         assert "Found 2" == list.findResult { it > 1 ? "Found $it" : null }
         
        Parameters:
        self - a Collection
        closure - a closure that returns a non-null value when processing should stop and a value should be returned
        Returns:
        the first non-null result from calling the closure, or null
        Since:
        1.7.5
      • findResults

        public static <T> java.util.Collection<T> findResults​(java.util.Collection<?> self,
                                                              Closure<T> filteringTransform)
        Iterates through the collection transforming items using the supplied closure and collecting any non-null results.

        Example:

         def list = [1,2,3]
         def result = list.findResults { it > 1 ? "Found $it" : null }
         assert result == ["Found 2", "Found 3"]
         
        Parameters:
        self - a Collection
        filteringTransform - a Closure that should return either a non-null transformed value or null for items which should be discarded
        Returns:
        the list of non-null transformed values
        Since:
        1.8.1
      • findResults

        public static <T> java.util.Collection<T> findResults​(java.util.Map<?,​?> self,
                                                              Closure<T> filteringTransform)
        Iterates through the map transforming items using the supplied closure and collecting any non-null results. If the closure takes two parameters, the entry key and value are passed. If the closure takes one parameter, the Map.Entry object is passed.

        Example:

         def map = [a:1, b:2, hi:2, cat:3, dog:2]
         def result = map.findResults { k, v -> k.size() == v ? "Found $k:$v" : null }
         assert result == ["Found a:1", "Found hi:2", "Found cat:3"]
         
        Parameters:
        self - a Map
        filteringTransform - a 1 or 2 arg Closure that should return either a non-null transformed value or null for items which should be discarded
        Returns:
        the list of non-null transformed values
        Since:
        1.8.1
      • find

        public static <K,​V> java.util.Map.Entry<K,​V> find​(java.util.Map<K,​V> self,
                                                                      Closure<?> closure)
        Finds the first entry matching the closure condition. If the closure takes two parameters, the entry key and value are passed. If the closure takes one parameter, the Map.Entry object is passed.
        assert [a:1, b:3].find { it.value == 3 }.key == "b"
        Parameters:
        self - a Map
        closure - a 1 or 2 arg Closure condition
        Returns:
        the first Object found
        Since:
        1.0
      • findResult

        public static <T,​U extends T,​V extends T> T findResult​(java.util.Map<?,​?> self,
                                                                           U defaultResult,
                                                                           Closure<V> closure)
        Returns the first non-null closure result found by passing each map entry to the closure, otherwise the defaultResult is returned. If the closure takes two parameters, the entry key and value are passed. If the closure takes one parameter, the Map.Entry object is passed.
         assert "Found b:3" == [a:1, b:3].findResult("default") { if (it.value == 3) return "Found ${it.key}:${it.value}" }
         assert "default" == [a:1, b:3].findResult("default") { if (it.value == 9) return "Found ${it.key}:${it.value}" }
         assert "Found a:1" == [a:1, b:3].findResult("default") { k, v -> if (k.size() + v == 2) return "Found $k:$v" }
         
        Parameters:
        self - a Map
        defaultResult - an Object that should be returned if all closure results are null
        closure - a 1 or 2 arg Closure that returns a non-null value when processing should stop and a value should be returned
        Returns:
        the first non-null result collected by calling the closure, or the defaultResult if no such result was found
        Since:
        1.7.5
      • findResult

        public static <T> T findResult​(java.util.Map<?,​?> self,
                                       Closure<T> closure)
        Returns the first non-null closure result found by passing each map entry to the closure, otherwise null is returned. If the closure takes two parameters, the entry key and value are passed. If the closure takes one parameter, the Map.Entry object is passed.
         assert "Found b:3" == [a:1, b:3].findResult { if (it.value == 3) return "Found ${it.key}:${it.value}" }
         assert null == [a:1, b:3].findResult { if (it.value == 9) return "Found ${it.key}:${it.value}" }
         assert "Found a:1" == [a:1, b:3].findResult { k, v -> if (k.size() + v == 2) return "Found $k:$v" }
         
        Parameters:
        self - a Map
        closure - a 1 or 2 arg Closure that returns a non-null value when processing should stop and a value should be returned
        Returns:
        the first non-null result collected by calling the closure, or null if no such result was found
        Since:
        1.7.5
      • findAll

        public static <T> java.util.Collection<T> findAll​(java.util.Collection<T> self,
                                                          Closure closure)
        Finds all values matching the closure condition.
        assert [2,4] == [1,2,3,4].findAll { it % 2 == 0 }
        Parameters:
        self - a Collection
        closure - a closure condition
        Returns:
        a Collection of matching values
        Since:
        1.5.6
      • findAll

        public static <T> java.util.Collection<T> findAll​(java.util.Collection<T> self)
        Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).

        Example:

         def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null]
         assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
         
        Parameters:
        self - a Collection
        Returns:
        a List of the values found
        Since:
        1.8.1
        See Also:
        Closure.IDENTITY
      • findAll

        public static java.util.Collection findAll​(java.lang.Object self,
                                                   Closure closure)
        Finds all items matching the closure condition.
        Parameters:
        self - an Object with an Iterator returning its values
        closure - a closure condition
        Returns:
        a List of the values found
        Since:
        1.6.0
      • findAll

        public static java.util.Collection findAll​(java.lang.Object self)
        Finds all items matching the IDENTITY Closure (i.e. matching Groovy truth).

        Example:

         def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null]
         assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
         
        Parameters:
        self - an Object with an Iterator returning its values
        Returns:
        a List of the values found
        Since:
        1.8.1
        See Also:
        Closure.IDENTITY
      • containsAll

        public static boolean containsAll​(java.util.Collection self,
                                          java.lang.Object[] items)
        Returns true if this collection contains all of the elements in the specified array.
        Parameters:
        self - a Collection to be checked for containment
        items - array to be checked for containment in this collection
        Returns:
        true if this collection contains all of the elements in the specified array
        Since:
        1.7.2
        See Also:
        Collection.containsAll(Collection)
      • removeAll

        public static boolean removeAll​(java.util.Collection self,
                                        java.lang.Object[] items)
        Modifies this collection by removing its elements that are contained within the specified object array. See also findAll and grep when wanting to produce a new list containing items which don't match some criteria while leaving the original collection unchanged.
        Parameters:
        self - a Collection to be modified
        items - array containing elements to be removed from this collection
        Returns:
        true if this collection changed as a result of the call
        Since:
        1.7.2
        See Also:
        Collection.removeAll(Collection)
      • retainAll

        public static boolean retainAll​(java.util.Collection self,
                                        java.lang.Object[] items)
        Modifies this collection so that it retains only its elements that are contained in the specified array. In other words, removes from this collection all of its elements that are not contained in the specified array. See also grep and findAll when wanting to produce a new list containing items which match some specified items but leaving the original collection unchanged.
        Parameters:
        self - a Collection to be modified
        items - array containing elements to be retained from this collection
        Returns:
        true if this collection changed as a result of the call
        Since:
        1.7.2
        See Also:
        Collection.retainAll(Collection)
      • retainAll

        public static boolean retainAll​(java.util.Collection self,
                                        Closure condition)
        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. See also findAll and grep when wanting to produce a new list containing items which match some criteria but leaving the original collection unchanged.
        Parameters:
        self - a Collection to be modified
        condition - a closure condition
        Returns:
        true if this collection changed as a result of the call
        Since:
        1.7.2
        See Also:
        Iterator.remove()
      • removeAll

        public static boolean removeAll​(java.util.Collection self,
                                        Closure condition)
        Modifies this collection by removing the elements that are matched according to the specified closure condition. See also findAll and grep when wanting to produce a new list containing items which don't match some criteria while leaving the original collection unchanged.
        Parameters:
        self - a Collection to be modified
        condition - a closure condition
        Returns:
        true if this collection changed as a result of the call
        Since:
        1.7.2
        See Also:
        Iterator.remove()
      • addAll

        public static <T> boolean addAll​(java.util.Collection<T> self,
                                         T[] 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. See also plus or the '+' operator if wanting to produce a new collection containing additional items but while leaving the original collection unchanged.
        Parameters:
        self - a Collection to be modified
        items - array containing elements to be added to this collection
        Returns:
        true if this collection changed as a result of the call
        Since:
        1.7.2
        See Also:
        Collection.addAll(Collection)
      • addAll

        public static <T> boolean addAll​(java.util.List<T> self,
                                         int index,
                                         T[] items)
        Modifies this list by inserting all of the elements in the specified array into the list at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they occur in the array. The behavior of this operation is undefined if the specified array is modified while the operation is in progress. See also plus for similar functionality with copy semantics, i.e. which produces a new list after adding the additional items at the specified position but leaves the original list unchanged.
        Parameters:
        self - a list to be modified
        items - array containing elements to be added to this collection
        index - index at which to insert the first element from the specified array
        Returns:
        true if this collection changed as a result of the call
        Since:
        1.7.2
        See Also:
        List.addAll(int, Collection)
      • split

        public static java.util.Collection split​(java.lang.Object self,
                                                 Closure closure)
        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.
        Parameters:
        self - an Object with an Iterator returning its values
        closure - a closure condition
        Returns:
        a List whose first item is the accepted values and whose second item is the rejected values
        Since:
        1.6.0
      • split

        public static <T> java.util.Collection<java.util.Collection<T>> split​(java.util.Collection<T> self,
                                                                              Closure closure)
        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.

        Example usage:

        assert [[2,4],[1,3]] == [1,2,3,4].split { it % 2 == 0 }
        Parameters:
        self - a Collection of values
        closure - a closure condition
        Returns:
        a List whose first item is the accepted values and whose second item is the rejected values
        Since:
        1.6.0
      • combinations

        public static java.util.List combinations​(java.util.Collection self)
        Adds GroovyCollections#combinations(Collection) as a method on collections.

        Example usage:

        assert [['a', 'b'],[1, 2, 3]].combinations() == [['a', 1], ['b', 1], ['a', 2], ['b', 2], ['a', 3], ['b', 3]]
        Parameters:
        self - a Collection of lists
        Returns:
        a List of the combinations found
        Since:
        1.5.0
        See Also:
        GroovyCollections.combinations(java.util.Collection)
      • subsequences

        public static <T> java.util.Set<java.util.List<T>> subsequences​(java.util.List<T> self)
        Finds all non-null subsequences of a list.

        Example usage:

        def result = [1, 2, 3].subsequences()
         assert result == [[1, 2, 3], [1, 3], [2, 3], [1, 2], [1], [2], [3]] as Set
        Parameters:
        self - the List of items
        Returns:
        the subsequences from the list
        Since:
        1.7.0
      • permutations

        public static <T> java.util.Set<java.util.List<T>> permutations​(java.util.List<T> self)
        Finds all permutations of a collection.

        Example usage:

        def result = [1, 2, 3].permutations()
         assert result == [[3, 2, 1], [3, 1, 2], [1, 3, 2], [2, 3, 1], [2, 1, 3], [1, 2, 3]] as Set
        Parameters:
        self - the Collection of items
        Returns:
        the permutations from the list
        Since:
        1.7.0
      • eachPermutation

        public static <T> java.util.Iterator<java.util.List<T>> eachPermutation​(java.util.Collection<T> self,
                                                                                Closure closure)
        Iterates over all permutations of a collection, running a closure for each iteration.

        Example usage:

        def permutations = []
         [1, 2, 3].eachPermutation{ permutations << it }
         assert permutations == [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
        Parameters:
        self - the Collection of items
        closure - the closure to call for each permutation
        Returns:
        the permutations from the list
        Since:
        1.7.0
      • transpose

        public static java.util.List transpose​(java.util.List self)
        Adds GroovyCollections#transpose(List) as a method on lists.
        A TransposeFunction takes a collection of columns and returns a collection of rows. The first row consists of the first element from each column. Successive rows are constructed similarly.

        Example usage:

        def result = [['a', 'b'], [1, 2]].transpose()
         assert result == [['a', 1], ['b', 2]]
        def result = [['a', 'b'], [1, 2], [3, 4]].transpose()
         assert result == [['a', 1, 3], ['b', 2, 4]]
        Parameters:
        self - a List of lists
        Returns:
        a List of the transposed lists
        Since:
        1.5.0
        See Also:
        GroovyCollections.transpose(java.util.List)
      • findAll

        public static <K,​V> java.util.Map<K,​V> findAll​(java.util.Map<K,​V> self,
                                                                   Closure closure)
        Finds all entries matching the closure condition. If the closure takes one parameter then it will be passed the Map.Entry. Otherwise if the closure should take two parameters, which will be the key and the value.

        If the self map is one of TreeMap, LinkedHashMap, Hashtable or Properties, the returned Map will preserve that type, otherwise a HashMap will be returned.

        Example usage:

        def result = [a:1, b:2, c:4, d:5].findAll { it.value % 2 == 0 }
         assert result.every { it instanceof Map.Entry }
         assert result*.key == ["b", "c"]
         assert result*.value == [2, 4]
        Parameters:
        self - a Map
        closure - a 1 or 2 arg Closure condition applying on the entries
        Returns:
        a new subMap
        Since:
        1.0
      • groupBy

        public static <K,​T> java.util.Map<K,​java.util.List<T>> groupBy​(java.util.Collection<T> self,
                                                                                   Closure<K> closure)
        Sorts all collection members into groups determined by the supplied mapping closure. The closure should return the key that this item should be grouped by. The returned LinkedHashMap will have an entry for each distinct key returned from the closure, with each value being a list of items for that group.

        Example usage:

        assert [0:[2,4,6], 1:[1,3,5]] == [1,2,3,4,5,6].groupBy { it % 2 }
        Parameters:
        self - a collection to group
        closure - a closure mapping entries on keys
        Returns:
        a new Map grouped by keys
        Since:
        1.0
      • groupBy

        public static java.util.Map groupBy​(java.util.Collection self,
                                            java.lang.Object... closures)
        Sorts all collection members into (sub)groups determined by the supplied mapping closures. Each closure should return the key that this item should be grouped by. The returned LinkedHashMap will have an entry for each distinct 'key path' returned from the closures, with each value being a list of items for that 'group path'.

        Example usage:

        def result = [1,2,3,4,5,6].groupBy({ it % 2 }, { it < 4 })
         assert result == [1:[(true):[1, 3], (false):[5]], 0:[(true):[2], (false):[4, 6]]]
        Another example:
        def sql = groovy.sql.Sql.newInstance(/* ... */)
         def data = sql.rows("SELECT * FROM a_table").groupBy({ it.column1 }, { it.column2 }, { it.column3 })
         if (data.val1.val2.val3) {
             // there exists a record where:
             //   a_table.column1 == val1
             //   a_table.column2 == val2, and
             //   a_table.column3 == val3
         } else {
             // there is no such record
         }
        If an empty array of closures is supplied the IDENTITY Closure will be used.
        Parameters:
        self - a collection to group
        closures - an array of closures, each mapping entries on keys
        Returns:
        a new Map grouped by keys on each criterion
        Since:
        1.8.1
        See Also:
        Closure.IDENTITY
      • groupBy

        public static java.util.Map groupBy​(java.util.Collection self,
                                            java.util.List<Closure> closures)
        Sorts all collection members into (sub)groups determined by the supplied mapping closures. Each closure should return the key that this item should be grouped by. The returned LinkedHashMap will have an entry for each distinct 'key path' returned from the closures, with each value being a list of items for that 'group path'.

        Example usage:

        def result = [1,2,3,4,5,6].groupBy([{ it % 2 }, { it < 4 }])
         assert result == [1:[(true):[1, 3], (false):[5]], 0:[(true):[2], (false):[4, 6]]]
        Another example:
        def sql = groovy.sql.Sql.newInstance(/* ... */)
         def data = sql.rows("SELECT * FROM a_table").groupBy([{ it.column1 }, { it.column2 }, { it.column3 }])
         if (data.val1.val2.val3) {
             // there exists a record where:
             //   a_table.column1 == val1
             //   a_table.column2 == val2, and
             //   a_table.column3 == val3
         } else {
             // there is no such record
         }
        If an empty list of closures is supplied the IDENTITY Closure will be used.
        Parameters:
        self - a collection to group
        closures - a list of closures, each mapping entries on keys
        Returns:
        a new Map grouped by keys on each criterion
        Since:
        1.8.1
        See Also:
        Closure.IDENTITY
      • countBy

        public static <K> java.util.Map<K,​java.lang.Integer> countBy​(java.util.Collection self,
                                                                           Closure<K> closure)
        Sorts all collection members into groups determined by the supplied mapping closure and counts the group size. The closure should return the key that each item should be grouped by. The returned Map will have an entry for each distinct key returned from the closure, with each value being the frequency of items occurring for that group.

        Example usage:

        assert [0:2, 1:3] == [1,2,3,4,5].countBy { it % 2 }
        Parameters:
        self - a collection to group and count
        closure - a closure mapping items to the frequency keys
        Returns:
        a new Map grouped by keys with frequency counts
        Since:
        1.8.0
      • countBy

        public static <K> java.util.Map<K,​java.lang.Integer> countBy​(java.lang.Object[] self,
                                                                           Closure<K> closure)
        Sorts all array members into groups determined by the supplied mapping closure and counts the group size. The closure should return the key that each item should be grouped by. The returned Map will have an entry for each distinct key returned from the closure, with each value being the frequency of items occurring for that group.

        Example usage:

        assert ([1,2,2,2,3] as Object[]).countBy{ it % 2 } == [1:2, 0:3]
        Parameters:
        self - an object array to group and count
        closure - a closure mapping items to the frequency keys
        Returns:
        a new Map grouped by keys with frequency counts
        Since:
        1.8.0
        See Also:
        countBy(Collection, Closure)
      • countBy

        public static <K> java.util.Map<K,​java.lang.Integer> countBy​(java.util.Iterator self,
                                                                           Closure<K> closure)
        Sorts all iterator items into groups determined by the supplied mapping closure and counts the group size. The closure should return the key that each item should be grouped by. The returned Map will have an entry for each distinct key returned from the closure, with each value being the frequency of items occurring for that group.

        Example usage:

        assert [1,2,2,2,3].toSet().iterator().countBy{ it % 2 } == [1:2, 0:1]
        Parameters:
        self - an iterator to group and count
        closure - a closure mapping items to the frequency keys
        Returns:
        a new Map grouped by keys with frequency counts
        Since:
        1.8.0
        See Also:
        countBy(Collection, Closure)
      • groupEntriesBy

        public static <G,​K,​V> java.util.Map<G,​java.util.List<java.util.Map.Entry<K,​V>>> groupEntriesBy​(java.util.Map<K,​V> self,
                                                                                                                               Closure<G> closure)
        Groups all map entries into groups determined by the supplied mapping closure. The closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group' key returned by the closure, with values being the list of map entries that belong to each group. (If instead of a list of map entries, you want an actual map use {code}groupBy{code}.)
        def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupEntriesBy { it.value % 2 }
         assert result[0]*.key == ["b", "d", "f"]
         assert result[1]*.value == [1, 3, 5]
        Parameters:
        self - a map to group
        closure - a 1 or 2 arg Closure mapping entries on keys
        Returns:
        a new Map grouped by keys
        Since:
        1.5.2
      • groupBy

        public static <G,​K,​V> java.util.Map<G,​java.util.Map<K,​V>> groupBy​(java.util.Map<K,​V> self,
                                                                                                  Closure<G> closure)
        Groups the members of a map into sub maps determined by the supplied mapping closure. The closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group' key returned by the closure, with values being the map members from the original map that belong to each group. (If instead of a map, you want a list of map entries use {code}groupEntriesBy{code}.)

        If the self map is one of TreeMap, Hashtable or Properties, the returned Map will preserve that type, otherwise a LinkedHashMap will be returned.

        def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupBy { it.value % 2 }
         assert result == [0:[b:2, d:4, f:6], 1:[a:1, c:3, e:5]]
        Parameters:
        self - a map to group
        closure - a closure mapping entries on keys
        Returns:
        a new Map grouped by keys
        Since:
        1.0
      • groupBy

        public static java.util.Map<java.lang.Object,​java.util.Map> groupBy​(java.util.Map self,
                                                                                  java.lang.Object... closures)
        Groups the members of a map into sub maps determined by the supplied mapping closures. Each closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group path' returned by all closures, with values being the map members from the original map that belong to each such 'group path'.

        If the self map is one of TreeMap, Hashtable, or Properties, the returned Map will preserve that type, otherwise a LinkedHashMap will be returned.

        def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupBy({ it.value % 2 }, { it.key.next() })
         assert result == [1:[b:[a:1], d:[c:3], f:[e:5]], 0:[c:[b:2], e:[d:4], g:[f:6]]]
        If an empty array of closures is supplied the IDENTITY Closure will be used.
        Parameters:
        self - a map to group
        closures - an array of closures that map entries on keys
        Returns:
        a new map grouped by keys on each criterion
        Since:
        1.8.1
        See Also:
        Closure.IDENTITY
      • groupBy

        public static java.util.Map<java.lang.Object,​java.util.Map> groupBy​(java.util.Map self,
                                                                                  java.util.List<Closure> closures)
        Groups the members of a map into sub maps determined by the supplied mapping closures. Each closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group path' returned by all closures, with values being the map members from the original map that belong to each such 'group path'.

        If the self map is one of TreeMap, Hashtable, or Properties, the returned Map will preserve that type, otherwise a LinkedHashMap will be returned.

        def result = [a:1,b:2,c:3,d:4,e:5,f:6].groupBy([{ it.value % 2 }, { it.key.next() }])
         assert result == [1:[b:[a:1], d:[c:3], f:[e:5]], 0:[c:[b:2], e:[d:4], g:[f:6]]]
        If an empty list of closures is supplied the IDENTITY Closure will be used.
        Parameters:
        self - a map to group
        closures - a list of closures that map entries on keys
        Returns:
        a new map grouped by keys on each criterion
        Since:
        1.8.1
        See Also:
        Closure.IDENTITY
      • countBy

        public static <K> java.util.Map<K,​java.lang.Integer> countBy​(java.util.Map self,
                                                                           Closure<K> closure)
        Groups the members of a map into groups determined by the supplied mapping closure and counts the frequency of the created groups. The closure will be passed a Map.Entry or key and value (depending on the number of parameters the closure accepts) and should return the key that each item should be grouped under. The resulting map will have an entry for each 'group' key returned by the closure, with values being the frequency counts for that 'group'.

        def result = [a:1,b:2,c:3,d:4,e:5].countBy { it.value % 2 }
         assert result == [0:2, 1:3]
        Parameters:
        self - a map to group and count
        closure - a closure mapping entries to frequency count keys
        Returns:
        a new Map grouped by keys with frequency counts
        Since:
        1.8.0
      • groupAnswer

        protected static <K,​T> void groupAnswer​(java.util.Map<K,​java.util.List<T>> answer,
                                                      T element,
                                                      K value)
        Groups the current element according to the value
        Parameters:
        answer - the map containing the results
        element - the element to be placed
        value - the value according to which the element will be placed
        Since:
        1.5.0
      • callClosureForMapEntry

        protected static <T> T callClosureForMapEntry​(Closure<T> closure,
                                                      java.util.Map.Entry entry)
      • callClosureForLine

        protected static <T> T callClosureForLine​(Closure<T> closure,
                                                  java.lang.String line,
                                                  int counter)
      • callClosureForMapEntryAndCounter

        protected static <T> T callClosureForMapEntryAndCounter​(Closure<T> closure,
                                                                java.util.Map.Entry entry,
                                                                int counter)
      • inject

        public static <T,​V extends T> T inject​(java.util.Collection<T> self,
                                                     Closure<V> closure)
        Performs the same function as the version of inject that takes an initial value, but uses the head of the Collection as the initial value, and iterates over the tail.
         assert 1 * 2 * 3 * 4 == [ 1, 2, 3, 4 ].inject { acc, val -> acc * val }
         assert ['b'] == [['a','b'], ['b','c'], ['d','b']].inject { acc, val -> acc.intersect( val ) }
         LinkedHashSet set = [ 't', 'i', 'm' ]
         assert 'tim' == set.inject { a, b -> a + b }
         
        Parameters:
        self - a Collection
        closure - a closure
        Returns:
        the result of the last closure call
        Throws:
        java.util.NoSuchElementException - if the collection is empty.
        Since:
        1.8.7
        See Also:
        inject(Collection, Object, Closure)
      • inject

        public static <T,​U extends T,​V extends T> T inject​(java.util.Collection self,
                                                                       U initialValue,
                                                                       Closure<V> closure)
        Iterates through the given Collection, passing in the initial value to the 2-arg closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until the entire collection has been used. Also known as foldLeft or reduce in functional parlance. Examples:
         assert 1*1*2*3*4 == [1,2,3,4].inject(1) { acc, val -> acc * val }
        
         assert 0+1+2+3+4 == [1,2,3,4].inject(0) { acc, val -> acc + val }
        
         assert 'The quick brown fox' ==
             ['quick', 'brown', 'fox'].inject('The') { acc, val -> acc + ' ' + val }
        
         assert 'bat' ==
             ['rat', 'bat', 'cat'].inject('zzz') { min, next -> next < min ? next : min }
        
         def max = { a, b -> [a, b].max() }
         def animals = ['bat', 'rat', 'cat']
         assert 'rat' == animals.inject('aaa', max)
         
        Visual representation of the last example above:
            initVal  animals[0]
               v        v
         max('aaa',   'bat')  =>  'bat'  animals[1]
                                    v       v
                              max('bat',  'rat')  =>  'rat'  animals[2]
                                                        v       v
                                                  max('rat',  'cat')  =>  'rat'
         
        Parameters:
        self - a Collection
        initialValue - some initial value
        closure - a closure
        Returns:
        the result of the last closure call
        Since:
        1.0
      • inject

        public static <T,​U extends T,​V extends T> T inject​(java.util.Map<?,​?> self,
                                                                       U initialValue,
                                                                       Closure<V> closure)
        Iterates through the given Map, passing in the initial value to the 2-arg Closure along with the first item (or 3-arg Closure along with the first key and value). The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until the entire collection has been used. Also known as foldLeft or reduce in functional parlance. Examples:
         def map = [a:1, b:2, c:3]
         assert map.inject([]) { list, k, v ->
           list + [k] * v
         } == ['a', 'b', 'b', 'c', 'c', 'c']
         
        Parameters:
        self - a Map
        initialValue - some initial value
        closure - a 2 or 3 arg Closure
        Returns:
        the result of the last closure call
        Since:
        1.8.1
      • inject

        public static <T,​U extends T,​V extends T> T inject​(java.util.Iterator self,
                                                                       U initialValue,
                                                                       Closure<V> closure)
        Iterates through the given Iterator, passing in the initial value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until the Iterator has been expired of values. Also known as foldLeft in functional parlance.
        Parameters:
        self - an Iterator
        initialValue - some initial value
        closure - a closure
        Returns:
        the result of the last closure call
        Since:
        1.5.0
        See Also:
        inject(Collection, Object, Closure)
      • inject

        public static <T,​V extends T> T inject​(java.lang.Object self,
                                                     Closure<V> closure)
        Iterates through the given Object, passing in the first value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until further iteration of the object is not possible. Also known as foldLeft in functional parlance.
        Parameters:
        self - an Object
        closure - a closure
        Returns:
        the result of the last closure call
        Throws:
        java.util.NoSuchElementException - if the collection is empty.
        Since:
        1.8.7
        See Also:
        inject(Collection, Object, Closure)
      • inject

        public static <T,​U extends T,​V extends T> T inject​(java.lang.Object self,
                                                                       U initialValue,
                                                                       Closure<V> closure)
        Iterates through the given Object, passing in the initial value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until further iteration of the object is not possible. Also known as foldLeft in functional parlance.
        Parameters:
        self - an Object
        initialValue - some initial value
        closure - a closure
        Returns:
        the result of the last closure call
        Since:
        1.5.0
        See Also:
        inject(Collection, Object, Closure)
      • inject

        public static <T,​V extends T> T inject​(java.lang.Object[] self,
                                                     Closure<V> closure)
        Iterates through the given array as with inject(Object[],initialValue,closure), but using the first element of the array as the initialValue, and then iterating the remaining elements of the array.
        Parameters:
        self - an Object[]
        closure - a closure
        Returns:
        the result of the last closure call
        Throws:
        java.util.NoSuchElementException - if the array is empty.
        Since:
        1.8.7
        See Also:
        inject(Object[], Object, Closure)
      • inject

        public static <T,​U extends T,​V extends T> T inject​(java.lang.Object[] self,
                                                                       U initialValue,
                                                                       Closure<V> closure)
        Iterates through the given array, passing in the initial value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until all elements of the array have been used. Also known as foldLeft in functional parlance.
        Parameters:
        self - an Object[]
        initialValue - some initial value
        closure - a closure
        Returns:
        the result of the last closure call
        Since:
        1.5.0
        See Also:
        inject(Collection, Object, Closure)
      • sum

        public static java.lang.Object sum​(java.util.Collection self)
        Sums the items in a collection. This is equivalent to invoking the "plus" method on all items in the collection.
        assert 1+2+3+4 == [1,2,3,4].sum()
        Parameters:
        self - Collection of values to add together
        Returns:
        The sum of all of the items
        Since:
        1.0
      • sum

        public static java.lang.Object sum​(java.lang.Object[] self)
        Sums the items in an array. This is equivalent to invoking the "plus" method on all items in the array.
        Parameters:
        self - The array of values to add together
        Returns:
        The sum of all of the items
        Since:
        1.7.1
        See Also:
        sum(java.util.Collection)
      • sum

        public static java.lang.Object sum​(java.util.Iterator<java.lang.Object> self)
        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.
        Parameters:
        self - an Iterator for the values to add together
        Returns:
        The sum of all of the items
        Since:
        1.5.5
      • sum

        public static java.lang.Object sum​(java.util.Collection self,
                                           java.lang.Object initialValue)
        Sums the items in a collection, adding the result to some initial value.
        assert 5+1+2+3+4 == [1,2,3,4].sum(5)
        Parameters:
        self - a collection of values to sum
        initialValue - the items in the collection will be summed to this initial value
        Returns:
        The sum of all of the items.
        Since:
        1.5.0
      • sum

        public static java.lang.Object sum​(java.lang.Object[] self,
                                           java.lang.Object initialValue)
        Sums the items in an array, adding the result to some initial value.
        Parameters:
        self - an array of values to sum
        initialValue - the items in the array will be summed to this initial value
        Returns:
        The sum of all of the items.
        Since:
        1.7.1
      • sum

        public static java.lang.Object sum​(java.util.Iterator<java.lang.Object> self,
                                           java.lang.Object initialValue)
        Sums the items from an Iterator, adding the result to some initial value. 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.
        Parameters:
        self - an Iterator for the values to add together
        initialValue - the items in the collection will be summed to this initial value
        Returns:
        The sum of all of the items
        Since:
        1.5.5
      • sum

        public static java.lang.Object sum​(java.util.Collection self,
                                           Closure closure)
        Sums the result of apply a closure to each item of a collection. coll.sum(closure) is equivalent to: coll.collect(closure).sum().
        assert 4+6+10+12 == [2,3,5,6].sum() { it * 2 }
        Parameters:
        self - a Collection
        closure - a single parameter closure that returns a numeric value.
        Returns:
        The sum of the values returned by applying the closure to each item of the collection.
        Since:
        1.0
      • sum

        public static java.lang.Object sum​(java.lang.Object[] self,
                                           Closure closure)
        Sums the result of apply a closure to each item of an array. array.sum(closure) is equivalent to: array.collect(closure).sum().
        Parameters:
        self - An array
        closure - a single parameter closure that returns a numeric value.
        Returns:
        The sum of the values returned by applying the closure to each item of the array.
        Since:
        1.7.1
      • sum

        public static java.lang.Object sum​(java.util.Iterator<java.lang.Object> self,
                                           Closure closure)
        Sums the result of apply a closure to each item returned from an iterator. iter.sum(closure) is equivalent to: iter.collect(closure).sum(). The iterator will become exhausted of elements after determining the sum value.
        Parameters:
        self - An Iterator
        closure - a single parameter closure that returns a numeric value.
        Returns:
        The sum of the values returned by applying the closure to each item from the Iterator.
        Since:
        1.7.1
      • sum

        public static java.lang.Object sum​(java.util.Collection self,
                                           java.lang.Object initialValue,
                                           Closure closure)
        Sums the result of applying a closure to each item of a collection to some initial value. coll.sum(initVal, closure) is equivalent to: coll.collect(closure).sum(initVal).
        assert 50+4+6+10+12 == [2,3,5,6].sum(50) { it * 2 }
        Parameters:
        self - a Collection
        closure - a single parameter closure that returns a numeric value.
        initialValue - the closure results will be summed to this initial value
        Returns:
        The sum of the values returned by applying the closure to each item of the collection.
        Since:
        1.5.0
      • sum

        public static java.lang.Object sum​(java.lang.Object[] self,
                                           java.lang.Object initialValue,
                                           Closure closure)
        Sums the result of applying a closure to each item of an array to some initial value. array.sum(initVal, closure) is equivalent to: array.collect(closure).sum(initVal).
        Parameters:
        self - an array
        closure - a single parameter closure that returns a numeric value.
        initialValue - the closure results will be summed to this initial value
        Returns:
        The sum of the values returned by applying the closure to each item of the array.
        Since:
        1.7.1
      • sum

        public static java.lang.Object sum​(java.util.Iterator<java.lang.Object> self,
                                           java.lang.Object initialValue,
                                           Closure closure)
        Sums the result of applying a closure to each item of an Iterator to some initial value. iter.sum(initVal, closure) is equivalent to: iter.collect(closure).sum(initVal). The iterator will become exhausted of elements after determining the sum value.
        Parameters:
        self - an Iterator
        closure - a single parameter closure that returns a numeric value.
        initialValue - the closure results will be summed to this initial value
        Returns:
        The sum of the values returned by applying the closure to each item from the Iterator.
        Since:
        1.7.1
      • join

        public static java.lang.String join​(java.util.Iterator<java.lang.Object> self,
                                            java.lang.String separator)
        Concatenates the toString() representation of each item from the iterator, with the given String as a separator between each item. The iterator will become exhausted of elements after determining the resulting conjoined value.
        Parameters:
        self - an Iterator of items
        separator - a String separator
        Returns:
        the joined String
        Since:
        1.5.5
      • join

        public static java.lang.String join​(java.util.Collection self,
                                            java.lang.String separator)
        Concatenates the toString() representation of each item in this collection, with the given String as a separator between each item.
        assert "1, 2, 3" == [1,2,3].join(", ")
        Parameters:
        self - a Collection of objects
        separator - a String separator
        Returns:
        the joined String
        Since:
        1.0
      • join

        public static java.lang.String join​(java.lang.Object[] self,
                                            java.lang.String separator)
        Concatenates the toString() representation of each items in this array, with the given String as a separator between each item.
        Parameters:
        self - an array of Object
        separator - a String separator
        Returns:
        the joined String
        Since:
        1.0
      • min

        public static <T> T min​(java.util.Collection<T> self)
        Adds min() method to Collection objects.
        assert 2 == [4,2,5].min()
        Parameters:
        self - a Collection
        Returns:
        the minimum value
        Since:
        1.0
        See Also:
        GroovyCollections.min(java.util.Collection)
      • min

        public static <T> T min​(java.util.Iterator<T> self)
        Adds min() method to Iterator objects. The iterator will become exhausted of elements after determining the minimum value.
        Parameters:
        self - an Iterator
        Returns:
        the minimum value
        Since:
        1.5.5
        See Also:
        min(java.util.Collection)
      • min

        public static <T> T min​(T[] self)
        Adds min() method to Object arrays.
        Parameters:
        self - an Object array
        Returns:
        the minimum value
        Since:
        1.5.5
        See Also:
        min(java.util.Collection)
      • min

        public static <T> T min​(java.util.Collection<T> self,
                                java.util.Comparator<T> comparator)
        Selects the minimum value found in the collection using the given comparator.
        assert "hi" == ["hello","hi","hey"].min( { a, b -> a.length() <=> b.length() } as Comparator )
        Parameters:
        self - a Collection
        comparator - a Comparator
        Returns:
        the minimum value
        Since:
        1.0
      • min

        public static <T> T min​(java.util.Iterator<T> self,
                                java.util.Comparator<T> comparator)
        Selects the minimum value found from the Iterator using the given comparator.
        Parameters:
        self - an Iterator
        comparator - a Comparator
        Returns:
        the minimum value
        Since:
        1.5.5
        See Also:
        min(java.util.Collection, java.util.Comparator)
      • min

        public static <T> T min​(T[] self,
                                java.util.Comparator<T> comparator)
        Selects the minimum value found from the Object array using the given comparator.
        Parameters:
        self - an Object array
        comparator - a Comparator
        Returns:
        the minimum value
        Since:
        1.5.5
        See Also:
        min(java.util.Collection, java.util.Comparator)
      • min

        public static <T> T min​(java.util.Collection<T> self,
                                Closure closure)
        Selects an item in the collection having the minimum value as determined by the supplied closure. If more than one item has the minimum value, an arbitrary choice is made between the items having the minimum value.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
         assert "hi" == ["hello","hi","hey"].min { it.length() }
         
         def lastDigit = { a, b -> a % 10 <=> b % 10 }
         assert [19, 55, 91].min(lastDigit) == 91
         
         def pets = ['dog', 'cat', 'anaconda']
         def shortestName = pets.min{ it.size() } // one of 'dog' or 'cat'
         assert shortestName.size() == 3
         
        Parameters:
        self - a Collection
        closure - a 1 or 2 arg Closure used to determine the correct ordering
        Returns:
        the minimum value
        Since:
        1.0
      • min

        public static <K,​V> java.util.Map.Entry<K,​V> min​(java.util.Map<K,​V> self,
                                                                     Closure closure)
        Selects an entry in the map having the minimum calculated value as determined by the supplied closure. If more than one entry has the minimum value, an arbitrary choice is made between the entries having the minimum value.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
         def zoo = [monkeys:6, lions:5, tigers:7]
         def leastCommonEntry = zoo.min{ it.value }
         assert leastCommonEntry.value == 5
         def mostCommonEntry = zoo.min{ a, b -> b.value <=> a.value } // double negative!
         assert mostCommonEntry.value == 7
         
        Edge case for multiple min values:
         def zoo = [monkeys:6, lions:5, tigers:7]
         def lastCharOfName = { e -> e.key[-1] }
         def ans = zoo.min(lastCharOfName) // some random entry
         assert lastCharOfName(ans) == 's'
         
        Parameters:
        self - a Map
        closure - a 1 or 2 arg Closure used to determine the correct ordering
        Returns:
        the Map.Entry having the minimum value as determined by the closure
        Since:
        1.7.6
      • max

        public static <K,​V> java.util.Map.Entry<K,​V> max​(java.util.Map<K,​V> self,
                                                                     Closure closure)
        Selects an entry in the map having the maximum calculated value as determined by the supplied closure. If more than one entry has the maximum value, an arbitrary choice is made between the entries having the maximum value.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison. An example:
         def zoo = [monkeys:6, lions:5, tigers:7]
         def mostCommonEntry = zoo.max{ it.value }
         assert mostCommonEntry.value == 7
         def leastCommonEntry = zoo.max{ a, b -> b.value <=> a.value } // double negative!
         assert leastCommonEntry.value == 5
         
        Edge case for multiple max values:
         def zoo = [monkeys:6, lions:5, tigers:7]
         def lengthOfNamePlusNumber = { e -> e.key.size() + e.value }
         def ans = zoo.max(lengthOfNamePlusNumber) // one of [monkeys:6, tigers:7]
         assert lengthOfNamePlusNumber(ans) == 13
         
        Parameters:
        self - a Map
        closure - a 1 or 2 arg Closure used to determine the correct ordering
        Returns:
        the Map.Entry having the maximum value as determined by the closure
        Since:
        1.7.6
      • min

        public static <T> T min​(java.util.Iterator<T> self,
                                Closure closure)
        Selects the minimum value found from the Iterator using the closure to determine the correct ordering. The iterator will become exhausted of elements after this operation.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
        Parameters:
        self - an Iterator
        closure - a Closure used to determine the correct ordering
        Returns:
        the minimum value
        Since:
        1.5.5
        See Also:
        min(java.util.Collection, groovy.lang.Closure)
      • min

        public static <T> T min​(T[] self,
                                Closure closure)
        Selects the minimum value found from the Object array using the closure to determine the correct ordering.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
        Parameters:
        self - an Object array
        closure - a Closure used to determine the correct ordering
        Returns:
        the minimum value
        Since:
        1.5.5
        See Also:
        min(java.util.Collection, groovy.lang.Closure)
      • max

        public static <T> T max​(java.util.Collection<T> self)
        Adds max() method to Collection objects.
        assert 5 == [2,3,1,5,4].max()
        Parameters:
        self - a Collection
        Returns:
        the maximum value
        Since:
        1.0
        See Also:
        GroovyCollections.max(java.util.Collection)
      • max

        public static <T> T max​(java.util.Iterator<T> self)
        Adds max() method to Iterator objects. The iterator will become exhausted of elements after determining the maximum value.
        Parameters:
        self - an Iterator
        Returns:
        the maximum value
        Since:
        1.5.5
        See Also:
        GroovyCollections.max(java.util.Collection)
      • max

        public static <T> T max​(T[] self)
        Adds max() method to Object arrays.
        Parameters:
        self - an Object array
        Returns:
        the maximum value
        Since:
        1.5.5
        See Also:
        max(java.util.Collection)
      • max

        public static <T> T max​(java.util.Collection<T> self,
                                Closure closure)
        Selects an item in the collection having the maximum value as determined by the supplied closure. If more than one item has the maximum value, an arbitrary choice is made between the items having the maximum value.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
        assert "hello" == ["hello","hi","hey"].max { it.length() }
        assert "hello" == ["hello","hi","hey"].max { a, b -> a.length() <=> b.length() }
         def pets = ['dog', 'elephant', 'anaconda']
         def longestName = pets.max{ it.size() } // one of 'elephant' or 'anaconda'
         assert longestName.size() == 8
         
        Parameters:
        self - a Collection
        closure - a 1 or 2 arg Closure used to determine the correct ordering
        Returns:
        the maximum value
        Since:
        1.0
      • max

        public static <T> T max​(java.util.Iterator<T> self,
                                Closure closure)
        Selects the maximum value found from the Iterator using the closure to determine the correct ordering. The iterator will become exhausted of elements after this operation.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
        Parameters:
        self - an Iterator
        closure - a Closure used to determine the correct ordering
        Returns:
        the maximum value
        Since:
        1.5.5
        See Also:
        max(java.util.Collection, groovy.lang.Closure)
      • max

        public static <T> T max​(T[] self,
                                Closure closure)
        Selects the maximum value found from the Object array using the closure to determine the correct ordering.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
        Parameters:
        self - an Object array
        closure - a Closure used to determine the correct ordering
        Returns:
        the maximum value
        Since:
        1.5.5
        See Also:
        max(java.util.Collection, groovy.lang.Closure)
      • max

        public static <T> T max​(java.util.Collection<T> self,
                                java.util.Comparator<T> comparator)
        Selects the maximum value found in the collection using the given comparator.
        assert "hello" == ["hello","hi","hey"].max( { a, b -> a.length() <=> b.length() } as Comparator )
        Parameters:
        self - a Collection
        comparator - a Comparator
        Returns:
        the maximum value
        Since:
        1.0
      • max

        public static <T> T max​(java.util.Iterator<T> self,
                                java.util.Comparator<T> comparator)
        Selects the maximum value found from the Iterator using the given comparator.
        Parameters:
        self - an Iterator
        comparator - a Comparator
        Returns:
        the maximum value
        Since:
        1.5.5
      • max

        public static <T> T max​(T[] self,
                                java.util.Comparator<T> comparator)
        Selects the maximum value found from the Object array using the given comparator.
        Parameters:
        self - an Object array
        comparator - a Comparator
        Returns:
        the maximum value
        Since:
        1.5.5
      • size

        public static int size​(java.util.Iterator self)
        Provide the standard Groovy size() method for Iterator. The iterator will become exhausted of elements after determining the size value.
        Parameters:
        self - an Iterator
        Returns:
        the length of the Iterator
        Since:
        1.5.5
      • size

        public static int size​(java.lang.String text)
        Provide the standard Groovy size() method for String.
        Parameters:
        text - a String
        Returns:
        the length of the String
        Since:
        1.0
      • size

        public static int size​(java.lang.CharSequence text)
        Provide the standard Groovy size() method for CharSequence.
        Parameters:
        text - a CharSequence
        Returns:
        the length of the CharSequence
        Since:
        1.8.2
      • size

        public static int size​(java.lang.StringBuffer buffer)
        Provide the standard Groovy size() method for StringBuffer.
        Parameters:
        buffer - a StringBuffer
        Returns:
        the length of the StringBuffer
        Since:
        1.0
      • size

        public static long size​(java.io.File self)
        Provide the standard Groovy size() method for File.
        Parameters:
        self - a file object
        Returns:
        the file's size (length)
        Since:
        1.5.0
      • size

        public static long size​(java.util.regex.Matcher self)
        Provide the standard Groovy size() method for Matcher.
        Parameters:
        self - a matcher object
        Returns:
        the matcher's size (count)
        Since:
        1.5.0
      • size

        public static int size​(java.lang.Object[] self)
        Provide the standard Groovy size() method for an array.
        Parameters:
        self - an Array of objects
        Returns:
        the size (length) of the Array
        Since:
        1.0
      • getAt

        public static java.lang.CharSequence getAt​(java.lang.CharSequence text,
                                                   int index)
        Support the subscript operator for CharSequence.
        Parameters:
        text - a CharSequence
        index - the index of the Character to get
        Returns:
        the Character at the given index
        Since:
        1.0
      • getAt

        public static java.lang.String getAt​(java.lang.String text,
                                             int index)
        Support the subscript operator for String.
        Parameters:
        text - a String
        index - the index of the Character to get
        Returns:
        the Character at the given index
        Since:
        1.0
      • getAt

        public static java.lang.CharSequence getAt​(java.lang.CharSequence text,
                                                   Range range)
        Support the range subscript operator for CharSequence
        Parameters:
        text - a CharSequence
        range - a Range
        Returns:
        the subsequence CharSequence
        Since:
        1.0
      • getAt

        public static java.lang.CharSequence getAt​(java.lang.CharSequence text,
                                                   IntRange range)
        Support the range subscript operator for CharSequence or StringBuffer with IntRange
        Parameters:
        text - a CharSequence
        range - an IntRange
        Returns:
        the subsequence CharSequence
        Since:
        1.0
      • getAt

        public static java.lang.CharSequence getAt​(java.lang.CharSequence text,
                                                   EmptyRange range)
        Support the range subscript operator for CharSequence or StringBuffer with EmptyRange
        Parameters:
        text - a CharSequence
        range - an EmptyRange
        Returns:
        the subsequence CharSequence
        Since:
        1.5.0
      • getAt

        public static java.lang.String getAt​(java.lang.String text,
                                             IntRange range)
        Support the range subscript operator for String with IntRange
        Parameters:
        text - a String
        range - an IntRange
        Returns:
        the resulting String
        Since:
        1.0
      • getAt

        public static java.lang.String getAt​(java.lang.String text,
                                             EmptyRange range)
        Support the range subscript operator for String with EmptyRange
        Parameters:
        text - a String
        range - an EmptyRange
        Returns:
        the resulting String
        Since:
        1.5.0
      • getAt

        public static java.lang.String getAt​(java.lang.String text,
                                             Range range)
        Support the range subscript operator for String
        Parameters:
        text - a String
        range - a Range
        Returns:
        a substring corresponding to the Range
        Since:
        1.0
      • reverse

        public static java.lang.String reverse​(java.lang.String self)
        Creates a new string which is the reverse (backwards) of this string
        Parameters:
        self - a String
        Returns:
        a new string with all the characters reversed.
        Since:
        1.0
        See Also:
        StringBuilder.reverse()
      • reverse

        public static java.lang.CharSequence reverse​(java.lang.CharSequence self)
        Creates a new CharSequence which is the reverse (backwards) of this string
        Parameters:
        self - a CharSequence
        Returns:
        a new CharSequence with all the characters reversed.
        Since:
        1.8.2
        See Also:
        reverse(String)
      • stripMargin

        public static java.lang.String stripMargin​(java.lang.String self)

        Strip leading whitespace/control characters followed by '|' from every line in a String.

         assert 'ABC\n123\n456' == '''ABC
                                     |123
                                     |456'''.stripMargin()
         
        Parameters:
        self - The String to strip the margin from
        Returns:
        the stripped String
        Since:
        1.7.3
        See Also:
        stripMargin(String, char)
      • stripMargin

        public static java.lang.CharSequence stripMargin​(java.lang.CharSequence self)

        Strip leading whitespace/control characters followed by '|' from every line in a CharSequence.

        Parameters:
        self - The CharSequence to strip the margin from
        Returns:
        the stripped CharSequence
        Since:
        1.8.2
        See Also:
        stripMargin(CharSequence, char)
      • stripMargin

        public static java.lang.String stripMargin​(java.lang.String self,
                                                   java.lang.String marginChar)

        Strip leading whitespace/control characters followed by marginChar from every line in a String.

        Parameters:
        self - The String to strip the margin from
        marginChar - Any character that serves as margin delimiter
        Returns:
        the stripped String
        Since:
        1.7.3
        See Also:
        stripMargin(String, char)
      • stripMargin

        public static java.lang.String stripMargin​(java.lang.CharSequence self,
                                                   java.lang.CharSequence marginChar)

        Strip leading whitespace/control characters followed by marginChar from every line in a CharSequence.

        Parameters:
        self - The CharSequence to strip the margin from
        marginChar - Any character that serves as margin delimiter
        Returns:
        the stripped CharSequence
        Since:
        1.8.2
        See Also:
        stripMargin(String, String)
      • stripMargin

        public static java.lang.String stripMargin​(java.lang.String self,
                                                   char marginChar)

        Strip leading whitespace/control characters followed by marginChar from every line in a String.

         assert 'ABC\n123\n456' == '''ABC
                                     *123
                                     *456'''.stripMargin('*')
         
        Parameters:
        self - The String to strip the margin from
        marginChar - Any character that serves as margin delimiter
        Returns:
        the stripped String
        Since:
        1.7.3
      • stripMargin

        public static java.lang.CharSequence stripMargin​(java.lang.CharSequence self,
                                                         char marginChar)

        Strip leading whitespace/control characters followed by marginChar from every line in a String.

        Parameters:
        self - The CharSequence to strip the margin from
        marginChar - Any character that serves as margin delimiter
        Returns:
        the stripped CharSequence
        Since:
        1.8.2
        See Also:
        stripMargin(String, char)
      • stripIndent

        public static java.lang.String stripIndent​(java.lang.String self)

        Strip leading spaces from every line in a String. The line with the least number of leading spaces determines the number to remove. Lines only containing whitespace are ignored when calculating the number of leading spaces to strip.

         assert '  A\n B\nC' == '   A\n  B\n C'.stripIndent()
         
        Parameters:
        self - The String to strip the leading spaces from
        Returns:
        the stripped String
        Since:
        1.7.3
        See Also:
        stripIndent(String, int)
      • stripIndent

        public static java.lang.CharSequence stripIndent​(java.lang.CharSequence self)

        Strip leading spaces from every line in a CharSequence. The line with the least number of leading spaces determines the number to remove. Lines only containing whitespace are ignored when calculating the number of leading spaces to strip.

        Parameters:
        self - The CharSequence to strip the leading spaces from
        Returns:
        the stripped CharSequence
        Since:
        1.8.2
        See Also:
        stripIndent(String)
      • isAllWhitespace

        public static boolean isAllWhitespace​(java.lang.String self)
        True if a String only contains whitespace characters.
        Parameters:
        self - The String to check the characters in
        Returns:
        true If all characters are whitespace characters
        Since:
        1.6
        See Also:
        Character.isWhitespace(char)
      • isAllWhitespace

        public static boolean isAllWhitespace​(java.lang.CharSequence self)
        True if a CharSequence only contains whitespace characters.
        Parameters:
        self - The CharSequence to check the characters in
        Returns:
        true If all characters are whitespace characters
        Since:
        1.8.2
        See Also:
        isAllWhitespace(String)
      • stripIndent

        public static java.lang.String stripIndent​(java.lang.String self,
                                                   int numChars)

        Strip numChar leading characters from every line in a String.

         assert 'DEF\n456' == '''ABCDEF\n123456'''.stripIndent(3)
         
        Parameters:
        self - The String to strip the characters from
        numChars - The number of characters to strip
        Returns:
        the stripped String
        Since:
        1.7.3
      • stripIndent

        public static java.lang.CharSequence stripIndent​(java.lang.CharSequence self,
                                                         int numChars)

        Strip numChar leading characters from every line in a CharSequence.

        Parameters:
        self - The CharSequence to strip the characters from
        numChars - The number of characters to strip
        Returns:
        the stripped CharSequence
        Since:
        1.8.2
      • toURL

        public static java.net.URL toURL​(java.lang.String self)
                                  throws java.net.MalformedURLException
        Transforms a String representing a URL into a URL object.
        Parameters:
        self - the String representing a URL
        Returns:
        a URL
        Throws:
        java.net.MalformedURLException - is thrown if the URL is not well formed.
        Since:
        1.0
      • toURL

        public static java.net.URL toURL​(java.lang.CharSequence self)
                                  throws java.net.MalformedURLException
        Transforms a CharSequence representing a URL into a URL object.
        Parameters:
        self - the CharSequence representing a URL
        Returns:
        a URL
        Throws:
        java.net.MalformedURLException - is thrown if the URL is not well formed.
        Since:
        1.8.2
      • toURI

        public static java.net.URI toURI​(java.lang.String self)
                                  throws java.net.URISyntaxException
        Transforms a String representing a URI into a URI object.
        Parameters:
        self - the String representing a URI
        Returns:
        a URI
        Throws:
        java.net.URISyntaxException - is thrown if the URI is not well formed.
        Since:
        1.0
      • toURI

        public static java.net.URI toURI​(java.lang.CharSequence self)
                                  throws java.net.URISyntaxException
        Transforms a CharSequence representing a URI into a URI object.
        Parameters:
        self - the CharSequence representing a URI
        Returns:
        a URI
        Throws:
        java.net.URISyntaxException - is thrown if the URI is not well formed.
        Since:
        1.8.2
      • bitwiseNegate

        public static java.util.regex.Pattern bitwiseNegate​(java.lang.String self)
        Turns a String into a regular expression Pattern
        Parameters:
        self - a String to convert into a regular expression
        Returns:
        the regular expression pattern
        Since:
        1.5.0
      • bitwiseNegate

        public static java.util.regex.Pattern bitwiseNegate​(java.lang.CharSequence self)
        Turns a CharSequence into a regular expression Pattern
        Parameters:
        self - a String to convert into a regular expression
        Returns:
        the regular expression pattern
        Since:
        1.8.2
      • replaceFirst

        public static java.lang.String replaceFirst​(java.lang.String self,
                                                    java.util.regex.Pattern pattern,
                                                    java.lang.String replacement)
        Replaces the first substring of a String that matches the given compiled regular expression with the given replacement.

        Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string; see Matcher.replaceFirst(java.lang.String). Use Matcher.quoteReplacement(java.lang.String) to suppress the special meaning of these characters, if desired.

         assert "foo".replaceFirst('o', 'X') == 'fXo'
         
        Parameters:
        self - the string that is to be matched
        pattern - the regex Pattern to which the string of interest is to be matched
        replacement - the string to be substituted for the first match
        Returns:
        The resulting String
        Since:
        1.6.1
        See Also:
        String.replaceFirst(java.lang.String, java.lang.String)
      • replaceFirst

        public static java.lang.CharSequence replaceFirst​(java.lang.CharSequence self,
                                                          java.util.regex.Pattern pattern,
                                                          java.lang.CharSequence replacement)
        Replaces the first substring of a CharSequence that matches the given compiled regular expression with the given replacement.
        Parameters:
        self - the CharSequence that is to be matched
        pattern - the regex Pattern to which the CharSequence of interest is to be matched
        replacement - the CharSequence to be substituted for the first match
        Returns:
        The resulting CharSequence
        Since:
        1.8.2
        See Also:
        replaceFirst(String, Pattern, String)
      • replaceAll

        public static java.lang.String replaceAll​(java.lang.String self,
                                                  java.util.regex.Pattern pattern,
                                                  java.lang.String replacement)
        Replaces all substrings of a String that match the given compiled regular expression with the given replacement.

        Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string; see Matcher.replaceAll(java.lang.String). Use Matcher.quoteReplacement(java.lang.String) to suppress the special meaning of these characters, if desired.

         assert "foo".replaceAll('o', 'X') == 'fXX'
         
        Parameters:
        self - the string that is to be matched
        pattern - the regex Pattern to which the string of interest is to be matched
        replacement - the string to be substituted for the first match
        Returns:
        The resulting String
        Since:
        1.6.1
        See Also:
        String.replaceAll(java.lang.String, java.lang.String)
      • replaceAll

        public static java.lang.CharSequence replaceAll​(java.lang.CharSequence self,
                                                        java.util.regex.Pattern pattern,
                                                        java.lang.CharSequence replacement)
        Replaces all substrings of a CharSequence that match the given compiled regular expression with the given replacement.
        Parameters:
        self - the CharSequence that is to be matched
        pattern - the regex Pattern to which the CharSequence of interest is to be matched
        replacement - the CharSequence to be substituted for the first match
        Returns:
        The resulting CharSequence
        Since:
        1.8.2
        See Also:
        replaceAll(String, Pattern, String)
      • tr

        public static java.lang.String tr​(java.lang.String self,
                                          java.lang.String sourceSet,
                                          java.lang.String replacementSet)
                                   throws java.lang.ClassNotFoundException
        Translates a string by replacing characters from the sourceSet with characters from replacementSet. If the first character from sourceSet appears in the string, it will be replaced with the first character from replacementSet. If the second character from sourceSet appears in the string, it will be replaced with the second character from replacementSet. and so on for all provided replacement characters.

        Here is an example which converts the vowels in a word from lower to uppercase:

         assert 'hello'.tr('aeiou', 'AEIOU') == 'hEllO'
         
        A character range using regex-style syntax can also be used, e.g. here is an example which converts a word from lower to uppercase:
         assert 'hello'.tr('a-z', 'A-Z') == 'HELLO'
         
        Hyphens at the start or end of sourceSet or replacementSet are treated as normal hyphens and are not considered to be part of a range specification. Similarly, a hyphen immediately after an earlier range is treated as a normal hyphen. So, '-x', 'x-' have no ranges while 'a-c-e' has the range 'a-c' plus the '-' character plus the 'e' character.

        Unlike the unix tr command, Groovy's tr command supports reverse ranges, e.g.:

         assert 'hello'.tr('z-a', 'Z-A') == 'HELLO'
         
        If replacementSet is smaller than sourceSet, then the last character from replacementSet is used as the replacement for all remaining source characters as shown here:
         assert 'Hello World!'.tr('a-z', 'A') == 'HAAAA WAAAA!'
         
        If sourceSet contains repeated characters, the last specified replacement is used as shown here:
         assert 'Hello World!'.tr('lloo', '1234') == 'He224 W4r2d!'
         
        The functionality provided by tr can be achieved using regular expressions but tr provides a much more compact notation and efficient implementation for certain scenarios.
        Parameters:
        self - the string that is to be translated
        sourceSet - the set of characters to translate from
        replacementSet - the set of replacement characters
        Returns:
        The resulting translated String
        Throws:
        java.lang.ClassNotFoundException
        Since:
        1.7.3
        See Also:
        StringUtil.tr(String, String, String)
      • tr

        public static java.lang.CharSequence tr​(java.lang.CharSequence self,
                                                java.lang.CharSequence sourceSet,
                                                java.lang.CharSequence replacementSet)
                                         throws java.lang.ClassNotFoundException
        Translates a string by replacing characters from the sourceSet with characters from replacementSet.
        Parameters:
        self - the CharSequence that is to be translated
        sourceSet - the set of characters to translate from
        replacementSet - the set of replacement characters
        Returns:
        The resulting translated CharSequence
        Throws:
        java.lang.ClassNotFoundException
        Since:
        1.8.2
        See Also:
        tr(String, String, String)
      • matches

        public static boolean matches​(java.lang.String self,
                                      java.util.regex.Pattern pattern)
        Tells whether or not self matches the given compiled regular expression Pattern.
        Parameters:
        self - the string that is to be matched
        pattern - the regex Pattern to which the string of interest is to be matched
        Returns:
        true if the string matches
        Since:
        1.6.1
        See Also:
        String.matches(java.lang.String)
      • matches

        public static boolean matches​(java.lang.CharSequence self,
                                      java.util.regex.Pattern pattern)
        Tells whether or not a CharSequence matches the given compiled regular expression Pattern.
        Parameters:
        self - the CharSequence that is to be matched
        pattern - the regex Pattern to which the string of interest is to be matched
        Returns:
        true if the CharSequence matches
        Since:
        1.8.2
        See Also:
        String.matches(java.lang.String)
      • find

        public static java.lang.String find​(java.lang.String self,
                                            java.lang.String regex)
        Finds the first occurrence of a regular expression String within a String. If the regex doesn't match, null will be returned.

        For example, if the regex doesn't match the result is null:

             assert null == "New York, NY".find(/\d{5}/)
         

        If it does match, we get the matching string back:

              assert "10292" == "New York, NY 10292-0098".find(/\d{5}/)
         

        If we have capture groups in our expression, we still get back the full match

              assert "10292-0098" == "New York, NY 10292-0098".find(/(\d{5})-?(\d{4})/)
         

        Parameters:
        self - a String
        regex - the capturing regex
        Returns:
        a String containing the matched portion, or null if the regex doesn't match
        Since:
        1.6.1
      • find

        public static java.lang.CharSequence find​(java.lang.CharSequence self,
                                                  java.lang.CharSequence regex)
        Finds the first occurrence of a regular expression CharSequence within a CharSequence.
        Parameters:
        self - a CharSequence
        regex - the capturing regex
        Returns:
        a CharSequence containing the matched portion, or null if the regex doesn't match
        Since:
        1.8.2
        See Also:
        find(String, Pattern)
      • find

        public static java.lang.String find​(java.lang.String self,
                                            java.util.regex.Pattern pattern)
        Finds the first occurrence of a compiled regular expression Pattern within a String. If the pattern doesn't match, null will be returned.

        For example, if the pattern doesn't match the result is null:

             assert null == "New York, NY".find(~/\d{5}/)
         

        If it does match, we get the matching string back:

              assert "10292" == "New York, NY 10292-0098".find(~/\d{5}/)
         

        If we have capture groups in our expression, the groups are ignored and we get back the full match:

              assert "10292-0098" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/)
         
        If you need to work with capture groups, then use the closure version of this method or use Groovy's matcher operators or use eachMatch.

        Parameters:
        self - a String
        pattern - the compiled regex Pattern
        Returns:
        a String containing the matched portion, or null if the regex pattern doesn't match
        Since:
        1.6.1
      • find

        public static java.lang.CharSequence find​(java.lang.CharSequence self,
                                                  java.util.regex.Pattern pattern)
        Finds the first occurrence of a compiled regular expression Pattern within a CharSequence.
        Parameters:
        self - a CharSequence
        pattern - the compiled regex Pattern
        Returns:
        a CharSequence containing the matched portion, or null if the regex pattern doesn't match
        Since:
        1.8.2
        See Also:
        find(String, Pattern)
      • find

        public static java.lang.String find​(java.lang.String self,
                                            java.lang.String regex,
                                            Closure closure)
        Returns the result of calling a closure with the first occurrence of a regular expression found within a String. If the regex doesn't match, the closure will not be called and find will return null.

        For example, if the regex doesn't match, the result is null:

             assert null == "New York, NY".find(~/\d{5}/) { match -> return "-$match-"}
         

        If it does match and we don't have any capture groups in our regex, there is a single parameter on the closure that the match gets passed to:

              assert "-10292-" == "New York, NY 10292-0098".find(~/\d{5}/) { match -> return "-$match-"}
         

        If we have capture groups in our expression, our closure has one parameter for the match, followed by one for each of the capture groups:

              assert "10292" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour ->
                  assert match == "10292-0098"
                  assert zip == "10292"
                  assert plusFour == "0098"
                  return zip
              }
         

        If we have capture groups in our expression, and our closure has one parameter, the closure will be passed an array with the first element corresponding to the whole match, followed by an element for each of the capture groups:

              assert "10292" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour ->
                  assert array[0] == "10292-0098"
                  assert array[1] == "10292"
                  assert array[2] == "0098"
                  return array[1]
              }
         

        If a capture group is optional, and doesn't match, then the corresponding value for that capture group passed to the closure will be null as illustrated here:

              assert "2339999" == "adsf 233-9999 adsf".find(~/(\d{3})?-?(\d{3})-(\d{4})/) { match, areaCode, exchange, stationNumber ->
                  assert "233-9999" == match
                  assert null == areaCode
                  assert "233" == exchange
                  assert "9999" == stationNumber
                  return "$exchange$stationNumber"
              }
         

        Parameters:
        self - a String
        regex - the capturing regex string
        closure - the closure that will be passed the full match, plus each of the capturing groups
        Returns:
        a String containing the result of the closure, or null if the regex pattern doesn't match
        Since:
        1.6.1
      • find

        public static java.lang.CharSequence find​(java.lang.CharSequence self,
                                                  java.lang.CharSequence regex,
                                                  Closure closure)
        Returns the result of calling a closure with the first occurrence of a regular expression found within a CharSequence. If the regex doesn't match, the closure will not be called and find will return null.
        Parameters:
        self - a CharSequence
        regex - the capturing regex CharSequence
        closure - the closure that will be passed the full match, plus each of the capturing groups
        Returns:
        a CharSequence containing the result of the closure, or null if the regex pattern doesn't match
        Since:
        1.8.2
        See Also:
        find(String, Pattern, Closure)
      • find

        public static java.lang.String find​(java.lang.String self,
                                            java.util.regex.Pattern pattern,
                                            Closure closure)
        Returns the result of calling a closure with the first occurrence of a compiled regular expression found within a String. If the regex doesn't match, the closure will not be called and find will return null.

        For example, if the pattern doesn't match, the result is null:

             assert null == "New York, NY".find(~/\d{5}/) { match -> return "-$match-"}
         

        If it does match and we don't have any capture groups in our regex, there is a single parameter on the closure that the match gets passed to:

              assert "-10292-" == "New York, NY 10292-0098".find(~/\d{5}/) { match -> return "-$match-"}
         

        If we have capture groups in our expression, our closure has one parameter for the match, followed by one for each of the capture groups:

              assert "10292" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour ->
                  assert match == "10292-0098"
                  assert zip == "10292"
                  assert plusFour == "0098"
                  return zip
              }
         

        If we have capture groups in our expression, and our closure has one parameter, the closure will be passed an array with the first element corresponding to the whole match, followed by an element for each of the capture groups:

              assert "10292" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour ->
                  assert array[0] == "10292-0098"
                  assert array[1] == "10292"
                  assert array[2] == "0098"
                  return array[1]
              }
         

        If a capture group is optional, and doesn't match, then the corresponding value for that capture group passed to the closure will be null as illustrated here:

              assert "2339999" == "adsf 233-9999 adsf".find(~/(\d{3})?-?(\d{3})-(\d{4})/) { match, areaCode, exchange, stationNumber ->
                  assert "233-9999" == match
                  assert null == areaCode
                  assert "233" == exchange
                  assert "9999" == stationNumber
                  return "$exchange$stationNumber"
              }
         

        Parameters:
        self - a String
        pattern - the compiled regex Pattern
        closure - the closure that will be passed the full match, plus each of the capturing groups
        Returns:
        a String containing the result of the closure, or null if the regex pattern doesn't match
        Since:
        1.6.1
      • find

        public static java.lang.CharSequence find​(java.lang.CharSequence self,
                                                  java.util.regex.Pattern pattern,
                                                  Closure closure)
      • findAll

        public static java.util.List<java.lang.String> findAll​(java.lang.String self,
                                                               java.lang.String regex)
        Returns a (possibly empty) list of all occurrences of a regular expression (in String format) found within a String.

        For example, if the regex doesn't match, it returns an empty list:

         assert [] == "foo".findAll(/(\w*) Fish/)
         

        Any regular expression matches are returned in a list, and all regex capture groupings are ignored, only the full match is returned:

         def expected = ["One Fish", "Two Fish", "Red Fish", "Blue Fish"]
         assert expected == "One Fish, Two Fish, Red Fish, Blue Fish".findAll(/(\w*) Fish/)
         
        If you need to work with capture groups, then use the closure version of this method or use Groovy's matcher operators or use eachMatch.

        Parameters:
        self - a String
        regex - the capturing regex String
        Returns:
        a List containing all full matches of the regex within the string, an empty list will be returned if there are no matches
        Since:
        1.6.1
      • findAll

        public static java.util.List<java.lang.CharSequence> findAll​(java.lang.CharSequence self,
                                                                     java.lang.CharSequence regex)
        Returns a (possibly empty) list of all occurrences of a regular expression (in CharSequence format) found within a CharSequence.
        Parameters:
        self - a CharSequence
        regex - the capturing regex CharSequence
        Returns:
        a List containing all full matches of the regex within the CharSequence, an empty list will be returned if there are no matches
        Since:
        1.8.2
        See Also:
        findAll(String, String)
      • findAll

        public static java.util.List<java.lang.String> findAll​(java.lang.String self,
                                                               java.util.regex.Pattern pattern)
        Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a String.

        For example, if the pattern doesn't match, it returns an empty list:

         assert [] == "foo".findAll(~/(\w*) Fish/)
         

        Any regular expression matches are returned in a list, and all regex capture groupings are ignored, only the full match is returned:

         def expected = ["One Fish", "Two Fish", "Red Fish", "Blue Fish"]
         assert expected == "One Fish, Two Fish, Red Fish, Blue Fish".findAll(~/(\w*) Fish/)
         
        Parameters:
        self - a String
        pattern - the compiled regex Pattern
        Returns:
        a List containing all full matches of the Pattern within the string, an empty list will be returned if there are no matches
        Since:
        1.6.1
      • findAll

        public static java.util.List<java.lang.CharSequence> findAll​(java.lang.CharSequence self,
                                                                     java.util.regex.Pattern pattern)
        Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a CharSequence.
        Parameters:
        self - a CharSequence
        pattern - the compiled regex Pattern
        Returns:
        a List containing all full matches of the Pattern within the CharSequence, an empty list will be returned if there are no matches
        Since:
        1.8.2
        See Also:
        findAll(String, Pattern)
      • findAll

        public static <T> java.util.List<T> findAll​(java.lang.String self,
                                                    java.lang.String regex,
                                                    Closure<T> closure)
        Finds all occurrences of a regular expression string within a String. Any matches are passed to the specified closure. The closure is expected to have the full match in the first parameter. If there are any capture groups, they will be placed in subsequent parameters.

        If there are no matches, the closure will not be called, and an empty List will be returned.

        For example, if the regex doesn't match, it returns an empty list:

         assert [] == "foo".findAll(/(\w*) Fish/) { match, firstWord -> return firstWord }
         

        Any regular expression matches are passed to the closure, if there are no capture groups, there will be one parameter for the match:

         assert ["couldn't", "wouldn't"] == "I could not, would not, with a fox.".findAll(/.ould/) { match -> "${match}n't"}
         

        If there are capture groups, the first parameter will be the match followed by one parameter for each capture group:

         def orig = "There's a Wocket in my Pocket"
         assert ["W > Wocket", "P > Pocket"] == orig.findAll(/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" }
         
        Parameters:
        self - a String
        regex - the capturing regex String
        closure - will be passed the full match plus each of the capturing groups
        Returns:
        a List containing all full matches of the regex within the string, an empty list will be returned if there are no matches
        Since:
        1.6.1
      • findAll

        public static <T> java.util.List<T> findAll​(java.lang.CharSequence self,
                                                    java.lang.CharSequence regex,
                                                    Closure<T> closure)
        Finds all occurrences of a capturing regular expression CharSequence within a CharSequence.
        Parameters:
        self - a CharSequence
        regex - the capturing regex CharSequence
        closure - will be passed the full match plus each of the capturing groups
        Returns:
        a List containing all full matches of the regex within the CharSequence, an empty list will be returned if there are no matches
        Since:
        1.8.2
        See Also:
        findAll(String, String, Closure)
      • findAll

        public static <T> java.util.List<T> findAll​(java.lang.String self,
                                                    java.util.regex.Pattern pattern,
                                                    Closure<T> closure)
        Finds all occurrences of a compiled regular expression Pattern within a String. Any matches are passed to the specified closure. The closure is expected to have the full match in the first parameter. If there are any capture groups, they will be placed in subsequent parameters.

        If there are no matches, the closure will not be called, and an empty List will be returned.

        For example, if the pattern doesn't match, it returns an empty list:

         assert [] == "foo".findAll(~/(\w*) Fish/) { match, firstWord -> return firstWord }
         

        Any regular expression matches are passed to the closure, if there are no capture groups, there will be one parameter for the match:

         assert ["couldn't", "wouldn't"] == "I could not, would not, with a fox.".findAll(~/.ould/) { match -> "${match}n't"}
         

        If there are capture groups, the first parameter will be the match followed by one parameter for each capture group:

         def orig = "There's a Wocket in my Pocket"
         assert ["W > Wocket", "P > Pocket"] == orig.findAll(~/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" }
         
        Parameters:
        self - a String
        pattern - the compiled regex Pattern
        closure - will be passed the full match plus each of the capturing groups
        Returns:
        a List containing all full matches of the regex Pattern within the string, an empty list will be returned if there are no matches
        Since:
        1.6.1
      • findAll

        public static <T> java.util.List<T> findAll​(java.lang.CharSequence self,
                                                    java.util.regex.Pattern pattern,
                                                    Closure<T> closure)
        Finds all occurrences of a compiled regular expression Pattern within a CharSequence.
        Parameters:
        self - a CharSequence
        pattern - the compiled regex Pattern
        closure - will be passed the full match plus each of the capturing groups
        Returns:
        a List containing all full matches of the regex Pattern within the CharSequence, an empty list will be returned if there are no matches
        Since:
        1.8.2
        See Also:
        findAll(String, Pattern, Closure)
      • replaceAll

        public static java.lang.String replaceAll​(java.lang.String self,
                                                  java.lang.String regex,
                                                  Closure closure)
        Replaces all occurrences of a captured group by the result of a closure on that text.

        For examples,

             assert "hellO wOrld" == "hello world".replaceAll("(o)") { it[0].toUpperCase() }
         

        assert "FOOBAR-FOOBAR-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() })

        Here, it[0] is the global string of the matched group it[1] is the first string in the matched group it[2] is the second string in the matched group

        assert "FOO-FOO-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() })

        Here, x is the global string of the matched group y is the first string in the matched group z is the second string in the matched group

        Note that unlike String.replaceAll(String regex, String replacement), where the replacement string treats '$' and '\' specially (for group substitution), the result of the closure is converted to a string and that value is used literally for the replacement.

        Parameters:
        self - a String
        regex - the capturing regex
        closure - the closure to apply on each captured group
        Returns:
        a String with replaced content
        Throws:
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.0
        See Also:
        Matcher.quoteReplacement(java.lang.String), replaceAll(String, Pattern, Closure)
      • replaceAll

        public static java.lang.CharSequence replaceAll​(java.lang.CharSequence self,
                                                        java.lang.CharSequence regex,
                                                        Closure closure)
        Replaces all occurrences of a captured group by the result of a closure on that text.
        Parameters:
        self - a CharSequence
        regex - the capturing regex
        closure - the closure to apply on each captured group
        Returns:
        a CharSequence with replaced content
        Throws:
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.8.2
        See Also:
        replaceAll(String, Pattern, Closure)
      • replaceAll

        public static java.lang.CharSequence replaceAll​(java.lang.CharSequence self,
                                                        java.lang.CharSequence regex,
                                                        java.lang.CharSequence replacement)
        Replaces each substring of this CharSequence that matches the given regular expression with the given replacement.
        Parameters:
        self - a CharSequence
        regex - the capturing regex
        replacement - the capturing regex
        Returns:
        a CharSequence with replaced content
        Throws:
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.8.2
        See Also:
        String.replaceAll(String, String)
      • replaceFirst

        public static java.lang.String replaceFirst​(java.lang.String self,
                                                    java.lang.String regex,
                                                    Closure closure)
        Replaces the first occurrence of a captured group by the result of a closure call on that text.

        For example (with some replaceAll variants thrown in for comparison purposes),

         assert "hellO world" == "hello world".replaceFirst("(o)") { it[0].toUpperCase() } // first match
         assert "hellO wOrld" == "hello world".replaceAll("(o)") { it[0].toUpperCase() }   // all matches
         

        assert '1-FISH, two fish' == "one fish, two fish".replaceFirst(/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() } assert '1-FISH, 2-FISH' == "one fish, two fish".replaceAll(/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() }

        Parameters:
        self - a String
        regex - the capturing regex
        closure - the closure to apply on the first captured group
        Returns:
        a String with replaced content
        Throws:
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.7.7
        See Also:
        Matcher.quoteReplacement(java.lang.String), replaceFirst(String, Pattern, Closure)
      • replaceFirst

        public static java.lang.String replaceFirst​(java.lang.CharSequence self,
                                                    java.lang.CharSequence regex,
                                                    java.lang.CharSequence replacement)
        Replaces the first substring of this CharSequence that matches the given regular expression with the given replacement.
        Parameters:
        self - a CharSequence
        regex - the capturing regex
        replacement - the capturing regex
        Returns:
        a CharSequence with replaced content
        Throws:
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.8.2
        See Also:
        String.replaceAll(String, String)
      • replaceFirst

        public static java.lang.String replaceFirst​(java.lang.CharSequence self,
                                                    java.lang.CharSequence regex,
                                                    Closure closure)
        Replaces the first occurrence of a captured group by the result of a closure call on that text.
        Parameters:
        self - a CharSequence
        regex - the capturing regex
        closure - the closure to apply on the first captured group
        Returns:
        a CharSequence with replaced content
        Throws:
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.8.2
        See Also:
        replaceFirst(String, String, Closure)
      • replaceAll

        public static java.lang.String replaceAll​(java.lang.String self,
                                                  java.util.regex.Pattern pattern,
                                                  Closure closure)
        Replaces all occurrences of a captured group by the result of a closure call on that text.

        For examples,

             assert "hellO wOrld" == "hello world".replaceAll(~"(o)") { it[0].toUpperCase() }
         

        assert "FOOBAR-FOOBAR-" == "foobar-FooBar-".replaceAll(~"(([fF][oO]{2})[bB]ar)", { it[0].toUpperCase() })

        Here, it[0] is the global string of the matched group it[1] is the first string in the matched group it[2] is the second string in the matched group

        assert "FOOBAR-FOOBAR-" == "foobar-FooBar-".replaceAll(~"(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() })

        Here, it[0] is the global string of the matched group it[1] is the first string in the matched group it[2] is the second string in the matched group

        assert "FOO-FOO-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() })

        Here, x is the global string of the matched group y is the first string in the matched group z is the second string in the matched group

        Note that unlike String.replaceAll(String regex, String replacement), where the replacement string treats '$' and '\' specially (for group substitution), the result of the closure is converted to a string and that value is used literally for the replacement.

        Parameters:
        self - a String
        pattern - the capturing regex Pattern
        closure - the closure to apply on each captured group
        Returns:
        a String with replaced content
        Since:
        1.6.8
        See Also:
        Matcher.quoteReplacement(java.lang.String)
      • replaceAll

        public static java.lang.String replaceAll​(java.lang.CharSequence self,
                                                  java.util.regex.Pattern pattern,
                                                  Closure closure)
        Replaces all occurrences of a captured group by the result of a closure call on that text.
        Parameters:
        self - a CharSequence
        pattern - the capturing regex Pattern
        closure - the closure to apply on each captured group
        Returns:
        a CharSequence with replaced content
        Since:
        1.8.2
        See Also:
        replaceAll(String, Pattern, Closure)
      • replaceFirst

        public static java.lang.String replaceFirst​(java.lang.String self,
                                                    java.util.regex.Pattern pattern,
                                                    Closure closure)
        Replaces the first occurrence of a captured group by the result of a closure call on that text.

        For example (with some replaceAll variants thrown in for comparison purposes),

         assert "hellO world" == "hello world".replaceFirst(~"(o)") { it[0].toUpperCase() } // first match
         assert "hellO wOrld" == "hello world".replaceAll(~"(o)") { it[0].toUpperCase() }   // all matches
         

        assert '1-FISH, two fish' == "one fish, two fish".replaceFirst(~/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() } assert '1-FISH, 2-FISH' == "one fish, two fish".replaceAll(~/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() }

        Parameters:
        self - a String
        pattern - the capturing regex Pattern
        closure - the closure to apply on the first captured group
        Returns:
        a String with replaced content
        Since:
        1.7.7
        See Also:
        replaceAll(String, Pattern, Closure)
      • replaceFirst

        public static java.lang.String replaceFirst​(java.lang.CharSequence self,
                                                    java.util.regex.Pattern pattern,
                                                    Closure closure)
        Replaces the first occurrence of a captured group by the result of a closure call on that text.
        Parameters:
        self - a CharSequence
        pattern - the capturing regex Pattern
        closure - the closure to apply on the first captured group
        Returns:
        a CharSequence with replaced content
        Since:
        1.8.2
        See Also:
        replaceFirst(String, Pattern, Closure)
      • padLeft

        public static java.lang.String padLeft​(java.lang.String self,
                                               java.lang.Number numberOfChars,
                                               java.lang.String padding)
        Pad a String to a minimum length specified by numberOfChars, adding the supplied padding String as many times as needed to the left. If the String is already the same size or bigger than the target numberOfChars, then the original String is returned. An example:
         println 'Numbers:'
         [1, 10, 100, 1000].each{ println it.toString().padLeft(5, '*') }
         [2, 20, 200, 2000].each{ println it.toString().padLeft(5, '*_') }
         
        will produce output like:
         Numbers:
         ****1
         ***10
         **100
         *1000
         *_*_2
         *_*20
         *_200
         *2000
         
        Parameters:
        self - a String object
        numberOfChars - the total minimum number of characters of the resulting string
        padding - the characters used for padding
        Returns:
        the String padded to the left
        Since:
        1.0
      • padLeft

        public static java.lang.CharSequence padLeft​(java.lang.CharSequence self,
                                                     java.lang.Number numberOfChars,
                                                     java.lang.CharSequence padding)
        Pad a CharSequence to a minimum length specified by numberOfChars, adding the supplied padding CharSequence as many times as needed to the left.
        Parameters:
        self - a CharSequence object
        numberOfChars - the total minimum number of characters of the resulting CharSequence
        padding - the characters used for padding
        Returns:
        the CharSequence padded to the left
        Since:
        1.8.2
        See Also:
        padLeft(String, Number, String)
      • padLeft

        public static java.lang.String padLeft​(java.lang.String self,
                                               java.lang.Number numberOfChars)
        Pad a String to a minimum length specified by numberOfChars by adding the space character to the left as many times as needed. If the String is already the same size or bigger than the target numberOfChars, then the original String is returned. An example:
         println 'Numbers:'
         [1, 10, 100, 1000].each{ println it.toString().padLeft(5) }
         
        will produce output like:
         Numbers:
             1
            10
           100
          1000
         
        Parameters:
        self - a String object
        numberOfChars - the total minimum number of characters of the resulting string
        Returns:
        the String padded to the left
        Since:
        1.0
        See Also:
        padLeft(String, Number, String)
      • padLeft

        public static java.lang.CharSequence padLeft​(java.lang.CharSequence self,
                                                     java.lang.Number numberOfChars)
        Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character to the left as many times as needed.
        Parameters:
        self - a CharSequence object
        numberOfChars - the total minimum number of characters of the resulting CharSequence
        Returns:
        the CharSequence padded to the left
        Since:
        1.8.2
        See Also:
        padLeft(CharSequence, Number, CharSequence)
      • padRight

        public static java.lang.String padRight​(java.lang.String self,
                                                java.lang.Number numberOfChars,
                                                java.lang.String padding)
        Pad a String to a minimum length specified by numberOfChars, adding the supplied padding String as many times as needed to the right. If the String is already the same size or bigger than the target numberOfChars, then the original String is returned. An example:
         ['A', 'BB', 'CCC', 'DDDD'].each{ println it.padRight(5, '#') + it.size() }
         
        will produce output like:
         A####1
         BB###2
         CCC##3
         DDDD#4
         
        Parameters:
        self - a String object
        numberOfChars - the total minimum number of characters of the resulting string
        padding - the characters used for padding
        Returns:
        the String padded to the right
        Since:
        1.0
      • padRight

        public static java.lang.CharSequence padRight​(java.lang.CharSequence self,
                                                      java.lang.Number numberOfChars,
                                                      java.lang.CharSequence padding)
        Pad a CharSequence to a minimum length specified by numberOfChars, adding the supplied padding CharSequence as many times as needed to the right.
        Parameters:
        self - a CharSequence object
        numberOfChars - the total minimum number of characters of the resulting CharSequence
        padding - the characters used for padding
        Returns:
        the CharSequence padded to the right
        Since:
        1.8.2
        See Also:
        padRight(String, Number, String)
      • padRight

        public static java.lang.String padRight​(java.lang.String self,
                                                java.lang.Number numberOfChars)
        Pad a String to a minimum length specified by numberOfChars by adding the space character to the right as many times as needed. If the String is already the same size or bigger than the target numberOfChars, then the original String is returned. An example:
         ['A', 'BB', 'CCC', 'DDDD'].each{ println it.padRight(5) + it.size() }
         
        will produce output like:
         A    1
         BB   2
         CCC  3
         DDDD 4
         
        Parameters:
        self - a String object
        numberOfChars - the total minimum number of characters of the resulting string
        Returns:
        the String padded to the right
        Since:
        1.0
      • padRight

        public static java.lang.CharSequence padRight​(java.lang.CharSequence self,
                                                      java.lang.Number numberOfChars)
        Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character to the right as many times as needed.
        Parameters:
        self - a CharSequence object
        numberOfChars - the total minimum number of characters of the resulting string
        Returns:
        the CharSequence padded to the right
        Since:
        1.8.2
        See Also:
        padRight(String, Number)
      • center

        public static java.lang.String center​(java.lang.String self,
                                              java.lang.Number numberOfChars,
                                              java.lang.String padding)
        Pad a String to a minimum length specified by numberOfChars, appending the supplied padding String around the original as many times as needed keeping it centered. If the String is already the same size or bigger than the target numberOfChars, then the original String is returned. An example:
         ['A', 'BB', 'CCC', 'DDDD'].each{ println '|' + it.center(6, '+') + '|' }
         
        will produce output like:
         |++A+++|
         |++BB++|
         |+CCC++|
         |+DDDD+|
         
        Parameters:
        self - a String object
        numberOfChars - the total minimum number of characters of the resulting string
        padding - the characters used for padding
        Returns:
        the String centered with padded characters around it
        Since:
        1.0
      • center

        public static java.lang.CharSequence center​(java.lang.CharSequence self,
                                                    java.lang.Number numberOfChars,
                                                    java.lang.CharSequence padding)
        Pad a CharSequence to a minimum length specified by numberOfChars, appending the supplied padding CharSequence around the original as many times as needed keeping it centered.
        Parameters:
        self - a CharSequence object
        numberOfChars - the total minimum number of characters of the resulting CharSequence
        padding - the characters used for padding
        Returns:
        the CharSequence centered with padded characters around it
        Since:
        1.8.2
        See Also:
        center(String, Number, String)
      • center

        public static java.lang.String center​(java.lang.String self,
                                              java.lang.Number numberOfChars)
        Pad a String to a minimum length specified by numberOfChars by adding the space character around it as many times as needed so that it remains centered. If the String is already the same size or bigger than the target numberOfChars, then the original String is returned. An example:
         ['A', 'BB', 'CCC', 'DDDD'].each{ println '|' + it.center(6) + '|' }
         
        will produce output like:
         |  A   |
         |  BB  |
         | CCC  |
         | DDDD |
         
        Parameters:
        self - a String object
        numberOfChars - the total minimum number of characters of the resulting string
        Returns:
        the String centered with padded characters around it
        Since:
        1.0
        See Also:
        center(String, Number, String)
      • center

        public static java.lang.CharSequence center​(java.lang.CharSequence self,
                                                    java.lang.Number numberOfChars)
        Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character around it as many times as needed so that it remains centered.
        Parameters:
        self - a CharSequence object
        numberOfChars - the total minimum number of characters of the resulting CharSequence
        Returns:
        the CharSequence centered with padded characters around it
        Since:
        1.8.2
        See Also:
        center(String, Number)
      • getAt

        public static java.lang.Object getAt​(java.util.regex.Matcher matcher,
                                             int idx)
        Support the subscript operator, e.g. matcher[index], for a regex Matcher.

        For an example using no group match,

            def p = /ab[d|f]/
            def m = "abcabdabeabf" =~ p
            assert 2 == m.count
            assert 2 == m.size() // synonym for m.getCount()
            assert ! m.hasGroup()
            assert 0 == m.groupCount()
            def matches = ["abd", "abf"]
            for (i in 0..<m.count) {
              assert m[i] == matches[i]
            }
         

        For an example using group matches,

            def p = /(?:ab([c|d|e|f]))/
            def m = "abcabdabeabf" =~ p
            assert 4 == m.count
            assert m.hasGroup()
            assert 1 == m.groupCount()
            def matches = [["abc", "c"], ["abd", "d"], ["abe", "e"], ["abf", "f"]]
            for (i in 0..<m.count) {
              assert m[i] == matches[i]
            }
         

        For another example using group matches,

            def m = "abcabdabeabfabxyzabx" =~ /(?:ab([d|x-z]+))/
            assert 3 == m.count
            assert m.hasGroup()
            assert 1 == m.groupCount()
            def matches = [["abd", "d"], ["abxyz", "xyz"], ["abx", "x"]]
            for (i in 0..<m.count) {
              assert m[i] == matches[i]
            }
         
        Parameters:
        matcher - a Matcher
        idx - an index
        Returns:
        object a matched String if no groups matched, list of matched groups otherwise.
        Since:
        1.0
      • setIndex

        public static void setIndex​(java.util.regex.Matcher matcher,
                                    int idx)
        Set the position of the given Matcher to the given index.
        Parameters:
        matcher - a Matcher
        idx - the index number
        Since:
        1.0
      • getCount

        public static int getCount​(java.util.regex.Matcher matcher)
        Find the number of Strings matched to the given Matcher.
        Parameters:
        matcher - a Matcher
        Returns:
        int the number of Strings matched to the given matcher.
        Since:
        1.0
      • hasGroup

        public static boolean hasGroup​(java.util.regex.Matcher matcher)
        Check whether a Matcher contains a group or not.
        Parameters:
        matcher - a Matcher
        Returns:
        boolean true if matcher contains at least one group.
        Since:
        1.0
      • getAt

        public static <T> java.util.List<T> getAt​(java.util.List<T> self,
                                                  Range range)
        Support the range subscript operator for a List.
        def list = [1, "a", 4.5, true]
         assert list[1..2] == ["a", 4.5]
        Parameters:
        self - a List
        range - a Range indicating the items to get
        Returns:
        a sublist based on range borders or a new list if range is reversed
        Since:
        1.0
        See Also:
        List.subList(int,int)
      • getAt

        public static <T> java.util.List<T> getAt​(java.util.List<T> self,
                                                  EmptyRange range)
        Support the range subscript operator for a List.
        def list = [true, 1, 3.4]
         assert list[0..<0] == []
        Parameters:
        self - a List
        range - a Range indicating the items to get
        Returns:
        a sublist based on range borders or a new list if range is reversed
        Since:
        1.0
        See Also:
        List.subList(int,int)
      • getAt

        public static <T> java.util.List<T> getAt​(java.util.List<T> self,
                                                  java.util.Collection indices)
        Select a List of items from a List using a Collection to identify the indices to be selected.
        def list = [true, 1, 3.4, false]
         assert list[1,0,2] == [1, true, 3.4]
        Parameters:
        self - a List
        indices - a Collection of indices
        Returns:
        a new list of the values at the given indices
        Since:
        1.0
      • getAt

        public static <T> java.util.List<T> getAt​(T[] self,
                                                  java.util.Collection indices)
        Select a List of items from an Object array using a Collection to identify the indices to be selected.
        Parameters:
        self - an Array of Objects
        indices - a Collection of indices
        Returns:
        a new list of the values at the given indices
        Since:
        1.0
      • getAt

        public static java.lang.CharSequence getAt​(java.lang.CharSequence self,
                                                   java.util.Collection indices)
        Select a List of characters from a CharSequence using a Collection to identify the indices to be selected.
        Parameters:
        self - a CharSequence
        indices - a Collection of indices
        Returns:
        a CharSequence consisting of the characters at the given indices
        Since:
        1.0
      • getAt

        public static java.lang.String getAt​(java.lang.String self,
                                             java.util.Collection indices)
        Select a List of characters from a String using a Collection to identify the indices to be selected.
        Parameters:
        self - a String
        indices - a Collection of indices
        Returns:
        a String consisting of the characters at the given indices
        Since:
        1.0
      • getAt

        public static java.util.List getAt​(java.util.regex.Matcher self,
                                           java.util.Collection indices)
        Select a List of values from a Matcher using a Collection to identify the indices to be selected.
        Parameters:
        self - a Matcher
        indices - a Collection of indices
        Returns:
        a String of the values at the given indices
        Since:
        1.6.0
      • subMap

        public static <K,​V> java.util.Map<K,​V> subMap​(java.util.Map<K,​V> map,
                                                                  java.util.Collection<K> keys)
        Creates a sub-Map containing the given keys. This method is similar to List.subList() but uses keys rather than index ranges.
        assert [1:10, 2:20, 4:40].subMap( [2, 4] ) == [2:20, 4:40]
        Parameters:
        map - a Map
        keys - a Collection of keys
        Returns:
        a new Map containing the given keys
        Since:
        1.0
      • get

        public static <K,​V> V get​(java.util.Map<K,​V> map,
                                        K key,
                                        V defaultValue)
        Looks up an item in a Map for the given key and returns the value - unless there is no entry for the given key in which case add the default value to the map and return that.
        def map=[:]
         map.get("a", []) << 5
         assert map == [a:[5]]
        Parameters:
        map - a Map
        key - the key to lookup the value of
        defaultValue - the value to return and add to the map for this key if there is no entry for the given key
        Returns:
        the value of the given key or the default value, added to the map if the key did not exist
        Since:
        1.0
      • getAt

        public static <T> java.util.List<T> getAt​(T[] array,
                                                  Range range)
        Support the range subscript operator for an Array
        Parameters:
        array - an Array of Objects
        range - a Range
        Returns:
        a range of a list from the range's from index up to but not including the range's to value
        Since:
        1.0
      • takeWhile

        public static <T> java.util.List<T> takeWhile​(java.util.List<T> self,
                                                      Closure condition)
        Returns the longest prefix of this list where each element passed to the given closure condition evaluates to true. Similar to takeWhile(Iterable, groovy.lang.Closure) except that it attempts to preserve the type of the original list.
         def nums = [ 1, 3, 2 ]
         assert nums.takeWhile{ it < 1 } == []
         assert nums.takeWhile{ it < 3 } == [ 1 ]
         assert nums.takeWhile{ it < 4 } == [ 1, 3, 2 ]
         
        Parameters:
        self - the original list
        condition - the closure that must evaluate to true to continue taking elements
        Returns:
        a prefix of the given list where each element passed to the given closure evaluates to true
        Since:
        1.8.7
      • takeWhile

        public static <T> java.util.List<T> takeWhile​(java.lang.Iterable<T> self,
                                                      Closure condition)
        Returns a List containing the longest prefix of the elements from this Iterable where each element passed to the given closure evaluates to true.
         class AbcIterable implements Iterable {
             Iterator iterator() { "abc".iterator() }
         }
         def abc = new AbcIterable()
         assert abc.takeWhile{ it < 'b' } == ['a']
         assert abc.takeWhile{ it <= 'b' } == ['a', 'b']
         
        Parameters:
        self - an Iterable
        condition - the closure that must evaluate to true to continue taking elements
        Returns:
        a List containing a prefix of the elements from the given Iterable where each element passed to the given closure evaluates to true
        Since:
        1.8.7
      • takeWhile

        public static <K,​V> java.util.Map<K,​V> takeWhile​(java.util.Map<K,​V> self,
                                                                     Closure<?> condition)
        Returns the longest prefix of this Map where each entry (or key/value pair) when passed to the given closure evaluates to true.
         def shopping = [milk:1, bread:2, chocolate:3]
         assert shopping.takeWhile{ it.key.size() < 6 } == [milk:1, bread:2]
         assert shopping.takeWhile{ it.value % 2 } == [milk:1]
         assert shopping.takeWhile{ k, v -> k.size() + v <= 7 } == [milk:1, bread:2]
         
        If the map instance does not have ordered keys, then this function could appear to take random entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.
        Parameters:
        self - a Map
        condition - a 1 (or 2) arg Closure that must evaluate to true for the entry (or key and value) to continue taking elements
        Returns:
        a prefix of the given Map where each entry (or key/value pair) passed to the given closure evaluates to true
        Since:
        1.8.7
      • takeWhile

        public static <T> T[] takeWhile​(T[] self,
                                        Closure condition)
        Returns the longest prefix of this array where each element passed to the given closure evaluates to true.
         def nums = [ 1, 3, 2 ] as Integer[]
         assert nums.takeWhile{ it < 1 } == [] as Integer[]
         assert nums.takeWhile{ it < 3 } == [ 1 ] as Integer[]
         assert nums.takeWhile{ it < 4 } == [ 1, 3, 2 ] as Integer[]
         
        Parameters:
        self - the original array
        condition - the closure that must evaluate to true to continue taking elements
        Returns:
        a prefix of the given array where each element passed to the given closure evaluates to true
        Since:
        1.8.7
      • takeWhile

        public static <T> java.util.Iterator<T> takeWhile​(java.util.Iterator<T> self,
                                                          Closure condition)
        Returns the longest prefix of elements in this iterator where each element passed to the given condition closure evaluates to true.

         def a = 0
         def iter = [ hasNext:{ true }, next:{ a++ } ] as Iterator
        
         assert [].iterator().takeWhile{ it < 3 }.toList() == []
         assert [1, 2, 3, 4, 5].iterator().takeWhile{ it < 3 }.toList() == [ 1, 2 ]
         assert iter.takeWhile{ it < 5 }.toList() == [ 0, 1, 2, 3, 4 ]
         
        Parameters:
        self - the Iterator
        condition - the closure that must evaluate to true to continue taking elements
        Returns:
        a prefix of elements in the given iterator where each element passed to the given closure evaluates to true
        Since:
        1.8.7
      • takeWhile

        public static java.lang.CharSequence takeWhile​(java.lang.CharSequence self,
                                                       Closure closure)
        Returns the longest prefix of this CharSequence where each element passed to the given closure evalutes to true.
             def text = "Groovy"
             assert text.takeWhile{ it < 'A' } == ''
             assert text.takeWhile{ it < 'Z' } == 'G'
             assert text.takeWhile{ it < 'z'  } == 'Groovy'
         
        Parameters:
        self - the original CharSequence
        num - the number of chars to take from this CharSequence
        Returns:
        a CharSequence consisting of the first num chars, or else the whole CharSequence if it has less then num elements.
        Since:
        1.8.1
      • getAt

        public static <T> java.util.List<T> getAt​(T[] array,
                                                  IntRange range)
        Parameters:
        array - an Array of Objects
        range - an IntRange
        Returns:
        a range of a list from the range's from index up to but not including the range's to value
        Since:
        1.0
      • getAt

        public static <T> java.util.List<T> getAt​(T[] array,
                                                  EmptyRange range)
        Parameters:
        array - an Array of Objects
        range - an EmptyRange
        Returns:
        an empty Range
        Since:
        1.5.0
      • getAt

        public static <T> java.util.List<T> getAt​(T[] array,
                                                  ObjectRange range)
        Parameters:
        array - an Array of Objects
        range - an ObjectRange
        Returns:
        a range of a list from the range's from index up to but not including the range's to value
        Since:
        1.0
      • toList

        public static <T> java.util.List<T> toList​(T[] array)
        Allows conversion of arrays into a mutable List.
        Parameters:
        array - an Array of Objects
        Returns:
        the array as a List
        Since:
        1.0
      • getAt

        public static <T> T getAt​(java.util.List<T> self,
                                  int idx)
        Support the subscript operator for a List.
        def list = [2, "a", 5.3]
         assert list[1] == "a"
        Parameters:
        self - a List
        idx - an index
        Returns:
        the value at the given index
        Since:
        1.0
      • getAt

        public static <T> T getAt​(java.util.Iterator<T> self,
                                  int idx)
        Support the subscript operator for an Iterator. The iterator will be partially exhausted up until the idx entry after returning if a +ve or 0 idx is used, or fully exhausted if a -ve idx is used or no corresponding entry was found. Typical usage:
         def iter = [2, "a", 5.3].iterator()
         assert iter[1] == "a"
         
        A more elaborate example:
         def items = [2, "a", 5.3]
         def iter = items.iterator()
         assert iter[-1] == 5.3
         // iter exhausted, so reset
         iter = items.iterator()
         assert iter[1] == "a"
         // iter partially exhausted so now idx starts after "a"
         assert iter[0] == 5.3
         
        Parameters:
        self - an Iterator
        idx - an index value (-self.size() <= idx < self.size())
        Returns:
        the value at the given index (after normalisation) or null if no corresponding value was found
        Since:
        1.7.2
      • putAt

        public static <T> void putAt​(java.util.List<T> self,
                                     int idx,
                                     T value)
        A helper method to allow lists to work with subscript operators.
        def list = [2, 3]
         list[0] = 1
         assert list == [1, 3]
        Parameters:
        self - a List
        idx - an index
        value - the value to put at the given index
        Since:
        1.0
      • putAt

        public static void putAt​(java.lang.StringBuffer self,
                                 IntRange range,
                                 java.lang.Object value)
        Support the range subscript operator for StringBuffer. Index values are treated as characters within the buffer.
        Parameters:
        self - a StringBuffer
        range - a Range
        value - the object that's toString() will be inserted
        Since:
        1.0
      • putAt

        public static void putAt​(java.lang.StringBuffer self,
                                 EmptyRange range,
                                 java.lang.Object value)
        Support the range subscript operator for StringBuffer.
        Parameters:
        self - a StringBuffer
        range - a Range
        value - the object that's toString() will be inserted
        Since:
        1.0
      • putAt

        public static void putAt​(java.util.List self,
                                 EmptyRange range,
                                 java.lang.Object value)
        A helper method to allow lists to work with subscript operators.
        def list = ["a", true]
         list[1..<1] = 5
         assert list == ["a", 5, true]
        Parameters:
        self - a List
        range - the (in this case empty) subset of the list to set
        value - the values to put at the given sublist or a Collection of values
        Since:
        1.0
      • putAt

        public static void putAt​(java.util.List self,
                                 EmptyRange range,
                                 java.util.Collection value)
        A helper method to allow lists to work with subscript operators.
        def list = ["a", true]
         list[1..<1] = [4, 3, 2]
         assert list == ["a", 4, 3, 2, true]
        Parameters:
        self - a List
        range - the (in this case empty) subset of the list to set
        value - the Collection of values
        Since:
        1.0
        See Also:
        putAt(java.util.List, groovy.lang.EmptyRange, java.lang.Object)
      • putAt

        public static void putAt​(java.util.List self,
                                 IntRange range,
                                 java.util.Collection col)
        List subscript assignment operator when given a range as the index and the assignment operand is a collection. Example:
        def myList = [4, 3, 5, 1, 2, 8, 10]
         myList[3..5] = ["a", true]
         assert myList == [4, 3, 5, "a", true, 10]
        Items in the given range are replaced with items from the collection.
        Parameters:
        self - a List
        range - the subset of the list to set
        col - the collection of values to put at the given sublist
        Since:
        1.5.0
      • putAt

        public static void putAt​(java.util.List self,
                                 IntRange range,
                                 java.lang.Object value)
        List subscript assignment operator when given a range as the index. Example:
        def myList = [4, 3, 5, 1, 2, 8, 10]
         myList[3..5] = "b"
         assert myList == [4, 3, 5, "b", 10]
        Items in the given range are replaced with the operand. The value operand is always treated as a single value.
        Parameters:
        self - a List
        range - the subset of the list to set
        value - the value to put at the given sublist
        Since:
        1.0
      • putAt

        public static void putAt​(java.util.List self,
                                 java.util.List splice,
                                 java.util.List values)
        A helper method to allow lists to work with subscript operators.
        def list = ["a", true, 42, 9.4]
         list[1, 4] = ["x", false]
         assert list == ["a", "x", 42, 9.4, false]
        Parameters:
        self - a List
        splice - the subset of the list to set
        values - the value to put at the given sublist
        Since:
        1.0
      • putAt

        public static void putAt​(java.util.List self,
                                 java.util.List splice,
                                 java.lang.Object value)
        A helper method to allow lists to work with subscript operators.
        def list = ["a", true, 42, 9.4]
         list[1, 3] = 5
         assert list == ["a", 5, 42, 5]
        Parameters:
        self - a List
        splice - the subset of the list to set
        value - the value to put at the given sublist
        Since:
        1.0
      • getSubList

        protected static java.util.List getSubList​(java.util.List self,
                                                   java.util.List splice)
      • getAt

        public static <K,​V> V getAt​(java.util.Map<K,​V> self,
                                          K key)
        Support the subscript operator for a Map.
        def map = [a:10]
         assert map["a"] == 10
        Parameters:
        self - a Map
        key - an Object as a key for the map
        Returns:
        the value corresponding to the given key
        Since:
        1.0
      • plus

        public static <K,​V> java.util.Map<K,​V> plus​(java.util.Map<K,​V> left,
                                                                java.util.Map<K,​V> right)
        Returns a new Map containing all entries from left and right, giving precedence to right. Any keys appearing in both Maps will appear in the resultant map with values from the right operand. If the left map is one of TreeMap, LinkedHashMap, Hashtable or Properties, the returned Map will preserve that type, otherwise a HashMap will be returned.

        Roughly equivalent to Map m = new HashMap(); m.putAll(left); m.putAll(right); return m; but with some additional logic to preserve the left Map type for common cases as described above.

        assert [a:10, b:20] + [a:5, c:7] == [a:5, b:20, c:7]
        Parameters:
        left - a Map
        right - a Map
        Returns:
        a new Map containing all entries from left and right
        Since:
        1.5.0
      • putAt

        public static <K,​V> V putAt​(java.util.Map<K,​V> self,
                                          K key,
                                          V value)
        A helper method to allow maps to work with subscript operators
        Parameters:
        self - a Map
        key - an Object as a key for the map
        value - the value to put into the map
        Returns:
        the value corresponding to the given key
        Since:
        1.0
      • getAt

        public static java.util.List getAt​(java.util.Collection coll,
                                           java.lang.String property)
        Support the subscript operator for Collection.
        assert [String, Long, Integer] == ["a",5L,2]["class"]
        Parameters:
        coll - a Collection
        property - a String
        Returns:
        a List
        Since:
        1.0
      • asImmutable

        public static <K,​V> java.util.Map<K,​V> asImmutable​(java.util.Map<? extends K,​? extends V> self)
        A convenience method for creating an immutable map.
        Parameters:
        self - a Map
        Returns:
        an immutable Map
        Since:
        1.0
        See Also:
        Collections.unmodifiableMap(java.util.Map)
      • asImmutable

        public static <K,​V> java.util.SortedMap<K,​V> asImmutable​(java.util.SortedMap<K,​? extends V> self)
        A convenience method for creating an immutable sorted map.
        Parameters:
        self - a SortedMap
        Returns:
        an immutable SortedMap
        Since:
        1.0
        See Also:
        Collections.unmodifiableSortedMap(java.util.SortedMap)
      • asImmutable

        public static <T> java.util.List<T> asImmutable​(java.util.List<? extends T> self)
        A convenience method for creating an immutable list
        Parameters:
        self - a List
        Returns:
        an immutable List
        Since:
        1.0
        See Also:
        Collections.unmodifiableList(java.util.List)
      • asImmutable

        public static <T> java.util.Set<T> asImmutable​(java.util.Set<? extends T> self)
        A convenience method for creating an immutable list.
        Parameters:
        self - a Set
        Returns:
        an immutable Set
        Since:
        1.0
        See Also:
        Collections.unmodifiableSet(java.util.Set)
      • asImmutable

        public static <T> java.util.SortedSet<T> asImmutable​(java.util.SortedSet<T> self)
        A convenience method for creating an immutable sorted set.
        Parameters:
        self - a SortedSet
        Returns:
        an immutable SortedSet
        Since:
        1.0
        See Also:
        Collections.unmodifiableSortedSet(java.util.SortedSet)
      • asImmutable

        public static <T> java.util.Collection<T> asImmutable​(java.util.Collection<? extends T> self)
        A convenience method for creating an immutable Collection.
        def mutable = [1,2,3]
         def immutable = mutable.asImmutable()
         mutable << 4
         try {
           immutable << 4
           assert false
         } catch (UnsupportedOperationException) {
           assert true
         }
        Parameters:
        self - a Collection
        Returns:
        an immutable Collection
        Since:
        1.5.0
        See Also:
        Collections.unmodifiableCollection(java.util.Collection)
      • asSynchronized

        public static <K,​V> java.util.Map<K,​V> asSynchronized​(java.util.Map<K,​V> self)
        A convenience method for creating a synchronized Map.
        Parameters:
        self - a Map
        Returns:
        a synchronized Map
        Since:
        1.0
        See Also:
        Collections.synchronizedMap(java.util.Map)
      • asSynchronized

        public static <K,​V> java.util.SortedMap<K,​V> asSynchronized​(java.util.SortedMap<K,​V> self)
        A convenience method for creating a synchronized SortedMap.
        Parameters:
        self - a SortedMap
        Returns:
        a synchronized SortedMap
        Since:
        1.0
        See Also:
        Collections.synchronizedSortedMap(java.util.SortedMap)
      • asSynchronized

        public static <T> java.util.Collection<T> asSynchronized​(java.util.Collection<T> self)
        A convenience method for creating a synchronized Collection.
        Parameters:
        self - a Collection
        Returns:
        a synchronized Collection
        Since:
        1.0
        See Also:
        Collections.synchronizedCollection(java.util.Collection)
      • asSynchronized

        public static <T> java.util.List<T> asSynchronized​(java.util.List<T> self)
        A convenience method for creating a synchronized List.
        Parameters:
        self - a List
        Returns:
        a synchronized List
        Since:
        1.0
        See Also:
        Collections.synchronizedList(java.util.List)
      • asSynchronized

        public static <T> java.util.Set<T> asSynchronized​(java.util.Set<T> self)
        A convenience method for creating a synchronized Set.
        Parameters:
        self - a Set
        Returns:
        a synchronized Set
        Since:
        1.0
        See Also:
        Collections.synchronizedSet(java.util.Set)
      • asSynchronized

        public static <T> java.util.SortedSet<T> asSynchronized​(java.util.SortedSet<T> self)
        A convenience method for creating a synchronized SortedSet.
        Parameters:
        self - a SortedSet
        Returns:
        a synchronized SortedSet
        Since:
        1.0
        See Also:
        Collections.synchronizedSortedSet(java.util.SortedSet)
      • plus

        public static <T> T[] plus​(T[] left,
                                   T[] right)
        Create an array as a union of two arrays.
         Integer[] a = [1, 2, 3]
         Integer[] b = [4, 5, 6]
         assert a + b == [1, 2, 3, 4, 5, 6] as Integer[]
         
        Parameters:
        left - the left Array
        right - the right Array
        Returns:
        A new array containing right appended to left.
        Since:
        1.8.7
      • plus

        public static <T> T[] plus​(T[] left,
                                   T right)
        Create an array containing elements from an original array plus an additional appended element.
         Integer[] a = [1, 2, 3]
         Integer[] result = a + 4
         assert result == [1, 2, 3, 4] as Integer[]
         
        Parameters:
        left - the array
        right - the value to append
        Returns:
        A new array containing left with right appended to it.
        Since:
        1.8.7
      • plus

        public static <T> T[] plus​(T[] left,
                                   java.util.Collection<T> right)
        Create an array containing elements from an original array plus those from a Collection.
         Integer[] a = [1, 2, 3]
         def additions = [7, 8]
         assert a + additions == [1, 2, 3, 7, 8] as Integer[]
         
        Parameters:
        left - the array
        right - a Collection to be appended
        Returns:
        A new array containing left with right appended to it.
        Since:
        1.8.7
      • plus

        public static <T> T[] plus​(T[] left,
                                   java.lang.Iterable<T> right)
        Create an array containing elements from an original array plus those from an Iterable.
         class AbcIterable implements Iterable {
             Iterator iterator() { "abc".iterator() }
         }
         String[] letters = ['x', 'y', 'z']
         def result = letters + new AbcIterable()
         assert result == ['x', 'y', 'z', 'a', 'b', 'c'] as String[]
         assert result.class.array
         
        Parameters:
        left - the array
        right - an Iterable to be appended
        Returns:
        A new array containing elements from left with those from right appended.
        Since:
        1.8.7
      • plus

        public static <T> java.util.Collection<T> plus​(java.util.Collection<T> left,
                                                       java.util.Collection<T> right)
        Create a Collection as a union of two collections. If the left collection is a Set, then the returned collection will be a Set otherwise a List. This operation will always create a new object for the result, while the operands remain unchanged.
        assert [1,2,3,4] == [1,2] + [3,4]
        Parameters:
        left - the left Collection
        right - the right Collection
        Returns:
        the merged Collection
        Since:
        1.5.0
      • plus

        public static <T> java.util.Collection<T> plus​(java.util.Collection<T> left,
                                                       java.lang.Iterable<T> right)
        Create a Collection as a union of a Collection and an Iterable. If the left collection is a Set, then the returned collection will be a Set otherwise a List. This operation will always create a new object for the result, while the operands remain unchanged.
        Parameters:
        left - the left Collection
        right - the right Iterable
        Returns:
        the merged Collection
        Since:
        1.8.7
        See Also:
        plus(Collection, Collection)
      • plus

        public static <T> java.util.List<T> plus​(java.util.List<T> self,
                                                 int index,
                                                 T[] items)
        Creates a new List by inserting all of the elements in the specified array to the elements from the original List at the specified index. Shifts the element currently at that index (if any) and any subsequent elements to the right (increasing their indices). The new elements will appear in the resulting List in the order that they occur in the original array. The behavior of this operation is undefined if the list or array operands are modified while the operation is in progress. The original list and array operands remain unchanged.
         def items = [1, 2, 3]
         def newItems = items.plus(2, 'a'..'c' as String[])
         assert newItems == [1, 2, 'a', 'b', 'c', 3]
         assert items == [1, 2, 3]
         
        See also addAll for similar functionality with modify semantics, i.e. which performs the changes on the original list itself.
        Parameters:
        self - an original list
        items - array containing elements to be merged with elements from the original list
        index - index at which to insert the first element from the specified array
        Returns:
        the new list
        Since:
        1.8.1
        See Also:
        plus(List, int, List)
      • plus

        public static <T> java.util.List<T> plus​(java.util.List<T> self,
                                                 int index,
                                                 java.util.List<T> additions)
        Creates a new List by inserting all of the elements in the given additions List to the elements from the original List at the specified index. Shifts the element currently at that index (if any) and any subsequent elements to the right (increasing their indices). The new elements will appear in the resulting List in the order that they occur in the original lists. The behavior of this operation is undefined if the original lists are modified while the operation is in progress. The original lists remain unchanged.
         def items = [1, 2, 3]
         def newItems = items.plus(2, 'a'..'c')
         assert newItems == [1, 2, 'a', 'b', 'c', 3]
         assert items == [1, 2, 3]
         
        See also addAll for similar functionality with modify semantics, i.e. which performs the changes on the original list itself.
        Parameters:
        self - an original List
        additions - a List containing elements to be merged with elements from the original List
        index - index at which to insert the first element from the given additions List
        Returns:
        the new list
        Since:
        1.8.1
      • plus

        public static <T> java.util.List<T> plus​(java.util.List<T> self,
                                                 int index,
                                                 java.lang.Iterable<T> 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.
        Parameters:
        self - an original list
        additions - an Iterable containing elements to be merged with the elements from the original List
        index - index at which to insert the first element from the given additions Iterable
        Returns:
        the new list
        Since:
        1.8.7
        See Also:
        plus(List, int, List)
      • plus

        public static <T> java.util.Collection<T> plus​(java.util.Collection<T> left,
                                                       T right)
        Create a collection as a union of a Collection and an Object. If the collection is a Set, then the returned collection will be a Set otherwise a List. This operation will always create a new object for the result, while the operands remain unchanged.
        assert [1,2,3] == [1,2] + 3
        Parameters:
        left - a Collection
        right - an object to add/append
        Returns:
        the resulting Collection
        Since:
        1.5.0
      • spread

        public static SpreadMap spread​(java.util.Map self)
        Parameters:
        self - a map
        Returns:
        a newly created SpreadMap
        Since:
        1.0
      • toSpreadMap

        public static SpreadMap toSpreadMap​(java.util.Map self)
        Returns a new SpreadMap from this map.

        The example below shows the various possible use cases:

         def fn(Map m) { return m.a + m.b + m.c + m.d }
        
         assert fn(a:1, b:2, c:3, d:4) == 10
         assert fn(a:1, *:[b:2, c:3], d:4) == 10
         assert fn([a:1, b:2, c:3, d:4].toSpreadMap()) == 10
         assert fn((['a', 1, 'b', 2, 'c', 3, 'd', 4] as Object[]).toSpreadMap()) == 10
         assert fn(['a', 1, 'b', 2, 'c', 3, 'd', 4].toSpreadMap()) == 10
         assert fn(['abcd'.toList(), 1..4].transpose().flatten().toSpreadMap()) == 10
         
        Note that toSpreadMap() is not normally used explicitly but under the covers by Groovy.
        Parameters:
        self - a map to be converted into a SpreadMap
        Returns:
        a newly created SpreadMap if this map is not null and its size is positive.
        Since:
        1.0
        See Also:
        SpreadMap(java.util.Map)
      • withDefault

        public static <K,​V> java.util.Map<K,​V> withDefault​(java.util.Map<K,​V> self,
                                                                       Closure init)
        Wraps a map using the decorator pattern with a wrapper that intercepts all calls to get(key). If an unknown key is found, a default value will be stored into the Map before being returned. The default value stored will be the result of calling the supplied Closure with the key as the parameter to the Closure. Example usage:
         def map = [a:1, b:2].withDefault{ k -> k.toCharacter().isLowerCase() ? 10 : -10 }
         def expected = [a:1, b:2, c:10, D:-10]
         assert expected.every{ e -> e.value == map[e.key] }
        
         def constMap = [:].withDefault{ 42 }
         assert constMap.foo == 42
         assert constMap.size() == 1
         
        Parameters:
        self - a Map
        init - a Closure which is passed the unknown key
        Returns:
        the wrapped Map
        Since:
        1.7.1
      • withLazyDefault

        public static <T> java.util.List<T> withLazyDefault​(java.util.List<T> self,
                                                            Closure init)
        Decorates a list allowing it to grow when called with a non-existent index value. When called with such values, the list is grown in size and a default value is placed in the list by calling a supplied init Closure. Subsequent retrieval operations if finding a null value in the list assume it was set as null from an earlier growing operation and again call the init Closure to populate the retrieved value; consequently the list can't be used to store null values.

        How it works: The decorated list intercepts all calls to getAt(index) and get(index). If an index greater than or equal to the current size() is used, the list will grow automatically up to the specified index. Gaps will be filled by null. If a default value should also be used to fill gaps instead of null, use withEagerDefault. If getAt(index) or get(index) are called and a null value is found, it is assumed that the null value was a consequence of an earlier grow list operation and the init Closure is called to populate the value.

        Example usage:

         def list = [0, 1].withLazyDefault{ 42 }
         assert list[0] == 0
         assert list[1] == 1
         assert list[3] == 42   // default value
         assert list == [0, 1, null, 42] // gap filled with null
        
         // illustrate using the index when generating default values
         def list2 = [5].withLazyDefault{ index -> index * index }
         assert list2[3] == 9
         assert list2 == [5, null, null, 9]
         assert list2[2] == 4
         assert list2 == [5, null, 4, 9]
        
         // illustrate what happens with null values
         list2[2] = null
         assert list2[2] == 4
         
        Parameters:
        self - a List
        init - a Closure with the target index as parameter which generates the default value
        Returns:
        the decorated List
        Since:
        1.8.7
      • withEagerDefault

        public static <T> java.util.List<T> withEagerDefault​(java.util.List<T> self,
                                                             Closure init)
        Decorates a list allowing it to grow when called with a non-existent index value. When called with such values, the list is grown in size and a default value is placed in the list by calling a supplied init Closure. Null values can be stored in the list.

        How it works: The decorated list intercepts all calls to getAt(index) and get(index). If an index greater than or equal to the current size() is used, the list will grow automatically up to the specified index. Gaps will be filled by calling the init Closure. If generating a default value is a costly operation consider using withLazyDefault.

        Example usage:

         def list = [0, 1].withEagerDefault{ 42 }
         assert list[0] == 0
         assert list[1] == 1
         assert list[3] == 42   // default value
         assert list == [0, 1, 42, 42]   // gap filled with default value
        
         // illustrate using the index when generating default values
         def list2 = [5].withEagerDefault{ index -> index * index }
         assert list2[3] == 9
         assert list2 == [5, 1, 4, 9]
        
         // illustrate what happens with null values
         list2[2] = null
         assert list2[2] == null
         assert list2 == [5, 1, null, 9]
         
        Parameters:
        self - a List
        init - a Closure with the target index as parameter which generates the default value
        Returns:
        the wrapped List
        Since:
        1.8.7
      • sort

        public static <T> java.util.List<T> sort​(java.util.Collection<T> self)
        Sorts the Collection. Assumes that the collection items are comparable and uses their natural ordering to determine the resulting order. If the Collection is a List, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Collection unchanged.
        assert [1,2,3] == [3,1,2].sort()
        Parameters:
        self - the collection to be sorted
        Returns:
        the sorted collection as a List
        Since:
        1.0
        See Also:
        sort(Collection, boolean)
      • sort

        public static <T> java.util.List<T> sort​(java.util.Collection<T> self,
                                                 boolean mutate)
        Sorts the Collection. Assumes that the collection items are comparable and uses their natural ordering to determine the resulting order. If the Collection is a List and mutate is true, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Collection unchanged.
        assert [1,2,3] == [3,1,2].sort()
         def orig = [1, 3, 2]
         def sorted = orig.sort(false)
         assert orig == [1, 3, 2]
         assert sorted == [1, 2, 3]
         
        Parameters:
        self - the collection to be sorted
        mutate - false will always cause a new list to be created, true will mutate lists in place
        Returns:
        the sorted collection as a List
        Since:
        1.8.1
      • sort

        public static <K,​V> java.util.Map<K,​V> sort​(java.util.Map<K,​V> self,
                                                                Closure closure)
        Sorts the elements from the given map into a new ordered map using the closure as a comparator to determine the ordering. The original map is unchanged.
        def map = [a:5, b:3, c:6, d:4].sort { a, b -> a.value <=> b.value }
         assert map == [b:3, d:4, a:5, c:6]
        Parameters:
        self - the original unsorted map
        closure - a Closure used as a comparator
        Returns:
        the sorted map
        Since:
        1.6.0
      • sort

        public static <K,​V> java.util.Map<K,​V> sort​(java.util.Map<K,​V> self,
                                                                java.util.Comparator<K> comparator)
        Sorts the elements from the given map into a new ordered Map using the specified key comparator to determine the ordering. The original map is unchanged.
        def map = [ba:3, cz:6, ab:5].sort({ a, b -> a[-1] <=> b[-1] } as Comparator)
         assert map*.value == [3, 5, 6]
        Parameters:
        self - the original unsorted map
        comparator - a Comparator
        Returns:
        the sorted map
        Since:
        1.7.2
      • sort

        public static <K,​V> java.util.Map<K,​V> sort​(java.util.Map<K,​V> self)
        Sorts the elements from the given map into a new ordered Map using the natural ordering of the keys to determine the ordering. The original map is unchanged.
        map = [ba:3, cz:6, ab:5].sort()
         assert map*.value == [5, 3, 6]
         
        Parameters:
        self - the original unsorted map
        Returns:
        the sorted map
        Since:
        1.7.2
      • sort

        public static <T> T[] sort​(T[] self)
        Modifies this array so that its elements are in sorted order. The array items are assumed to be comparable.
        Parameters:
        self - the array to be sorted
        Returns:
        the sorted array
        Since:
        1.5.5
      • sort

        public static <T> T[] sort​(T[] self,
                                   boolean mutate)
        Sorts the given array into sorted order. The array items are assumed to be comparable. If mutate is true, the array is sorted in place and returned. Otherwise, a new sorted array is returned and the original array remains unchanged.
         def orig = ["hello","hi","Hey"] as String[]
         def sorted = orig.sort(false)
         assert orig == ["hello","hi","Hey"] as String[]
         assert sorted == ["Hey","hello","hi"] as String[]
         orig.sort(true)
         assert orig == ["Hey","hello","hi"] as String[]
         
        Parameters:
        self - the array to be sorted
        mutate - false will always cause a new array to be created, true will mutate the array in place
        Returns:
        the sorted array
        Since:
        1.8.1
      • sort

        public static <T> java.util.Iterator<T> sort​(java.util.Iterator<T> self)
        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.
        Parameters:
        self - the Iterator to be sorted
        Returns:
        the sorted items as an Iterator
        Since:
        1.5.5
      • sort

        public static <T> java.util.Iterator<T> sort​(java.util.Iterator<T> self,
                                                     java.util.Comparator<T> comparator)
        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.
        Parameters:
        self - the Iterator to be sorted
        comparator - a Comparator used for comparing items
        Returns:
        the sorted items as an Iterator
        Since:
        1.5.5
      • sort

        public static <T> java.util.List<T> sort​(java.util.Collection<T> self,
                                                 java.util.Comparator<T> comparator)
        Sorts the Collection using the given Comparator. If the Collection is a List, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Collection unchanged.
         assert ["hi","hey","hello"] == ["hello","hi","hey"].sort( { a, b -> a.length() <=> b.length() } as Comparator )
         
         assert ["hello","Hey","hi"] == ["hello","hi","Hey"].sort(String.CASE_INSENSITIVE_ORDER)
         
        Parameters:
        self - a collection to be sorted
        comparator - a Comparator used for the comparison
        Returns:
        a sorted List
        Since:
        1.0
        See Also:
        sort(Collection, boolean, Comparator)
      • sort

        public static <T> java.util.List<T> sort​(java.util.Collection<T> self,
                                                 boolean mutate,
                                                 java.util.Comparator<T> comparator)
        Sorts the Collection using the given Comparator. If the Collection is a List and mutate is true, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Collection unchanged.
         assert ["hi","hey","hello"] == ["hello","hi","hey"].sort( { a, b -> a.length() <=> b.length() } as Comparator )
         
         def orig = ["hello","hi","Hey"]
         def sorted = orig.sort(false, String.CASE_INSENSITIVE_ORDER)
         assert orig == ["hello","hi","Hey"]
         assert sorted == ["hello","Hey","hi"]
         
        Parameters:
        self - a collection to be sorted
        mutate - false will always cause a new list to be created, true will mutate lists in place
        comparator - a Comparator used for the comparison
        Returns:
        a sorted List
        Since:
        1.8.1
      • sort

        public static <T> T[] sort​(T[] self,
                                   java.util.Comparator<T> comparator)
        Sorts the given array into sorted order using the given comparator.
        Parameters:
        self - the array to be sorted
        comparator - a Comparator used for the comparison
        Returns:
        the sorted array
        Since:
        1.5.5
      • sort

        public static <T> T[] sort​(T[] self,
                                   boolean mutate,
                                   java.util.Comparator<T> comparator)
        Modifies this array so that its elements are in sorted order as determined by the given comparator. If mutate is true, the array is sorted in place and returned. Otherwise, a new sorted array is returned and the original array remains unchanged.
         def orig = ["hello","hi","Hey"] as String[]
         def sorted = orig.sort(false, String.CASE_INSENSITIVE_ORDER)
         assert orig == ["hello","hi","Hey"] as String[]
         assert sorted == ["hello","Hey","hi"] as String[]
         orig.sort(true, String.CASE_INSENSITIVE_ORDER)
         assert orig == ["hello","Hey","hi"] as String[]
         
        Parameters:
        self - the array containing elements to be sorted
        mutate - false will always cause a new array to be created, true will mutate arrays in place
        comparator - a Comparator used for the comparison
        Returns:
        a sorted array
        Since:
        1.8.1
      • sort

        public static <T> java.util.Iterator<T> sort​(java.util.Iterator<T> self,
                                                     Closure closure)
        Sorts the given iterator items into a sorted iterator using the Closure to determine the correct ordering. The original iterator will be fully processed after the method call.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
        Parameters:
        self - the Iterator to be sorted
        closure - a Closure used to determine the correct ordering
        Returns:
        the sorted items as an Iterator
        Since:
        1.5.5
      • sort

        public static <T> T[] sort​(T[] self,
                                   Closure closure)
        Sorts the elements from this array into a newly created array using the Closure to determine the correct ordering.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
        Parameters:
        self - the array containing the elements to be sorted
        closure - a Closure used to determine the correct ordering
        Returns:
        the sorted array
        Since:
        1.5.5
      • sort

        public static <T> T[] sort​(T[] self,
                                   boolean mutate,
                                   Closure closure)
        Modifies this array so that its elements are in sorted order using the Closure to determine the correct ordering. If mutate is false, a new array is returned and the original array remains unchanged. Otherwise, the original array is sorted in place and returned.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
         def orig = ["hello","hi","Hey"] as String[]
         def sorted = orig.sort(false) { it.size() }
         assert orig == ["hello","hi","Hey"] as String[]
         assert sorted == ["hi","Hey","hello"] as String[]
         orig.sort(true) { it.size() }
         assert orig == ["hi","Hey","hello"] as String[]
         
        Parameters:
        self - the array to be sorted
        mutate - false will always cause a new array to be created, true will mutate arrays in place
        closure - a Closure used to determine the correct ordering
        Returns:
        the sorted array
        Since:
        1.8.1
      • sort

        public static <T> java.util.List<T> sort​(java.util.Collection<T> self,
                                                 Closure closure)
        Sorts this Collection using the given Closure to determine the correct ordering. If the Collection is a List, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Collection unchanged.

        If the Closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
        assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { it.length() }
        assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { a, b -> a.length() <=> b.length() }
        Parameters:
        self - a Collection to be sorted
        closure - a 1 or 2 arg Closure used to determine the correct ordering
        Returns:
        a newly created sorted List
        Since:
        1.0
        See Also:
        sort(Collection, boolean, Closure)
      • sort

        public static <T> java.util.List<T> sort​(java.util.Collection<T> self,
                                                 boolean mutate,
                                                 Closure closure)
        Sorts this Collection using the given Closure to determine the correct ordering. If the Collection is a List and mutate is true, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Collection unchanged.

        If the closure has two parameters it is used like a traditional Comparator. I.e. it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.
        assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { it.length() }
        assert ["hi","hey","hello"] == ["hello","hi","hey"].sort { a, b -> a.length() <=> b.length() }
         def orig = ["hello","hi","Hey"]
         def sorted = orig.sort(false) { it.toUpperCase() }
         assert orig == ["hello","hi","Hey"]
         assert sorted == ["hello","Hey","hi"]
         
        Parameters:
        self - a Collection to be sorted
        mutate - false will always cause a new list to be created, true will mutate lists in place
        closure - a 1 or 2 arg Closure used to determine the correct ordering
        Returns:
        a newly created sorted List
        Since:
        1.8.1
      • sort

        public static <T> java.util.SortedSet<T> sort​(java.util.SortedSet<T> self)
        Avoids doing unnecessary work when sorting an already sorted set (i.e. an identity function for an already sorted set).
        Parameters:
        self - an already sorted set
        Returns:
        the set
        Since:
        1.0
      • sort

        public static <K,​V> java.util.SortedMap<K,​V> sort​(java.util.SortedMap<K,​V> self)
        Avoids doing unnecessary work when sorting an already sorted map (i.e. an identity function for an already sorted map).
        Parameters:
        self - an already sorted map
        Returns:
        the map
        Since:
        1.8.1
      • pop

        public static <T> T pop​(java.util.List<T> self)
        Removes the last item from the List. Using add() and pop() is similar to push and pop on a Stack.
        def list = ["a", false, 2]
         assert list.pop() == 2
         assert list == ["a", false]
        Parameters:
        self - a List
        Returns:
        the item removed from the List
        Throws:
        java.util.NoSuchElementException - if the list is empty and you try to pop() it.
        Since:
        1.0
      • putAll

        public static <K,​V> java.util.Map<K,​V> putAll​(java.util.Map<K,​V> self,
                                                                  java.util.Collection<java.util.Map.Entry<K,​V>> entries)
        Provides an easy way to append multiple Map.Entry values to a Map.
        Parameters:
        self - a Map
        entries - a Collection of Map.Entry items to be added to the Map.
        Returns:
        the same map, after the items have been added to it.
        Since:
        1.6.1
      • plus

        public static <K,​V> java.util.Map<K,​V> plus​(java.util.Map<K,​V> self,
                                                                java.util.Collection<java.util.Map.Entry<K,​V>> entries)
        Returns a new Map containing all entries from self and entries, giving precedence to entries. Any keys appearing in both Maps will appear in the resultant map with values from the entries operand. If self map is one of TreeMap, LinkedHashMap, Hashtable or Properties, the returned Map will preserve that type, otherwise a HashMap will be returned.

        Parameters:
        self - a Map
        entries - a Collection of Map.Entry items to be added to the Map.
        Returns:
        a new Map containing all key, value pairs from self and entries
        Since:
        1.6.1
      • push

        public static <T> boolean push​(java.util.List<T> self,
                                       T value)
        Appends an item to the List. Synonym for add().
        def list = [3, 4, 2]
         list.push("x")
         assert list == [3, 4, 2, "x"]
        Parameters:
        self - a List
        value - element to be appended to this list.
        Returns:
        true (as per the general contract of the Collection.add method).
        Throws:
        java.util.NoSuchElementException - if the list is empty and you try to pop() it.
        Since:
        1.5.5
      • last

        public static <T> T last​(java.util.List<T> self)
        Returns the last item from the List.
         def list = [3, 4, 2]
         assert list.last() == 2
         // check original is unaltered
         assert list == [3, 4, 2]
         
        Parameters:
        self - a List
        Returns:
        the last item from the List
        Throws:
        java.util.NoSuchElementException - if the list is empty and you try to access the last() item.
        Since:
        1.5.5
      • last

        public static <T> T last​(java.lang.Iterable<T> self)
        Returns the last item from the Iterable.
         def set = [3, 4, 2] as LinkedHashSet
         assert set.last() == 2
         // check original unaltered
         assert set == [3, 4, 2] as Set
         
        The first element returned by the Iterable's iterator is returned. If the Iterable doesn't guarantee a defined order it may appear like a random element is returned.
        Parameters:
        self - an Iterable
        Returns:
        the first item from the Iterable
        Throws:
        java.util.NoSuchElementException - if the Iterable is empty and you try to access the last() item.
        Since:
        1.8.7
      • last

        public static <T> T last​(T[] self)
        Returns the last item from the array.
         def array = [3, 4, 2].toArray()
         assert array.last() == 2
         
        Parameters:
        self - an array
        Returns:
        the last item from the array
        Throws:
        java.util.NoSuchElementException - if the array is empty and you try to access the last() item.
        Since:
        1.7.3
      • first

        public static <T> T first​(java.util.List<T> self)
        Returns the first item from the List.
         def list = [3, 4, 2]
         assert list.first() == 3
         // check original is unaltered
         assert list == [3, 4, 2]
         
        Parameters:
        self - a List
        Returns:
        the first item from the List
        Throws:
        java.util.NoSuchElementException - if the list is empty and you try to access the first() item.
        Since:
        1.5.5
      • first

        public static <T> T first​(java.lang.Iterable<T> self)
        Returns the first item from the Iterable.
         def set = [3, 4, 2] as LinkedHashSet
         assert set.first() == 3
         // check original is unaltered
         assert set == [3, 4, 2] as Set
         
        The first element returned by the Iterable's iterator is returned. If the Iterable doesn't guarantee a defined order it may appear like a random element is returned.
        Parameters:
        self - an Iterable
        Returns:
        the first item from the Iterable
        Throws:
        java.util.NoSuchElementException - if the Iterable is empty and you try to access the first() item.
        Since:
        1.8.7
      • first

        public static <T> T first​(T[] self)
        Returns the first item from the array.
         def array = [3, 4, 2].toArray()
         assert array.first() == 3
         
        Parameters:
        self - an array
        Returns:
        the first item from the array
        Throws:
        java.util.NoSuchElementException - if the array is empty and you try to access the first() item.
        Since:
        1.7.3
      • head

        public static <T> T head​(java.util.List<T> self)
        Returns the first item from the List.
        def list = [3, 4, 2]
         assert list.head() == 3
         assert list == [3, 4, 2]
        Parameters:
        self - a List
        Returns:
        the first item from the List
        Throws:
        java.util.NoSuchElementException - if the list is empty and you try to access the head() item.
        Since:
        1.5.5
      • head

        public static <T> T head​(T[] self)
        Returns the first item from the Object array.
        def array = [3, 4, 2].toArray()
         assert array.head() == 3
        Parameters:
        self - an Object array
        Returns:
        the first item from the Object array
        Throws:
        java.util.NoSuchElementException - if the array is empty and you try to access the head() item.
        Since:
        1.7.3
      • tail

        public static <T> java.util.List<T> tail​(java.util.List<T> self)
        Returns the items from the List excluding the first item.
        def list = [3, 4, 2]
         assert list.tail() == [4, 2]
         assert list == [3, 4, 2]
        Parameters:
        self - a List
        Returns:
        a list without its first element
        Throws:
        java.util.NoSuchElementException - if the list is empty and you try to access the tail() item.
        Since:
        1.5.6
      • tail

        public static <T> T[] tail​(T[] self)
        Returns the items from the Object array excluding the first item.
             String[] strings = ["a", "b", "c"]
             def result = strings.tail()
             assert strings.class.componentType == String
         
        Parameters:
        self - an Object array
        Returns:
        an Object array without its first element
        Throws:
        java.util.NoSuchElementException - if the list is empty and you try to access the tail() item.
        Since:
        1.7.3
      • take

        public static <T> java.util.List<T> take​(java.util.List<T> self,
                                                 int num)
        Returns the first num elements from the head of this list.
         def strings = [ 'a', 'b', 'c' ]
         assert strings.take( 0 ) == []
         assert strings.take( 2 ) == [ 'a', 'b' ]
         assert strings.take( 5 ) == [ 'a', 'b', 'c' ]
         
        Similar to take(Iterable, int) except that it attempts to preserve the type of the original list.
        Parameters:
        self - the original list
        num - the number of elements to take from this list
        Returns:
        a list consisting of the first num elements of this list, or else the whole list if it has less then num elements.
        Since:
        1.8.1
      • take

        public static <T> T[] take​(T[] self,
                                   int num)
        Returns the first num elements from the head of this array.
         String[] strings = [ 'a', 'b', 'c' ]
         assert strings.take( 0 ) == [] as String[]
         assert strings.take( 2 ) == [ 'a', 'b' ] as String[]
         assert strings.take( 5 ) == [ 'a', 'b', 'c' ] as String[]
         
        Parameters:
        self - the original array
        num - the number of elements to take from this array
        Returns:
        an array consisting of the first num elements of this array, or else the whole array if it has less then num elements.
        Since:
        1.8.1
      • take

        public static <T> java.util.List<T> take​(java.lang.Iterable<T> self,
                                                 int num)
        Returns the first num elements from the head of this Iterable.
         class AbcIterable implements Iterable {
             Iterator iterator() { "abc".iterator() }
         }
         def abc = new AbcIterable()
         assert abc.take(0) == []
         assert abc.take(1) == ['a']
         assert abc.take(3) == ['a', 'b', 'c']
         assert abc.take(5) == ['a', 'b', 'c']
         
        Parameters:
        self - the original Iterable
        num - the number of elements to take from this Iterable
        Returns:
        a List consisting of the first num elements from this Iterable, or else all the elements from the Iterable if it has less then num elements.
        Since:
        1.8.7
      • take

        public static <K,​V> java.util.Map<K,​V> take​(java.util.Map<K,​V> self,
                                                                int num)
        Returns a new map containing the first num elements from the head of this map. If the map instance does not have ordered keys, then this function could return a random num entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.
         def strings = [ 'a':10, 'b':20, 'c':30 ]
         assert strings.take( 0 ) == [:]
         assert strings.take( 2 ) == [ 'a':10, 'b':20 ]
         assert strings.take( 5 ) == [ 'a':10, 'b':20, 'c':30 ]
         
        Parameters:
        self - the original map
        num - the number of elements to take from this map
        Returns:
        a new map consisting of the first num elements of this map, or else the whole map if it has less then num elements.
        Since:
        1.8.1
      • take

        public static <T> java.util.Iterator<T> take​(java.util.Iterator<T> self,
                                                     int num)
        Returns an iterator of up to the first num elements from this iterator. The original iterator is stepped along by num elements.
         def a = 0
         def iter = [ hasNext:{ true }, next:{ a++ } ] as Iterator
         def iteratorCompare( Iterator a, List b ) {
             a.collect { it } == b
         }
         assert iteratorCompare( iter.take( 0 ), [] )
         assert iteratorCompare( iter.take( 2 ), [ 0, 1 ] )
         assert iteratorCompare( iter.take( 5 ), [ 2, 3, 4, 5, 6 ] )
         
        Parameters:
        self - the Iterator
        num - the number of elements to take from this iterator
        Returns:
        an iterator consisting of up to the first num elements of this iterator.
        Since:
        1.8.1
      • take

        public static java.lang.CharSequence take​(java.lang.CharSequence self,
                                                  int num)
        Returns the first num elements from this CharSequence.
             def text = "Groovy"
             assert text.take( 0 ) == ''
             assert text.take( 2 ) == 'Gr'
             assert text.take( 7 ) == 'Groovy'
         
        Parameters:
        self - the original CharSequence
        num - the number of chars to take from this CharSequence
        Returns:
        a CharSequence consisting of the first num chars, or else the whole CharSequence if it has less then num elements.
        Since:
        1.8.1
      • drop

        public static <T> java.util.List<T> drop​(java.util.List<T> self,
                                                 int num)
        Drops the given number of elements from the head of this list if they are available.
         def strings = [ 'a', 'b', 'c' ]
         assert strings.drop( 0 ) == [ 'a', 'b', 'c' ]
         assert strings.drop( 2 ) == [ 'c' ]
         assert strings.drop( 5 ) == []
         
        Similar to drop(Iterable, int) except that it attempts to preserve the type of the original list.
        Parameters:
        self - the original list
        num - the number of elements to drop from this list
        Returns:
        a list consisting of all elements of this list except the first num ones, or else the empty list, if this list has less than num elements.
        Since:
        1.8.1
      • drop

        public static <T> java.util.List<T> drop​(java.lang.Iterable<T> self,
                                                 int num)
        Drops the given number of elements from the head of this Iterable.
         class AbcIterable implements Iterable {
             Iterator iterator() { "abc".iterator() }
         }
         def abc = new AbcIterable()
         assert abc.drop(0) == ['a', 'b', 'c']
         assert abc.drop(1) == ['b', 'c']
         assert abc.drop(3) == []
         assert abc.drop(5) == []
         
        Parameters:
        self - the original Iterable
        num - the number of elements to drop from this Iterable
        Returns:
        a List consisting of all the elements of this Iterable minus the first num elements, or an empty list if it has less then num elements.
        Since:
        1.8.7
      • drop

        public static <T> T[] drop​(T[] self,
                                   int num)
        Drops the given number of elements from the head of this array if they are available.
         String[] strings = [ 'a', 'b', 'c' ]
         assert strings.drop( 0 ) == [ 'a', 'b', 'c' ] as String[]
         assert strings.drop( 2 ) == [ 'c' ] as String[]
         assert strings.drop( 5 ) == [] as String[]
         
        Parameters:
        self - the original array
        num - the number of elements to drop from this array
        Returns:
        an array consisting of all elements of this array except the first num ones, or else the empty array, if this array has less than num elements.
        Since:
        1.8.1
      • drop

        public static <K,​V> java.util.Map<K,​V> drop​(java.util.Map<K,​V> self,
                                                                int num)
        Drops the given number of key/value pairs from the head of this map if they are available.
         def strings = [ 'a':10, 'b':20, 'c':30 ]
         assert strings.drop( 0 ) == [ 'a':10, 'b':20, 'c':30 ]
         assert strings.drop( 2 ) == [ 'c':30 ]
         assert strings.drop( 5 ) == [:]
         
        If the map instance does not have ordered keys, then this function could drop a random num entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.
        Parameters:
        self - the original map
        num - the number of elements to drop from this map
        Returns:
        a map consisting of all key/value pairs of this map except the first num ones, or else the empty map, if this map has less than num elements.
        Since:
        1.8.1
      • drop

        public static <T> java.util.Iterator<T> drop​(java.util.Iterator<T> self,
                                                     int num)
        Drops the given number of elements from the head of this iterator if they are available. The original iterator is stepped along by num elements.
         def iteratorCompare( Iterator a, List b ) {
             a.collect { it } == b
         }
         def iter = [ 1, 2, 3, 4, 5 ].listIterator()
         assert iteratorCompare( iter.drop( 0 ), [ 1, 2, 3, 4, 5 ] )
         iter = [ 1, 2, 3, 4, 5 ].listIterator()
         assert iteratorCompare( iter.drop( 2 ), [ 3, 4, 5 ] )
         iter = [ 1, 2, 3, 4, 5 ].listIterator()
         assert iteratorCompare( iter.drop( 5 ), [] )
         
        Parameters:
        self - the original iterator
        num - the number of elements to drop from this iterator
        Returns:
        The iterator stepped along by num elements if they exist.
        Since:
        1.8.1
      • drop

        public static java.lang.CharSequence drop​(java.lang.CharSequence self,
                                                  int num)
        Drops the given number of chars from the head of this CharSequence if they are available.
             def text = "Groovy"
             assert text.drop( 0 ) == 'Groovy'
             assert text.drop( 2 ) == 'oovy'
             assert text.drop( 7 ) == ''
         
        Parameters:
        self - the original CharSequence
        num - the number of characters to drop from this iterator
        Returns:
        a CharSequence consisting of all characters except the first num ones, or else an empty String, if this CharSequence has less than num characters.
        Since:
        1.8.1
      • dropWhile

        public static <T> java.util.List<T> dropWhile​(java.util.List<T> self,
                                                      Closure<?> condition)
        Returns a suffix of this List where elements are dropped from the front while the given Closure evaluates to true. Similar to dropWhile(Iterable, groovy.lang.Closure) except that it attempts to preserve the type of the original list.
         def nums = [ 1, 3, 2 ]
         assert nums.dropWhile{ it < 4 } == []
         assert nums.dropWhile{ it < 3 } == [ 3, 2 ]
         assert nums.dropWhile{ it != 2 } == [ 2 ]
         assert nums.dropWhile{ it == 0 } == [ 1, 3, 2 ]
         
        Parameters:
        self - the original list
        condition - the closure that must evaluate to true to continue dropping elements
        Returns:
        the shortest suffix of the given List such that the given closure condition evaluates to true for each element dropped from the front of the List
        Since:
        1.8.7
      • dropWhile

        public static <T> java.util.List<T> dropWhile​(java.lang.Iterable<T> self,
                                                      Closure<?> condition)
        Returns a suffix of this Iterable where elements are dropped from the front while the given closure evaluates to true.
         class AbcIterable implements Iterable {
             Iterator iterator() { "abc".iterator() }
         }
         def abc = new AbcIterable()
         assert abc.dropWhile{ it < 'b' } == ['b', 'c']
         assert abc.dropWhile{ it <= 'b' } == ['c']
         
        Parameters:
        self - an Iterable
        condition - the closure that must evaluate to true to continue dropping elements
        Returns:
        the shortest suffix of the given Iterable such that the given closure condition evaluates to true for each element dropped from the front of the Iterable
        Since:
        1.8.7
      • dropWhile

        public static <K,​V> java.util.Map<K,​V> dropWhile​(java.util.Map<K,​V> self,
                                                                     Closure<?> condition)
        Create a suffix of the given Map by dropping as many entries as possible from the front of the original Map such that calling the given closure condition evaluates to true when passed each of the dropped entries (or key/value pairs).
         def shopping = [milk:1, bread:2, chocolate:3]
         assert shopping.takeWhile{ it.key.size() < 6 } == [milk:1, bread:2]
         assert shopping.takeWhile{ it.value % 2 } == [milk:1]
         assert shopping.takeWhile{ k, v -> k.size() + v <= 7 } == [milk:1, bread:2]
         
        If the map instance does not have ordered keys, then this function could appear to drop random entries. Groovy by default uses LinkedHashMap, so this shouldn't be an issue in the main.
        Parameters:
        self - a Map
        condition - a 1 (or 2) arg Closure that must evaluate to true for the entry (or key and value) to continue dropping elements
        Returns:
        the shortest suffix of the given Map such that the given closure condition evaluates to true for each element dropped from the front of the Map
        Since:
        1.8.7
      • dropWhile

        public static <T> T[] dropWhile​(T[] self,
                                        Closure<?> condition)
        Create a suffix of the given array by dropping as many elements as possible from the front of the original array such that calling the given closure condition evaluates to true when passed each of the dropped elements.
         def nums = [ 1, 3, 2 ] as Integer[]
         assert nums.dropWhile{ it <= 3 } == [ ] as Integer[]
         assert nums.dropWhile{ it < 3 } == [ 3, 2 ] as Integer[]
         assert nums.dropWhile{ it != 2 } == [ 2 ] as Integer[]
         assert nums.dropWhile{ it == 0 } == [ 1, 3, 2 ] as Integer[]
         
        Parameters:
        self - the original array
        condition - the closure that must evaluate to true to continue dropping elements
        Returns:
        the shortest suffix of the given array such that the given closure condition evaluates to true for each element dropped from the front of the array
        Since:
        1.8.7
      • dropWhile

        public static <T> java.util.Iterator<T> dropWhile​(java.util.Iterator<T> self,
                                                          Closure<?> condition)
        Creates an Iterator that returns a suffix of the elements from an original Iterator. As many elements as possible are dropped from the front of the original Iterator such that calling the given closure condition evaluates to true when passed each of the dropped elements.

         def a = 0
         def iter = [ hasNext:{ a < 10 }, next:{ a++ } ] as Iterator
         assert [].iterator().dropWhile{ it < 3 }.toList() == []
         assert [1, 2, 3, 4, 5].iterator().dropWhile{ it < 3 }.toList() == [ 3, 4, 5 ]
         assert iter.dropWhile{ it < 5 }.toList() == [ 5, 6, 7, 8, 9 ]
         
        Parameters:
        self - the Iterator
        condition - the closure that must evaluate to true to continue dropping elements
        Returns:
        the shortest suffix of elements from the given Iterator such that the given closure condition evaluates to true for each element dropped from the front of the Iterator
        Since:
        1.8.7
      • asList

        public static <T> java.util.List<T> asList​(java.util.Collection<T> self)
        Converts this Collection to a List. Returns the original Collection if it is already a List.

        Example usage:

        assert new HashSet().asList() instanceof List
        Parameters:
        self - a collection to be converted into a List
        Returns:
        a newly created List if this collection is not already a List
        Since:
        1.0
      • asBoolean

        public static boolean asBoolean​(java.lang.Object object)
        Coerce an object instance to a boolean value. An object is coerced to true if it's not null, to false if it is null.
        Parameters:
        object - the object to coerce
        Returns:
        the boolean value
        Since:
        1.7.0
      • asBoolean

        public static boolean asBoolean​(java.lang.Boolean bool)
        Coerce an Boolean instance to a boolean value.
        Parameters:
        bool - the Boolean
        Returns:
        the boolean value
        Since:
        1.7.0
      • asBoolean

        public static boolean asBoolean​(java.util.regex.Matcher matcher)
        Coerce a Matcher instance to a boolean value.
        Parameters:
        matcher - the matcher
        Returns:
        the boolean value
        Since:
        1.7.0
      • asBoolean

        public static boolean asBoolean​(java.util.Collection collection)
        Coerce a collection instance to a boolean value. A collection is coerced to false if it's empty, and to true otherwise.
        assert [1,2].asBoolean() == true
        assert [].asBoolean() == false
        Parameters:
        collection - the collection
        Returns:
        the boolean value
        Since:
        1.7.0
      • asBoolean

        public static boolean asBoolean​(java.util.Map map)
        Coerce a map instance to a boolean value. A map is coerced to false if it's empty, and to true otherwise.
        assert [:] as Boolean == false
         assert [a:2] as Boolean == true
        Parameters:
        map - the map
        Returns:
        the boolean value
        Since:
        1.7.0
      • asBoolean

        public static boolean asBoolean​(java.util.Iterator iterator)
        Coerce an iterator instance to a boolean value. An iterator is coerced to false if there are no more elements to iterate over, and to true otherwise.
        Parameters:
        iterator - the iterator
        Returns:
        the boolean value
        Since:
        1.7.0
      • asBoolean

        public static boolean asBoolean​(java.util.Enumeration enumeration)
        Coerce an enumeration instance to a boolean value. An enumeration is coerced to false if there are no more elements to enumerate, and to true otherwise.
        Parameters:
        enumeration - the enumeration
        Returns:
        the boolean value
        Since:
        1.7.0
      • asBoolean

        public static boolean asBoolean​(java.lang.CharSequence string)
        Coerce a string (an instance of CharSequence) to a boolean value. A string is coerced to false if it is of length 0, and to true otherwise.
        Parameters:
        string - the character sequence
        Returns:
        the boolean value
        Since:
        1.7.0
      • asBoolean

        public static boolean asBoolean​(java.lang.Object[] array)
        Coerce an Object array to a boolean value. An Object array is false if the array is of length 0. and to true otherwise
        Parameters:
        array - the array
        Returns:
        the boolean value
        Since:
        1.7.0
      • asBoolean

        public static boolean asBoolean​(byte[] array)
        Coerces a byte array to a boolean value. A byte array is false if the array is of length 0, and true otherwise.
        Parameters:
        array - an array
        Returns:
        the array's boolean value
        Since:
        1.7.4
      • asBoolean

        public static boolean asBoolean​(short[] array)
        Coerces a short array to a boolean value. A short array is false if the array is of length 0, and true otherwise.
        Parameters:
        array - an array
        Returns:
        the array's boolean value
        Since:
        1.7.4
      • asBoolean

        public static boolean asBoolean​(int[] array)
        Coerces an int array to a boolean value. An int array is false if the array is of length 0, and true otherwise.
        Parameters:
        array - an array
        Returns:
        the array's boolean value
        Since:
        1.7.4
      • asBoolean

        public static boolean asBoolean​(long[] array)
        Coerces a long array to a boolean value. A long array is false if the array is of length 0, and true otherwise.
        Parameters:
        array - an array
        Returns:
        the array's boolean value
        Since:
        1.7.4
      • asBoolean

        public static boolean asBoolean​(float[] array)
        Coerces a float array to a boolean value. A float array is false if the array is of length 0, and true otherwise.
        Parameters:
        array - an array
        Returns:
        the array's boolean value
        Since:
        1.7.4
      • asBoolean

        public static boolean asBoolean​(double[] array)
        Coerces a double array to a boolean value. A double array is false if the array is of length 0, and true otherwise.
        Parameters:
        array - an array
        Returns:
        the array's boolean value
        Since:
        1.7.4
      • asBoolean

        public static boolean asBoolean​(boolean[] array)
        Coerces a boolean array to a boolean value. A boolean array is false if the array is of length 0, and true otherwise.
        Parameters:
        array - an array
        Returns:
        the array's boolean value
        Since:
        1.7.4
      • asBoolean

        public static boolean asBoolean​(char[] array)
        Coerces a char array to a boolean value. A char array is false if the array is of length 0, and true otherwise.
        Parameters:
        array - an array
        Returns:
        the array's boolean value
        Since:
        1.7.4
      • asBoolean

        public static boolean asBoolean​(java.lang.Character character)
        Coerce a character to a boolean value. A character is coerced to false if it's character value is equal to 0, and to true otherwise.
        Parameters:
        character - the character
        Returns:
        the boolean value
        Since:
        1.7.0
      • asBoolean

        public static boolean asBoolean​(java.lang.Number number)
        Coerce a number to a boolean value. A number is coerced to false if its double value is equal to 0, and to true otherwise, and to true otherwise.
        Parameters:
        number - the number
        Returns:
        the boolean value
        Since:
        1.7.0
      • asType

        public static <T> T asType​(java.util.Collection col,
                                   java.lang.Class<T> clazz)
        Converts the given collection to another type. A default concrete type is used for List, Set, or SortedSet. If the given type has a constructor taking a collection, that is used. Otherwise, the call is deferred to {link #asType(Object,Class)}. If this collection is already of the given type, the same instance is returned.
        Parameters:
        col - a collection
        clazz - the desired class
        Returns:
        the object resulting from this type conversion
        Since:
        1.0
        See Also:
        asType(java.lang.Object, java.lang.Class)
      • asType

        public static <T> T asType​(java.lang.Object[] ary,
                                   java.lang.Class<T> clazz)
        Converts the given array to either a List, Set, or SortedSet. If the given class is something else, the call is deferred to {link #asType(Object,Class)}.
        Parameters:
        ary - an array
        clazz - the desired class
        Returns:
        the object resulting from this type conversion
        Since:
        1.5.1
        See Also:
        asType(java.lang.Object, java.lang.Class)
      • asType

        public static <T> T asType​(Closure cl,
                                   java.lang.Class<T> clazz)
        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.
        Parameters:
        cl - the implementation of the single method
        clazz - the target type
        Returns:
        a Proxy of the given type which wraps this closure.
        Since:
        1.0
      • asType

        public static <T> T asType​(java.util.Map map,
                                   java.lang.Class<T> clazz)
        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.
        Parameters:
        map - this map
        clazz - the target type
        Returns:
        a Proxy of the given type, which defers calls to this map's elements.
        Since:
        1.0
      • reverse

        public static <T> java.util.List<T> reverse​(java.util.List<T> self)
        Creates a new List with the identical contents to this list but in reverse order.
         def list = ["a", 4, false]
         assert list.reverse() == [false, 4, "a"]
         assert list == ["a", 4, false]
         
        Parameters:
        self - a List
        Returns:
        a reversed List
        Since:
        1.0
        See Also:
        reverse(List, boolean)
      • reverse

        public static <T> java.util.List<T> reverse​(java.util.List<T> self,
                                                    boolean mutate)
        Reverses the elements in a list. If mutate is true, the original list is modified in place and returned. Otherwise, a new list containing the reversed items is produced.
         def list = ["a", 4, false]
         assert list.reverse(false) == [false, 4, "a"]
         assert list == ["a", 4, false]
         assert list.reverse(true) == [false, 4, "a"]
         assert list == [false, 4, "a"]
         
        Parameters:
        self - a List
        mutate - true if the list itself should be reversed in place and returned, false if a new list should be created
        Returns:
        a reversed List
        Since:
        1.8.1
      • reverse

        public static <T> T[] reverse​(T[] self)
        Creates a new array containing items which are the same as this array but in reverse order.
        Parameters:
        self - an array
        Returns:
        an array containing the reversed items
        Since:
        1.5.5
        See Also:
        reverse(Object[], boolean)
      • reverse

        public static <T> T[] reverse​(T[] self,
                                      boolean mutate)
        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.
        Parameters:
        self - an array
        mutate - true if the array itself should be reversed in place and returned, false if a new array should be created
        Returns:
        an array containing the reversed items
        Since:
        1.8.1
      • reverse

        public static <T> java.util.Iterator<T> reverse​(java.util.Iterator<T> 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.
        Parameters:
        self - an Iterator
        Returns:
        a reversed Iterator
        Since:
        1.5.5
      • multiply

        public static <T> java.util.List<T> multiply​(java.util.Collection<T> self,
                                                     java.lang.Number factor)
        Create a List composed of the elements of this list, repeated a certain number of times. Note that for non-primitive elements, multiple references to the same instance will be added.
        assert [1,2,3,1,2,3] == [1,2,3] * 2
        Parameters:
        self - a Collection
        factor - the number of times to append
        Returns:
        the multiplied list
        Since:
        1.0
      • intersect

        public static <T> java.util.Collection<T> intersect​(java.util.Collection<T> left,
                                                            java.util.Collection<T> right)
        Create a Collection composed of the intersection of both collections. Any elements that exist in both collections are added to the resultant collection.
        assert [4,5] == [1,2,3,4,5].intersect([4,5,6,7,8])
        Parameters:
        left - a Collection
        right - a Collection
        Returns:
        a Collection as an intersection of both collections
        Since:
        1.5.6
      • intersect

        public static <K,​V> java.util.Map<K,​V> intersect​(java.util.Map<K,​V> left,
                                                                     java.util.Map<K,​V> right)
        Create a Map composed of the intersection of both maps. Any entries that exist in both maps are added to the resultant map.
        assert [4:4,5:5] == [1:1,2:2,3:3,4:4,5:5].intersect([4:4,5:5,6:6,7:7,8:8])
        assert [1: 1, 2: 2, 3: 3, 4: 4].intersect( [1: 1.0, 2: 2, 5: 5] ) == [1:1, 2:2]
        Parameters:
        left - a map
        right - a map
        Returns:
        a Map as an intersection of both maps
        Since:
        1.7.4
      • disjoint

        public static boolean disjoint​(java.util.Collection left,
                                       java.util.Collection right)
        Returns true if the intersection of two collections is empty.
        assert [1,2,3].disjoint([3,4,5]) == false
        assert [1,2].disjoint([3,4]) == true
        Parameters:
        left - a Collection
        right - a Collection
        Returns:
        boolean true if the intersection of two collections is empty, false otherwise.
        Since:
        1.0
      • equals

        public static boolean equals​(int[] left,
                                     int[] right)
        Compare the contents of this array to the contents of the given array.
        Parameters:
        left - an int array
        right - the array being compared
        Returns:
        true if the contents of both arrays are equal.
        Since:
        1.5.0
      • equals

        public static boolean equals​(java.lang.Object[] left,
                                     java.util.List right)
        Determines if the contents of this array are equal to the contents of the given list, in the same order. This returns false if either collection is null.
        Parameters:
        left - an array
        right - the List being compared
        Returns:
        true if the contents of both collections are equal
        Since:
        1.5.0
      • equals

        public static boolean equals​(java.util.List left,
                                     java.lang.Object[] right)
        Determines if the contents of this list are equal to the contents of the given array in the same order. This returns false if either collection is null.
        assert [1, "a"].equals( [ 1, "a" ] as Object[] )
        Parameters:
        left - a List
        right - the Object[] being compared to
        Returns:
        true if the contents of both collections are equal
        Since:
        1.5.0
      • equals

        public static boolean equals​(java.util.List left,
                                     java.util.List right)
        Compare the contents of two Lists. Order matters. If numbers exist in the Lists, then they are compared as numbers, for example 2 == 2L. If both lists are null, the result is true; otherwise if either list is null, the result is false.
        assert ["a", 2].equals(["a", 2])
         assert ![2, "a"].equals("a", 2)
         assert [2.0, "a"].equals(2L, "a") // number comparison at work
        Parameters:
        left - a List
        right - the List being compared to
        Returns:
        boolean true if the contents of both lists are identical, false otherwise.
        Since:
        1.0
      • equals

        public static <T> boolean equals​(java.util.Set<T> self,
                                         java.util.Set<T> other)
        Compare the contents of two Sets for equality using Groovy's coercion rules.

        Returns true if the two sets have the same size, and every member of the specified set is contained in this set (or equivalently, every member of this set is contained in the specified set). If numbers exist in the sets, then they are compared as numbers, for example 2 == 2L. If both sets are null, the result is true; otherwise if either set is null, the result is false. Example usage:

         Set s1 = ["a", 2]
         def s2 = [2, 'a'] as Set
         Set s3 = [3, 'a']
         def s4 = [2.0, 'a'] as Set
         def s5 = [2L, 'a'] as Set
         assert s1.equals(s2)
         assert !s1.equals(s3)
         assert s1.equals(s4)
         assert s1.equals(s5)
        Parameters:
        self - a Set
        other - the Set being compared to
        Returns:
        true if the contents of both sets are identical
        Since:
        1.8.0
      • equals

        public static boolean equals​(java.util.Map self,
                                     java.util.Map other)
        Compares two Maps treating coerced numerical values as identical.

        Example usage:

        assert [a:2, b:3] == [a:2L, b:3.0]
        Parameters:
        self - this Map
        other - the Map being compared to
        Returns:
        true if the contents of both maps are identical
        Since:
        1.8.0
      • minus

        public static <T> java.util.Set<T> minus​(java.util.Set<T> self,
                                                 java.util.Collection<?> removeMe)
        Create a Set composed of the elements of the first Set minus the elements of the given Collection.
        Parameters:
        self - a Set object
        removeMe - the items to remove from the Set
        Returns:
        the resulting Set
        Since:
        1.5.0
      • minus

        public static <T> java.util.Set<T> minus​(java.util.Set<T> self,
                                                 java.lang.Iterable<?> removeMe)
        Create a Set composed of the elements of the first Set minus the elements from the given Iterable.
        Parameters:
        self - a Set object
        removeMe - the items to remove from the Set
        Returns:
        the resulting Set
        Since:
        1.8.7
      • minus

        public static <T> java.util.Set<T> minus​(java.util.Set<T> self,
                                                 java.lang.Object removeMe)
        Create a Set composed of the elements of the first Set minus the given element.
        Parameters:
        self - a Set object
        removeMe - the element to remove from the Set
        Returns:
        the resulting Set
        Since:
        1.5.0
      • minus

        public static <T> T[] minus​(T[] self,
                                    java.lang.Iterable removeMe)
        Create an array composed of the elements of the first array minus the elements of the given Iterable.
        Parameters:
        self - an object array
        removeMe - a Collection of elements to remove
        Returns:
        an array with the supplied elements removed
        Since:
        1.5.5
      • minus

        public static <T> T[] minus​(T[] self,
                                    java.lang.Object[] removeMe)
        Create an array composed of the elements of the first array minus the elements of the given array.
        Parameters:
        self - an object array
        removeMe - an array of elements to remove
        Returns:
        an array with the supplied elements removed
        Since:
        1.5.5
      • minus

        public static <T> java.util.List<T> minus​(java.util.List<T> self,
                                                  java.util.Collection<?> removeMe)
        Create a List composed of the elements of the first list minus every occurrence of elements of the given Collection.
        assert [1, "a", true, true, false, 5.3] - [true, 5.3] == [1, "a", false]
        Parameters:
        self - a List
        removeMe - a Collection of elements to remove
        Returns:
        a List with the given elements removed
        Since:
        1.0
      • minus

        public static <T> java.util.List<T> minus​(java.util.List<T> self,
                                                  java.lang.Iterable<?> removeMe)
        Create a List composed of the elements of the first list minus every occurrence of elements of the given Iterable.
         class AbcIterable implements Iterable {
             Iterator iterator() { "abc".iterator() }
         }
         assert "backtrack".toList() - new AbcIterable() == ["k", "t", "r", "k"]
         
        Parameters:
        self - a List
        removeMe - an Iterable of elements to remove
        Returns:
        a List with the supplied elements removed
        Since:
        1.8.7
      • minus

        public static <T> java.util.List<T> minus​(java.util.List<T> self,
                                                  java.lang.Object removeMe)
        Create a new List composed of the elements of the first list minus every occurrence of the given element to remove.
        assert ["a", 5, 5, true] - 5 == ["a", true]
        Parameters:
        self - a List object
        removeMe - an element to remove from the list
        Returns:
        the resulting List with the given element removed
        Since:
        1.0
      • minus

        public static <T> T[] minus​(T[] self,
                                    java.lang.Object removeMe)
        Create a new object array composed of the elements of the first array minus the element to remove.
        Parameters:
        self - an object array
        removeMe - an element to remove from the array
        Returns:
        a new array with the operand removed
        Since:
        1.5.5
      • minus

        public static <K,​V> java.util.Map<K,​V> minus​(java.util.Map<K,​V> self,
                                                                 java.util.Map removeMe)
        Create a Map composed of the entries of the first map minus the entries of the given map.
        Parameters:
        self - a map object
        removeMe - the entries to remove from the map
        Returns:
        the resulting map
        Since:
        1.7.4
      • flatten

        public static java.util.Collection<?> flatten​(java.util.Collection<?> self)
        Flatten a collection. This collection and any nested arrays or collections have their contents (recursively) added to the new collection.
        assert [1,2,3,4,5] == [1,[2,3],[[4]],[],5].flatten()
        Parameters:
        self - a Collection to flatten
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • flatten

        public static java.util.Collection flatten​(java.lang.Object[] self)
        Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
        Parameters:
        self - an Array to flatten
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • flatten

        public static java.util.Collection flatten​(boolean[] self)
        Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
        Parameters:
        self - a boolean Array to flatten
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • flatten

        public static java.util.Collection flatten​(byte[] self)
        Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
        Parameters:
        self - a byte Array to flatten
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • flatten

        public static java.util.Collection flatten​(char[] self)
        Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
        Parameters:
        self - a char Array to flatten
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • flatten

        public static java.util.Collection flatten​(short[] self)
        Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
        Parameters:
        self - a short Array to flatten
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • flatten

        public static java.util.Collection flatten​(int[] self)
        Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
        Parameters:
        self - an int Array to flatten
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • flatten

        public static java.util.Collection flatten​(long[] self)
        Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
        Parameters:
        self - a long Array to flatten
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • flatten

        public static java.util.Collection flatten​(float[] self)
        Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
        Parameters:
        self - a float Array to flatten
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • flatten

        public static java.util.Collection flatten​(double[] self)
        Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
        Parameters:
        self - a double Array to flatten
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • flatten

        public static <T> java.util.Collection<T> flatten​(java.util.Collection<T> self,
                                                          Closure<? extends T> flattenUsing)
        Flatten a collection. This collection and any nested arrays or collections have their contents (recursively) added to the new collection. For any non-Array, non-Collection object which represents some sort of collective type, the supplied closure should yield the contained items; otherwise, the closure should just return any element which corresponds to a leaf.
        Parameters:
        self - a Collection
        flattenUsing - a closure to determine how to flatten non-Array, non-Collection elements
        Returns:
        a flattened Collection
        Since:
        1.6.0
      • leftShift

        public static <T> java.util.Collection<T> leftShift​(java.util.Collection<T> self,
                                                            T value)
        Overloads the left shift operator to provide an easy way to append objects to a Collection.
        def list = [1,2]
         list << 3
         assert list == [1,2,3]
        Parameters:
        self - a Collection
        value - an Object to be added to the collection.
        Returns:
        same collection, after the value was added to it.
        Since:
        1.0
      • leftShift

        public static <T> java.util.concurrent.BlockingQueue<T> leftShift​(java.util.concurrent.BlockingQueue<T> self,
                                                                          T value)
                                                                   throws java.lang.InterruptedException
        Overloads the left shift operator to provide an easy way to append objects to a BlockingQueue. In case of bounded queue the method will block till space in the queue become available
        def list = new java.util.concurrent.LinkedBlockingQueue ()
         list << 3 << 2 << 1
         assert list.iterator().collect{it} == [3,2,1]
        Parameters:
        self - a Collection
        value - an Object to be added to the collection.
        Returns:
        same collection, after the value was added to it.
        Throws:
        java.lang.InterruptedException
        Since:
        1.7.1
      • leftShift

        public static <K,​V> java.util.Map<K,​V> leftShift​(java.util.Map<K,​V> self,
                                                                     java.util.Map.Entry<K,​V> entry)
        Overloads the left shift operator to provide an easy way to append Map.Entry values to a Map.
        Parameters:
        self - a Map
        entry - a Map.Entry to be added to the Map.
        Returns:
        same map, after the value has been added to it.
        Since:
        1.6.0
      • leftShift

        public static <K,​V> java.util.Map<K,​V> leftShift​(java.util.Map<K,​V> self,
                                                                     java.util.Map<K,​V> other)
        Overloads the left shift operator to provide an easy way to put one maps entries into another map. This allows the compact syntax map1 << map2; otherwise it's just a synonym for putAll though it returns the original map rather than being a void method. Example usage:
        def map = [a:1, b:2]
         map << [c:3, d:4]
         assert map == [a:1, b:2, c:3, d:4]
        Parameters:
        self - a Map
        other - another Map whose entries should be added to the original Map.
        Returns:
        same map, after the values have been added to it.
        Since:
        1.7.2
      • leftShift

        public static java.lang.StringBuffer leftShift​(java.lang.String self,
                                                       java.lang.Object value)
        Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String.
        Parameters:
        self - a String
        value - an Object
        Returns:
        a StringBuffer built from this string
        Since:
        1.0
      • leftShift

        public static java.lang.StringBuilder leftShift​(java.lang.CharSequence self,
                                                        java.lang.Object value)
        Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a CharSequence.
        Parameters:
        self - a CharSequence
        value - an Object
        Returns:
        a StringBuilder built from this CharSequence
        Since:
        1.8.2
      • leftShift

        public static java.lang.StringBuilder leftShift​(java.lang.StringBuilder self,
                                                        java.lang.Object value)
        Overloads the left shift operator to provide syntactic sugar for appending to a StringBuilder.
        Parameters:
        self - a StringBuilder
        value - an Object
        Returns:
        the original StringBuilder
        Since:
        1.8.2
      • createStringWriter

        protected static java.io.StringWriter createStringWriter​(java.lang.String self)
      • createStringBufferWriter

        protected static StringBufferWriter createStringBufferWriter​(java.lang.StringBuffer self)
      • leftShift

        public static java.lang.StringBuffer leftShift​(java.lang.StringBuffer self,
                                                       java.lang.Object value)
        Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a StringBuffer.
        Parameters:
        self - a StringBuffer
        value - a value to append
        Returns:
        the StringBuffer on which this operation was invoked
        Since:
        1.0
      • leftShift

        public static java.io.Writer leftShift​(java.io.Writer self,
                                               java.lang.Object value)
                                        throws java.io.IOException
        Overloads the left shift operator to provide a mechanism to append values to a writer.
        Parameters:
        self - a Writer
        value - a value to append
        Returns:
        the writer on which this operation was invoked
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        1.0
      • leftShift

        public static java.lang.Number leftShift​(java.lang.Number self,
                                                 java.lang.Number operand)
        Implementation of the left shift operator for integral types. Non integral Number types throw UnsupportedOperationException.
        Parameters:
        self - a Number object
        operand - the shift distance by which to left shift the number
        Returns:
        the resulting number
        Since:
        1.5.0
      • rightShift

        public static java.lang.Number rightShift​(java.lang.Number self,
                                                  java.lang.Number operand)
        Implementation of the right shift operator for integral types. Non integral Number types throw UnsupportedOperationException.
        Parameters:
        self - a Number object
        operand - the shift distance by which to right shift the number
        Returns:
        the resulting number
        Since:
        1.5.0
      • rightShiftUnsigned

        public static java.lang.Number rightShiftUnsigned​(java.lang.Number self,
                                                          java.lang.Number operand)
        Implementation of the right shift (unsigned) operator for integral types. Non integral Number types throw UnsupportedOperationException.
        Parameters:
        self - a Number object
        operand - the shift distance by which to right shift (unsigned) the number
        Returns:
        the resulting number
        Since:
        1.5.0
      • write

        public static void write​(java.io.Writer self,
                                 Writable writable)
                          throws java.io.IOException
        A helper method so that dynamic dispatch of the writer.write(object) method will always use the more efficient Writable.writeTo(writer) mechanism if the object implements the Writable interface.
        Parameters:
        self - a Writer
        writable - an object implementing the Writable interface
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        1.0
      • leftShift

        public static java.io.Writer leftShift​(java.io.OutputStream self,
                                               java.lang.Object value)
                                        throws java.io.IOException
        Overloads the leftShift operator to provide an append mechanism to add values to a stream.
        Parameters:
        self - an OutputStream
        value - a value to append
        Returns:
        a Writer
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        1.0
      • leftShift

        public static void leftShift​(java.io.ObjectOutputStream self,
                                     java.lang.Object value)
                              throws java.io.IOException
        Overloads the leftShift operator to add objects to an ObjectOutputStream.
        Parameters:
        self - an ObjectOutputStream
        value - an object to write to the stream
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        1.5.0
      • leftShift

        public static java.io.OutputStream leftShift​(java.io.OutputStream self,
                                                     java.io.InputStream in)
                                              throws java.io.IOException
        Pipe an InputStream into an OutputStream for efficient stream copying.
        Parameters:
        self - stream on which to write
        in - stream to read from
        Returns:
        the outputstream itself
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        1.0
      • leftShift

        public static java.io.OutputStream leftShift​(java.io.OutputStream self,
                                                     byte[] value)
                                              throws java.io.IOException
        Overloads the leftShift operator to provide an append mechanism to add bytes to a stream.
        Parameters:
        self - an OutputStream
        value - a value to append
        Returns:
        an OutputStream
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Byte> getAt​(byte[] array,
                                                           Range range)
        Support the subscript operator with a range for a byte array
        Parameters:
        array - a byte array
        range - a range indicating the indices for the items to retrieve
        Returns:
        list of the retrieved bytes
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Character> getAt​(char[] array,
                                                                Range range)
        Support the subscript operator with a range for a char array
        Parameters:
        array - a char array
        range - a range indicating the indices for the items to retrieve
        Returns:
        list of the retrieved chars
        Since:
        1.5.0
      • getAt

        public static java.util.List<java.lang.Short> getAt​(short[] array,
                                                            Range range)
        Support the subscript operator with a range for a short array
        Parameters:
        array - a short array
        range - a range indicating the indices for the items to retrieve
        Returns:
        list of the retrieved shorts
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Integer> getAt​(int[] array,
                                                              Range range)
        Support the subscript operator with a range for an int array
        Parameters:
        array - an int array
        range - a range indicating the indices for the items to retrieve
        Returns:
        list of the ints at the given indices
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Long> getAt​(long[] array,
                                                           Range range)
        Support the subscript operator with a range for a long array
        Parameters:
        array - a long array
        range - a range indicating the indices for the items to retrieve
        Returns:
        list of the retrieved longs
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Float> getAt​(float[] array,
                                                            Range range)
        Support the subscript operator with a range for a float array
        Parameters:
        array - a float array
        range - a range indicating the indices for the items to retrieve
        Returns:
        list of the retrieved floats
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Double> getAt​(double[] array,
                                                             Range range)
        Support the subscript operator with a range for a double array
        Parameters:
        array - a double array
        range - a range indicating the indices for the items to retrieve
        Returns:
        list of the retrieved doubles
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Boolean> getAt​(boolean[] array,
                                                              Range range)
        Support the subscript operator with a range for a boolean array
        Parameters:
        array - a boolean array
        range - a range indicating the indices for the items to retrieve
        Returns:
        list of the retrieved booleans
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Byte> getAt​(byte[] array,
                                                           IntRange range)
        Support the subscript operator with an IntRange for a byte array
        Parameters:
        array - a byte array
        range - an IntRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved bytes
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Character> getAt​(char[] array,
                                                                IntRange range)
        Support the subscript operator with an IntRange for a char array
        Parameters:
        array - a char array
        range - an IntRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved chars
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Short> getAt​(short[] array,
                                                            IntRange range)
        Support the subscript operator with an IntRange for a short array
        Parameters:
        array - a short array
        range - an IntRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved shorts
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Integer> getAt​(int[] array,
                                                              IntRange range)
        Support the subscript operator with an IntRange for an int array
        Parameters:
        array - an int array
        range - an IntRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved ints
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Long> getAt​(long[] array,
                                                           IntRange range)
        Support the subscript operator with an IntRange for a long array
        Parameters:
        array - a long array
        range - an IntRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved longs
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Float> getAt​(float[] array,
                                                            IntRange range)
        Support the subscript operator with an IntRange for a float array
        Parameters:
        array - a float array
        range - an IntRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved floats
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Double> getAt​(double[] array,
                                                             IntRange range)
        Support the subscript operator with an IntRange for a double array
        Parameters:
        array - a double array
        range - an IntRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved doubles
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Boolean> getAt​(boolean[] array,
                                                              IntRange range)
        Support the subscript operator with an IntRange for a boolean array
        Parameters:
        array - a boolean array
        range - an IntRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved booleans
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Byte> getAt​(byte[] array,
                                                           ObjectRange range)
        Support the subscript operator with an ObjectRange for a byte array
        Parameters:
        array - a byte array
        range - an ObjectRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved bytes
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Character> getAt​(char[] array,
                                                                ObjectRange range)
        Support the subscript operator with an ObjectRange for a char array
        Parameters:
        array - a char array
        range - an ObjectRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved chars
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Short> getAt​(short[] array,
                                                            ObjectRange range)
        Support the subscript operator with an ObjectRange for a short array
        Parameters:
        array - a short array
        range - an ObjectRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved shorts
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Integer> getAt​(int[] array,
                                                              ObjectRange range)
        Support the subscript operator with an ObjectRange for an int array
        Parameters:
        array - an int array
        range - an ObjectRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved ints
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Long> getAt​(long[] array,
                                                           ObjectRange range)
        Support the subscript operator with an ObjectRange for a long array
        Parameters:
        array - a long array
        range - an ObjectRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved longs
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Float> getAt​(float[] array,
                                                            ObjectRange range)
        Support the subscript operator with an ObjectRange for a float array
        Parameters:
        array - a float array
        range - an ObjectRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved floats
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Double> getAt​(double[] array,
                                                             ObjectRange range)
        Support the subscript operator with an ObjectRange for a double array
        Parameters:
        array - a double array
        range - an ObjectRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved doubles
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Boolean> getAt​(boolean[] array,
                                                              ObjectRange range)
        Support the subscript operator with an ObjectRange for a byte array
        Parameters:
        array - a byte array
        range - an ObjectRange indicating the indices for the items to retrieve
        Returns:
        list of the retrieved bytes
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Byte> getAt​(byte[] array,
                                                           java.util.Collection indices)
        Support the subscript operator with a collection for a byte array
        Parameters:
        array - a byte array
        indices - a collection of indices for the items to retrieve
        Returns:
        list of the bytes at the given indices
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Character> getAt​(char[] array,
                                                                java.util.Collection indices)
        Support the subscript operator with a collection for a char array
        Parameters:
        array - a char array
        indices - a collection of indices for the items to retrieve
        Returns:
        list of the chars at the given indices
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Short> getAt​(short[] array,
                                                            java.util.Collection indices)
        Support the subscript operator with a collection for a short array
        Parameters:
        array - a short array
        indices - a collection of indices for the items to retrieve
        Returns:
        list of the shorts at the given indices
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Integer> getAt​(int[] array,
                                                              java.util.Collection indices)
        Support the subscript operator with a collection for an int array
        Parameters:
        array - an int array
        indices - a collection of indices for the items to retrieve
        Returns:
        list of the ints at the given indices
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Long> getAt​(long[] array,
                                                           java.util.Collection indices)
        Support the subscript operator with a collection for a long array
        Parameters:
        array - a long array
        indices - a collection of indices for the items to retrieve
        Returns:
        list of the longs at the given indices
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Float> getAt​(float[] array,
                                                            java.util.Collection indices)
        Support the subscript operator with a collection for a float array
        Parameters:
        array - a float array
        indices - a collection of indices for the items to retrieve
        Returns:
        list of the floats at the given indices
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Double> getAt​(double[] array,
                                                             java.util.Collection indices)
        Support the subscript operator with a collection for a double array
        Parameters:
        array - a double array
        indices - a collection of indices for the items to retrieve
        Returns:
        list of the doubles at the given indices
        Since:
        1.0
      • getAt

        public static java.util.List<java.lang.Boolean> getAt​(boolean[] array,
                                                              java.util.Collection indices)
        Support the subscript operator with a collection for a boolean array
        Parameters:
        array - a boolean array
        indices - a collection of indices for the items to retrieve
        Returns:
        list of the booleans at the given indices
        Since:
        1.0
      • getAt

        public static boolean getAt​(java.util.BitSet self,
                                    int index)
        Support the subscript operator for a Bitset
        Parameters:
        self - a BitSet
        index - index to retrieve
        Returns:
        value of the bit at the given index
        Since:
        1.5.0
        See Also:
        BitSet
      • getAt

        public static java.util.BitSet getAt​(java.util.BitSet self,
                                             IntRange range)
        Support retrieving a subset of a BitSet using a Range
        Parameters:
        self - a BitSet
        range - a Range defining the desired subset
        Returns:
        a new BitSet that represents the requested subset
        Since:
        1.5.0
        See Also:
        BitSet, IntRange
      • putAt

        public static void putAt​(java.util.BitSet self,
                                 IntRange range,
                                 boolean value)
        Support assigning a range of values with a single assignment statement.
        Parameters:
        self - a BitSet
        range - the range of values to set
        value - value
        Since:
        1.5.0
        See Also:
        BitSet, Range
      • putAt

        public static void putAt​(java.util.BitSet self,
                                 int index,
                                 boolean value)
        Support subscript-style assignment for a BitSet.
        Parameters:
        self - a BitSet
        index - index of the entry to set
        value - value
        Since:
        1.5.0
        See Also:
        BitSet
      • size

        public static int size​(boolean[] array)
        Allows arrays to behave similar to collections.
        Parameters:
        array - a boolean array
        Returns:
        the length of the array
        Since:
        1.5.0
        See Also:
        Array.getLength(java.lang.Object)
      • size

        public static int size​(byte[] array)
        Allows arrays to behave similar to collections.
        Parameters:
        array - a byte array
        Returns:
        the length of the array
        Since:
        1.0
        See Also:
        Array.getLength(java.lang.Object)
      • size

        public static int size​(char[] array)
        Allows arrays to behave similar to collections.
        Parameters:
        array - a char array
        Returns:
        the length of the array
        Since:
        1.0
        See Also:
        Array.getLength(java.lang.Object)
      • size

        public static int size​(short[] array)
        Allows arrays to behave similar to collections.
        Parameters:
        array - a short array
        Returns:
        the length of the array
        Since:
        1.0
        See Also:
        Array.getLength(java.lang.Object)
      • size

        public static int size​(int[] array)
        Allows arrays to behave similar to collections.
        Parameters:
        array - an int array
        Returns:
        the length of the array
        Since:
        1.0
        See Also:
        Array.getLength(java.lang.Object)
      • size

        public static int size​(long[] array)
        Allows arrays to behave similar to collections.
        Parameters:
        array - a long array
        Returns:
        the length of the array
        Since:
        1.0
        See Also:
        Array.getLength(java.lang.Object)
      • size

        public static int size​(float[] array)
        Allows arrays to behave similar to collections.
        Parameters:
        array - a float array
        Returns:
        the length of the array
        Since:
        1.0
        See Also:
        Array.getLength(java.lang.Object)
      • size

        public static int size​(double[] array)
        Allows arrays to behave similar to collections.
        Parameters:
        array - a double array
        Returns:
        the length of the array
        Since:
        1.0
        See Also:
        Array.getLength(java.lang.Object)
      • toList

        public static java.util.List<java.lang.Byte> toList​(byte[] array)
        Converts this array to a List of the same size, with each element added to the list.
        Parameters:
        array - a byte array
        Returns:
        a list containing the contents of this array.
        Since:
        1.0
      • toList

        public static java.util.List<java.lang.Boolean> toList​(boolean[] array)
        Converts this array to a List of the same size, with each element added to the list.
        Parameters:
        array - a boolean array
        Returns:
        a list containing the contents of this array.
        Since:
        1.6.0
      • toList

        public static java.util.List<java.lang.Character> toList​(char[] array)
        Converts this array to a List of the same size, with each element added to the list.
        Parameters:
        array - a char array
        Returns:
        a list containing the contents of this array.
        Since:
        1.0
      • toList

        public static java.util.List<java.lang.Short> toList​(short[] array)
        Converts this array to a List of the same size, with each element added to the list.
        Parameters:
        array - a short array
        Returns:
        a list containing the contents of this array.
        Since:
        1.0
      • toList

        public static java.util.List<java.lang.Integer> toList​(int[] array)
        Converts this array to a List of the same size, with each element added to the list.
        Parameters:
        array - an int array
        Returns:
        a list containing the contents of this array.
        Since:
        1.0
      • toList

        public static java.util.List<java.lang.Long> toList​(long[] array)
        Converts this array to a List of the same size, with each element added to the list.
        Parameters:
        array - a long array
        Returns:
        a list containing the contents of this array.
        Since:
        1.0
      • toList

        public static java.util.List<java.lang.Float> toList​(float[] array)
        Converts this array to a List of the same size, with each element added to the list.
        Parameters:
        array - a float array
        Returns:
        a list containing the contents of this array.
        Since:
        1.0
      • toList

        public static java.util.List<java.lang.Double> toList​(double[] array)
        Converts this array to a List of the same size, with each element added to the list.
        Parameters:
        array - a double array
        Returns:
        a list containing the contents of this array.
        Since:
        1.0
      • toSet

        public static java.util.Set<java.lang.Byte> toSet​(byte[] array)
        Converts this array to a Set, with each unique element added to the set.
        Parameters:
        array - a byte array
        Returns:
        a set containing the unique contents of this array.
        Since:
        1.8.0
      • toSet

        public static java.util.Set<java.lang.Boolean> toSet​(boolean[] array)
        Converts this array to a Set, with each unique element added to the set.
        Parameters:
        array - a boolean array
        Returns:
        a set containing the unique contents of this array.
        Since:
        1.8.0
      • toSet

        public static java.util.Set<java.lang.Character> toSet​(char[] array)
        Converts this array to a Set, with each unique element added to the set.
        Parameters:
        array - a char array
        Returns:
        a set containing the unique contents of this array.
        Since:
        1.8.0
      • toSet

        public static java.util.Set<java.lang.Short> toSet​(short[] array)
        Converts this array to a Set, with each unique element added to the set.
        Parameters:
        array - a short array
        Returns:
        a set containing the unique contents of this array.
        Since:
        1.8.0
      • toSet

        public static java.util.Set<java.lang.Integer> toSet​(int[] array)
        Converts this array to a Set, with each unique element added to the set.
        Parameters:
        array - an int array
        Returns:
        a set containing the unique contents of this array.
        Since:
        1.8.0
      • toSet

        public static java.util.Set<java.lang.Long> toSet​(long[] array)
        Converts this array to a Set, with each unique element added to the set.
        Parameters:
        array - a long array
        Returns:
        a set containing the unique contents of this array.
        Since:
        1.8.0
      • toSet

        public static java.util.Set<java.lang.Float> toSet​(float[] array)
        Converts this array to a Set, with each unique element added to the set.
        Parameters:
        array - a float array
        Returns:
        a set containing the unique contents of this array.
        Since:
        1.8.0
      • toSet

        public static java.util.Set<java.lang.Double> toSet​(double[] array)
        Converts this array to a Set, with each unique element added to the set.
        Parameters:
        array - a double array
        Returns:
        a set containing the unique contents of this array.
        Since:
        1.8.0
      • toSet

        public static <T> java.util.Set<T> toSet​(java.util.Collection<T> self)
        Convert a Collection to a Set. Always returns a new Set even if the Collection is already a Set.

        Example usage:

         def result = [1, 2, 2, 2, 3].toSet()
         assert result instanceof Set
         assert result == [1, 2, 3] as Set
         
        Parameters:
        self - a collection
        Returns:
        a Set
        Since:
        1.8.0
      • toSet

        public static <T> java.util.Set<T> toSet​(java.util.Iterator<T> self)
        Convert an iterator to a Set. The iterator will become exhausted of elements after making this conversion.
        Parameters:
        self - an iterator
        Returns:
        a Set
        Since:
        1.8.0
      • toSet

        public static <T> java.util.Set<T> toSet​(java.util.Enumeration<T> self)
        Convert an enumeration to a Set.
        Parameters:
        self - an enumeration
        Returns:
        a Set
        Since:
        1.8.0
      • primitiveArrayGet

        protected static java.lang.Object primitiveArrayGet​(java.lang.Object self,
                                                            int idx)
        Implements the getAt(int) method for primitive type arrays.
        Parameters:
        self - an array object
        idx - the index of interest
        Returns:
        the returned value from the array
        Since:
        1.5.0
      • primitiveArrayGet

        protected static java.util.List primitiveArrayGet​(java.lang.Object self,
                                                          Range range)
        Implements the getAt(Range) method for primitive type arrays.
        Parameters:
        self - an array object
        range - the range of indices of interest
        Returns:
        the returned values from the array corresponding to the range
        Since:
        1.5.0
      • primitiveArrayGet

        protected static java.util.List primitiveArrayGet​(java.lang.Object self,
                                                          java.util.Collection indices)
        Implements the getAt(Collection) method for primitive type arrays. Each value in the collection argument is assumed to be a valid array index. The value at each index is then added to a list which is returned.
        Parameters:
        self - an array object
        indices - the indices of interest
        Returns:
        the returned values from the array
        Since:
        1.0
      • primitiveArrayPut

        protected static java.lang.Object primitiveArrayPut​(java.lang.Object self,
                                                            int idx,
                                                            java.lang.Object newValue)
        Implements the setAt(int idx) method for primitive type arrays.
        Parameters:
        self - an object
        idx - the index of interest
        newValue - the new value to be put into the index of interest
        Returns:
        the added value
        Since:
        1.5.0
      • toCharacter

        public static java.lang.Character toCharacter​(java.lang.String self)
        Converts the given string into a Character object using the first character in the string.
        Parameters:
        self - a String
        Returns:
        the first Character
        Since:
        1.0
      • toBoolean

        public static java.lang.Boolean toBoolean​(java.lang.String self)
        Converts the given string into a Boolean object. If the trimmed string is "true", "y" or "1" (ignoring case) then the result is true otherwise it is false.
        Parameters:
        self - a String
        Returns:
        The Boolean value
        Since:
        1.0
      • toBoolean

        public static java.lang.Boolean toBoolean​(java.lang.Boolean self)
        Identity conversion which returns Boolean.TRUE for a true Boolean and Boolean.FALSE for a false Boolean.
        Parameters:
        self - a Boolean
        Returns:
        the original Boolean
        Since:
        1.7.6
      • split

        public static java.lang.String[] split​(java.lang.String self)
        Convenience method to split a string (with whitespace as delimiter) Like tokenize, but returns an Array of Strings instead of a List
        Parameters:
        self - the string to split
        Returns:
        String[] result of split
        Since:
        1.5.0
      • split

        public static java.lang.CharSequence[] split​(java.lang.CharSequence self)
        Convenience method to split a CharSequence (with whitespace as delimiter). Similar to tokenize, but returns an Array of CharSequence instead of a List.
        Parameters:
        self - the CharSequence to split
        Returns:
        CharSequence[] result of split
        Since:
        1.8.2
        See Also:
        split(String)
      • capitalize

        public static java.lang.String capitalize​(java.lang.String self)
        Convenience method to capitalize the first letter of a string (typically the first letter of a word). Example usage:
         assert 'h'.capitalize() == 'H'
         assert 'hello'.capitalize() == 'Hello'
         assert 'hello world'.capitalize() == 'Hello world'
         assert 'Hello World' ==
             'hello world'.split(' ').collect{ it.capitalize() }.join(' ')
         
        Parameters:
        self - The string to capitalize
        Returns:
        The capitalized String
        Since:
        1.7.3
      • capitalize

        public static java.lang.CharSequence capitalize​(java.lang.CharSequence self)
        Convenience method to capitalize the first letter of a CharSequence.
        Parameters:
        self - The CharSequence to capitalize
        Returns:
        The capitalized CharSequence
        Since:
        1.8.2
        See Also:
        capitalize(String)
      • expand

        public static java.lang.String expand​(java.lang.String self)
        Expands all tabs into spaces with tabStops of size 8.
        Parameters:
        self - A String to expand
        Returns:
        The expanded String
        Since:
        1.7.3
        See Also:
        expand(java.lang.String, int)
      • expand

        public static java.lang.CharSequence expand​(java.lang.CharSequence self)
        Expands all tabs into spaces with tabStops of size 8.
        Parameters:
        self - A CharSequence to expand
        Returns:
        The expanded CharSequence
        Since:
        1.8.2
        See Also:
        expand(java.lang.String)
      • expand

        public static java.lang.String expand​(java.lang.String self,
                                              int tabStop)
        Expands all tabs into spaces. If the String has multiple lines, expand each line - restarting tab stops at the start of each line.
        Parameters:
        self - A String to expand
        tabStop - The number of spaces a tab represents
        Returns:
        The expanded String
        Since:
        1.7.3
      • expand

        public static java.lang.CharSequence expand​(java.lang.CharSequence self,
                                                    int tabStop)
        Expands all tabs into spaces. If the CharSequence has multiple lines, expand each line - restarting tab stops at the start of each line.
        Parameters:
        self - A CharSequence to expand
        tabStop - The number of spaces a tab represents
        Returns:
        The expanded CharSequence
        Since:
        1.8.2
        See Also:
        expand(String, int)
      • expandLine

        public static java.lang.String expandLine​(java.lang.String self,
                                                  int tabStop)
        Expands all tabs into spaces. Assumes the String represents a single line of text.
        Parameters:
        self - A line to expand
        tabStop - The number of spaces a tab represents
        Returns:
        The expanded String
        Since:
        1.7.3
      • expandLine

        public static java.lang.CharSequence expandLine​(java.lang.CharSequence self,
                                                        int tabStop)
        Expands all tabs into spaces. Assumes the CharSequence represents a single line of text.
        Parameters:
        self - A line to expand
        tabStop - The number of spaces a tab represents
        Returns:
        The expanded CharSequence
        Since:
        1.8.2
        See Also:
        expandLine(String, int)
      • unexpand

        public static java.lang.String unexpand​(java.lang.String self)
        Replaces sequences of whitespaces with tabs using tabStops of size 8.
        Parameters:
        self - A String to unexpand
        Returns:
        The unexpanded String
        Since:
        1.7.3
        See Also:
        unexpand(java.lang.String, int)
      • unexpand

        public static java.lang.CharSequence unexpand​(java.lang.CharSequence self)
        Replaces sequences of whitespaces with tabs using tabStops of size 8.
        Parameters:
        self - A CharSequence to unexpand
        Returns:
        The unexpanded CharSequence
        Since:
        1.8.2
        See Also:
        unexpand(java.lang.String)
      • unexpand

        public static java.lang.String unexpand​(java.lang.String self,
                                                int tabStop)
        Replaces sequences of whitespaces with tabs.
        Parameters:
        self - A String to unexpand
        tabStop - The number of spaces a tab represents
        Returns:
        The unexpanded String
        Since:
        1.7.3
      • unexpand

        public static java.lang.CharSequence unexpand​(java.lang.CharSequence self,
                                                      int tabStop)
        Replaces sequences of whitespaces with tabs.
        Parameters:
        self - A CharSequence to unexpand
        tabStop - The number of spaces a tab represents
        Returns:
        The unexpanded CharSequence
        Since:
        1.8.2
        See Also:
        unexpand(String, int)
      • unexpandLine

        public static java.lang.String unexpandLine​(java.lang.String self,
                                                    int tabStop)
        Replaces sequences of whitespaces with tabs within a line.
        Parameters:
        self - A line to unexpand
        tabStop - The number of spaces a tab represents
        Returns:
        The unexpanded String
        Since:
        1.7.3
      • unexpandLine

        public static java.lang.CharSequence unexpandLine​(java.lang.CharSequence self,
                                                          int tabStop)
        Replaces sequences of whitespaces with tabs within a line.
        Parameters:
        self - A line to unexpand
        tabStop - The number of spaces a tab represents
        Returns:
        The unexpanded CharSequence
        Since:
        1.8.2
        See Also:
        unexpandLine(String, int)
      • split

        public static java.lang.String[] split​(GString self)
        Convenience method to split a GString (with whitespace as delimiter).
        Parameters:
        self - the GString to split
        Returns:
        String[] result of split
        Since:
        1.6.1
        See Also:
        split(java.lang.String)
      • tokenize

        public static java.util.List<java.lang.String> tokenize​(java.lang.String self,
                                                                java.lang.String token)
        Tokenize a String based on the given string delimiter.
        Parameters:
        self - a String
        token - the delimiter
        Returns:
        a List of tokens
        Since:
        1.0
        See Also:
        StringTokenizer(java.lang.String, java.lang.String)
      • tokenize

        public static java.util.List<java.lang.CharSequence> tokenize​(java.lang.CharSequence self,
                                                                      java.lang.CharSequence token)
        Tokenize a CharSequence based on the given CharSequence delimiter.
        Parameters:
        self - a CharSequence
        token - the delimiter
        Returns:
        a List of tokens
        Since:
        1.8.2
        See Also:
        tokenize(String, String)
      • tokenize

        public static java.util.List<java.lang.String> tokenize​(java.lang.String self,
                                                                java.lang.Character token)
        Tokenize a String based on the given character delimiter. For example:
         char pathSep = ':'
         assert "/tmp:/usr".tokenize(pathSep) == ["/tmp", "/usr"]
         
        Parameters:
        self - a String
        token - the delimiter
        Returns:
        a List of tokens
        Since:
        1.7.2
        See Also:
        StringTokenizer(java.lang.String, java.lang.String)
      • tokenize

        public static java.util.List<java.lang.CharSequence> tokenize​(java.lang.CharSequence self,
                                                                      java.lang.Character token)
        Tokenize a CharSequence based on the given character delimiter.
        Parameters:
        self - a CharSequence
        token - the delimiter
        Returns:
        a List of tokens
        Since:
        1.8.2
        See Also:
        tokenize(String, Character)
      • tokenize

        public static java.util.List<java.lang.String> tokenize​(java.lang.String self)
        Tokenize a String (with a whitespace as the delimiter).
        Parameters:
        self - a String
        Returns:
        a List of tokens
        Since:
        1.0
        See Also:
        StringTokenizer(java.lang.String)
      • tokenize

        public static java.util.List<java.lang.CharSequence> tokenize​(java.lang.CharSequence self)
        Tokenize a CharSequence (with a whitespace as the delimiter).
        Parameters:
        self - a CharSequence
        Returns:
        a List of tokens
        Since:
        1.8.2
        See Also:
        tokenize(String)
      • plus

        public static java.lang.String plus​(java.lang.String left,
                                            java.lang.Object value)
        Appends the String representation of the given operand to this string.
        Parameters:
        left - a String
        value - any Object
        Returns:
        the new string with the object appended
        Since:
        1.0
      • plus

        public static java.lang.CharSequence plus​(java.lang.CharSequence left,
                                                  java.lang.Object value)
        Appends the String representation of the given operand to this string.
        Parameters:
        left - a CharSequence
        value - any Object
        Returns:
        the new CharSequence with the object appended
        Since:
        1.8.2
      • plus

        public static java.lang.String plus​(java.lang.Number value,
                                            java.lang.String right)
        Appends a String to the string representation of this number.
        Parameters:
        value - a Number
        right - a String
        Returns:
        a String
        Since:
        1.0
      • plus

        public static java.lang.String plus​(java.lang.StringBuffer left,
                                            java.lang.String value)
        Appends a String to this StringBuffer.
        Parameters:
        left - a StringBuffer
        value - a String
        Returns:
        a String
        Since:
        1.0
      • minus

        public static java.lang.String minus​(java.lang.String self,
                                             java.lang.Object target)
        Remove a part of a String. This replaces the first occurrence of target within self with '' and returns the result. If target is a regex Pattern, the first occurrence of that pattern will be removed (using regex matching), otherwise the first occurrence of target.toString() will be removed.
        Parameters:
        self - a String
        target - an object representing the part to remove
        Returns:
        a String minus the part to be removed
        Since:
        1.0
      • minus

        public static java.lang.CharSequence minus​(java.lang.CharSequence self,
                                                   java.lang.Object target)
        Remove a part of a CharSequence by replacing the first occurrence of target within self with '' and returns the result.
        Parameters:
        self - a CharSequence
        target - an object representing the part to remove
        Returns:
        a CharSequence minus the part to be removed
        Since:
        1.8.2
        See Also:
        minus(String, Object)
      • contains

        public static boolean contains​(java.lang.String self,
                                       java.lang.String text)
        Provide an implementation of contains() like Collection.contains(java.lang.Object) to make Strings more polymorphic. This method is not required on JDK 1.5 onwards
        Parameters:
        self - a String
        text - a String to look for
        Returns:
        true if this string contains the given text
        Since:
        1.0
      • contains

        public static boolean contains​(java.lang.CharSequence self,
                                       java.lang.CharSequence text)
        Provide an implementation of contains() like Collection.contains(java.lang.Object) to make CharSequences more polymorphic.
        Parameters:
        self - a CharSequence
        text - the CharSequence to look for
        Returns:
        true if this CharSequence contains the given text
        Since:
        1.8.2
        See Also:
        contains(String, String)
      • contains

        public static boolean contains​(int[] self,
                                       java.lang.Object value)
        Checks whether the array contains the given value.
        Parameters:
        self - the array we are searching
        value - the value being searched for
        Returns:
        true if the array contains the value
        Since:
        1.8.6
      • contains

        public static boolean contains​(long[] self,
                                       java.lang.Object value)
        Checks whether the array contains the given value.
        Parameters:
        self - the array we are searching
        value - the value being searched for
        Returns:
        true if the array contains the value
        Since:
        1.8.6
      • contains

        public static boolean contains​(short[] self,
                                       java.lang.Object value)
        Checks whether the array contains the given value.
        Parameters:
        self - the array we are searching
        value - the value being searched for
        Returns:
        true if the array contains the value
        Since:
        1.8.6
      • contains

        public static boolean contains​(char[] self,
                                       java.lang.Object value)
        Checks whether the array contains the given value.
        Parameters:
        self - the array we are searching
        value - the value being searched for
        Returns:
        true if the array contains the value
        Since:
        1.8.6
      • contains

        public static boolean contains​(boolean[] self,
                                       java.lang.Object value)
        Checks whether the array contains the given value.
        Parameters:
        self - the array within which we count the number of occurrences
        value - the value being searched for
        Returns:
        the number of occurrences
        Since:
        1.8.6
      • contains

        public static boolean contains​(double[] self,
                                       java.lang.Object value)
        Checks whether the array contains the given value.
        Parameters:
        self - the array we are searching
        value - the value being searched for
        Returns:
        true if the array contains the value
        Since:
        1.8.6
      • contains

        public static boolean contains​(float[] self,
                                       java.lang.Object value)
        Checks whether the array contains the given value.
        Parameters:
        self - the array we are searching
        value - the value being searched for
        Returns:
        true if the array contains the value
        Since:
        1.8.6
      • contains

        public static boolean contains​(byte[] self,
                                       java.lang.Object value)
        Checks whether the array contains the given value.
        Parameters:
        self - the array we are searching
        value - the value being searched for
        Returns:
        true if the array contains the value
        Since:
        1.8.6
      • contains

        public static boolean contains​(java.lang.Object[] self,
                                       java.lang.Object value)
        Checks whether the array contains the given value.
        Parameters:
        self - the array we are searching
        value - the value being searched for
        Returns:
        true if the array contains the value
        Since:
        1.8.6
      • count

        public static int count​(java.lang.String self,
                                java.lang.String text)
        Count the number of occurrences of a substring.
        Parameters:
        self - a String
        text - a substring
        Returns:
        the number of occurrences of the given string inside this String
        Since:
        1.0
      • count

        public static int count​(java.lang.CharSequence self,
                                java.lang.CharSequence text)
        Count the number of occurrences of a sub CharSequence.
        Parameters:
        self - a CharSequence
        text - a sub CharSequence
        Returns:
        the number of occurrences of the given CharSequence inside this CharSequence
        Since:
        1.8.2
        See Also:
        count(String, String)
      • next

        public static java.lang.String next​(java.lang.String self)
        This method is called by the ++ operator for the class String. It increments the last character in the given string. If the character in the string is Character.MAX_VALUE a Character.MIN_VALUE will be appended. The empty string is incremented to a string consisting of the character Character.MIN_VALUE.
        Parameters:
        self - a String
        Returns:
        an incremented String
        Since:
        1.0
      • next

        public static java.lang.CharSequence next​(java.lang.CharSequence self)
        This method is called by the ++ operator for the class CharSequence.
        Parameters:
        self - a CharSequence
        Returns:
        an incremented CharSequence
        Since:
        1.8.2
        See Also:
        next(String)
      • previous

        public static java.lang.String previous​(java.lang.String self)
        This method is called by the -- operator for the class String. It decrements the last character in the given string. If the character in the string is Character.MIN_VALUE it will be deleted. The empty string can't be decremented.
        Parameters:
        self - a String
        Returns:
        a String with a decremented digit at the end
        Since:
        1.0
      • previous

        public static java.lang.CharSequence previous​(java.lang.CharSequence self)
        This method is called by the -- operator for the class CharSequence.
        Parameters:
        self - a CharSequence
        Returns:
        a CharSequence with a decremented digit at the end
        Since:
        1.8.2
        See Also:
        previous(String)
      • execute

        public static java.lang.Process execute​(java.lang.String self)
                                         throws java.io.IOException
        Executes the command specified by self as a command-line process.

        For more control over Process construction you can use java.lang.ProcessBuilder (JDK 1.5+).

        Parameters:
        self - a command line String
        Returns:
        the Process which has just started for this command line representation
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • execute

        public static java.lang.Process execute​(java.lang.String self,
                                                java.lang.String[] envp,
                                                java.io.File dir)
                                         throws java.io.IOException
        Executes the command specified by self with environment defined by envp and under the working directory dir.

        For more control over Process construction you can use java.lang.ProcessBuilder (JDK 1.5+).

        Parameters:
        self - a command line String to be executed.
        envp - an array of Strings, each element of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
        dir - the working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process.
        Returns:
        the Process which has just started for this command line representation.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • execute

        public static java.lang.Process execute​(java.lang.String self,
                                                java.util.List envp,
                                                java.io.File dir)
                                         throws java.io.IOException
        Executes the command specified by self with environment defined by envp and under the working directory dir.

        For more control over Process construction you can use java.lang.ProcessBuilder (JDK 1.5+).

        Parameters:
        self - a command line String to be executed.
        envp - a List of Objects (converted to Strings using toString), each member of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
        dir - the working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process.
        Returns:
        the Process which has just started for this command line representation.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • execute

        public static java.lang.Process execute​(java.lang.String[] commandArray)
                                         throws java.io.IOException
        Executes the command specified by the given String array. The first item in the array is the command; the others are the parameters.

        For more control over Process construction you can use java.lang.ProcessBuilder (JDK 1.5+).

        Parameters:
        commandArray - an array of String containing the command name and parameters as separate items in the array.
        Returns:
        the Process which has just started for this command line representation.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • execute

        public static java.lang.Process execute​(java.lang.String[] commandArray,
                                                java.lang.String[] envp,
                                                java.io.File dir)
                                         throws java.io.IOException
        Executes the command specified by the String array given in the first parameter, with the environment defined by envp and under the working directory dir. The first item in the array is the command; the others are the parameters.

        For more control over Process construction you can use java.lang.ProcessBuilder (JDK 1.5+).

        Parameters:
        commandArray - an array of String containing the command name and parameters as separate items in the array.
        envp - an array of Strings, each member of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
        dir - the working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process.
        Returns:
        the Process which has just started for this command line representation.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.1
      • execute

        public static java.lang.Process execute​(java.lang.String[] commandArray,
                                                java.util.List envp,
                                                java.io.File dir)
                                         throws java.io.IOException
        Executes the command specified by the String array given in the first parameter, with the environment defined by envp and under the working directory dir. The first item in the array is the command; the others are the parameters.

        For more control over Process construction you can use java.lang.ProcessBuilder (JDK 1.5+).

        Parameters:
        commandArray - an array of String containing the command name and parameters as separate items in the array.
        envp - a List of Objects (converted to Strings using toString), each member of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
        dir - the working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process.
        Returns:
        the Process which has just started for this command line representation.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.1
      • execute

        public static java.lang.Process execute​(java.util.List commands)
                                         throws java.io.IOException
        Executes the command specified by the given list. The toString() method is called for each item in the list to convert into a resulting String. The first item in the list is the command the others are the parameters.

        For more control over Process construction you can use java.lang.ProcessBuilder (JDK 1.5+).

        Parameters:
        commands - a list containing the command name and parameters as separate items in the list.
        Returns:
        the Process which has just started for this command line representation.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • execute

        public static java.lang.Process execute​(java.util.List commands,
                                                java.lang.String[] envp,
                                                java.io.File dir)
                                         throws java.io.IOException
        Executes the command specified by the given list, with the environment defined by envp and under the working directory dir. The first item in the list is the command; the others are the parameters. The toString() method is called on items in the list to convert them to Strings.

        For more control over Process construction you can use java.lang.ProcessBuilder (JDK 1.5+).

        Parameters:
        commands - a List containing the command name and parameters as separate items in the list.
        envp - an array of Strings, each member of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
        dir - the working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process.
        Returns:
        the Process which has just started for this command line representation.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.1
      • execute

        public static java.lang.Process execute​(java.util.List commands,
                                                java.util.List envp,
                                                java.io.File dir)
                                         throws java.io.IOException
        Executes the command specified by the given list, with the environment defined by envp and under the working directory dir. The first item in the list is the command; the others are the parameters. The toString() method is called on items in the list to convert them to Strings.

        For more control over Process construction you can use java.lang.ProcessBuilder (JDK 1.5+).

        Parameters:
        commands - a List containing the command name and parameters as separate items in the list.
        envp - a List of Objects (converted to Strings using toString), each member of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
        dir - the working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process.
        Returns:
        the Process which has just started for this command line representation.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.1
      • multiply

        public static java.lang.String multiply​(java.lang.String self,
                                                java.lang.Number factor)
        Repeat a String a certain number of times.
        Parameters:
        self - a String to be repeated
        factor - the number of times the String should be repeated
        Returns:
        a String composed of a repetition
        Throws:
        java.lang.IllegalArgumentException - if the number of repetitions is < 0
        Since:
        1.0
      • multiply

        public static java.lang.CharSequence multiply​(java.lang.CharSequence self,
                                                      java.lang.Number factor)
        Repeat a CharSequence a certain number of times.
        Parameters:
        self - a CharSequence to be repeated
        factor - the number of times the CharSequence should be repeated
        Returns:
        a CharSequence composed of a repetition
        Throws:
        java.lang.IllegalArgumentException - if the number of repetitions is < 0
        Since:
        1.8.2
      • toString

        public static java.lang.String toString​(boolean[] self)
        Returns the string representation of the given array.
        Parameters:
        self - an array
        Returns:
        the string representation
        Since:
        1.6.0
      • toString

        public static java.lang.String toString​(byte[] self)
        Returns the string representation of the given array.
        Parameters:
        self - an array
        Returns:
        the string representation
        Since:
        1.6.0
      • toString

        public static java.lang.String toString​(char[] self)
        Returns the string representation of the given array.
        Parameters:
        self - an array
        Returns:
        the string representation
        Since:
        1.6.0
      • toString

        public static java.lang.String toString​(short[] self)
        Returns the string representation of the given array.
        Parameters:
        self - an array
        Returns:
        the string representation
        Since:
        1.6.0
      • toString

        public static java.lang.String toString​(int[] self)
        Returns the string representation of the given array.
        Parameters:
        self - an array
        Returns:
        the string representation
        Since:
        1.6.0
      • toString

        public static java.lang.String toString​(long[] self)
        Returns the string representation of the given array.
        Parameters:
        self - an array
        Returns:
        the string representation
        Since:
        1.6.0
      • toString

        public static java.lang.String toString​(float[] self)
        Returns the string representation of the given array.
        Parameters:
        self - an array
        Returns:
        the string representation
        Since:
        1.6.0
      • toString

        public static java.lang.String toString​(double[] self)
        Returns the string representation of the given array.
        Parameters:
        self - an array
        Returns:
        the string representation
        Since:
        1.6.0
      • toString

        public static java.lang.String toString​(java.util.AbstractMap self)
        Returns the string representation of the given map.
        Parameters:
        self - a Map
        Returns:
        the string representation
        Since:
        1.0
        See Also:
        toMapString(java.util.Map)
      • toMapString

        public static java.lang.String toMapString​(java.util.Map self)
        Returns the string representation of this map. The string displays the contents of the map, i.e. [one:1, two:2, three:3].
        Parameters:
        self - a Map
        Returns:
        the string representation
        Since:
        1.0
      • toMapString

        public static java.lang.String toMapString​(java.util.Map self,
                                                   int maxSize)
        Returns the string representation of this map. The string displays the contents of the map, i.e. [one:1, two:2, three:3].
        Parameters:
        self - a Map
        maxSize - stop after approximately this many characters and append '...'
        Returns:
        the string representation
        Since:
        1.0
      • toString

        public static java.lang.String toString​(java.util.AbstractCollection self)
        Returns the string representation of the given collection. The string displays the contents of the collection, i.e. [1, 2, a].
        Parameters:
        self - a Collection
        Returns:
        the string representation
        Since:
        1.0
        See Also:
        toListString(java.util.Collection)
      • toListString

        public static java.lang.String toListString​(java.util.Collection self)
        Returns the string representation of the given list. The string displays the contents of the list, similar to a list literal, i.e. [1, 2, a].
        Parameters:
        self - a Collection
        Returns:
        the string representation
        Since:
        1.0
      • toListString

        public static java.lang.String toListString​(java.util.Collection self,
                                                    int maxSize)
        Returns the string representation of the given list. The string displays the contents of the list, similar to a list literal, i.e. [1, 2, a].
        Parameters:
        self - a Collection
        maxSize - stop after approximately this many characters and append '...'
        Returns:
        the string representation
        Since:
        1.7.3
      • toString

        public static java.lang.String toString​(java.lang.Object[] self)
        Returns the string representation of this array's contents.
        Parameters:
        self - an Object[]
        Returns:
        the string representation
        Since:
        1.0
        See Also:
        toArrayString(java.lang.Object[])
      • toArrayString

        public static java.lang.String toArrayString​(java.lang.Object[] self)
        Returns the string representation of the given array. The string displays the contents of the array, similar to an array literal, i.e. {1, 2, "a"}.
        Parameters:
        self - an Object[]
        Returns:
        the string representation
        Since:
        1.0
      • toString

        public static java.lang.String toString​(java.lang.Object value)
        Create a String representation of this object.
        Parameters:
        value - an object
        Returns:
        a string.
        Since:
        1.0
      • next

        public static java.lang.Character next​(java.lang.Character self)
        Increment a Character by one.
        Parameters:
        self - a Character
        Returns:
        an incremented Character
        Since:
        1.5.7
      • next

        public static java.lang.Number next​(java.lang.Number self)
        Increment a Number by one.
        Parameters:
        self - a Number
        Returns:
        an incremented Number
        Since:
        1.0
      • previous

        public static java.lang.Character previous​(java.lang.Character self)
        Decrement a Character by one.
        Parameters:
        self - a Character
        Returns:
        a decremented Character
        Since:
        1.5.7
      • previous

        public static java.lang.Number previous​(java.lang.Number self)
        Decrement a Number by one.
        Parameters:
        self - a Number
        Returns:
        a decremented Number
        Since:
        1.0
      • plus

        public static java.lang.Number plus​(java.lang.Character left,
                                            java.lang.Number right)
        Add a Character and a Number. The ordinal value of the Character is used in the addition (the ordinal value is the unicode value which for simple character sets is the ASCII value). This operation will always create a new object for the result, while the operands remain unchanged.
        Parameters:
        left - a Character
        right - a Number
        Returns:
        the Number corresponding to the addition of left and right
        Since:
        1.0
        See Also:
        Integer.valueOf(int)
      • plus

        public static java.lang.Number plus​(java.lang.Number left,
                                            java.lang.Character right)
        Add a Number and a Character. The ordinal value of the Character is used in the addition (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Number
        right - a Character
        Returns:
        The Number corresponding to the addition of left and right
        Since:
        1.0
        See Also:
        Integer.valueOf(int)
      • plus

        public static java.lang.Number plus​(java.lang.Character left,
                                            java.lang.Character right)
        Add one Character to another. The ordinal values of the Characters are used in the addition (the ordinal value is the unicode value which for simple character sets is the ASCII value). This operation will always create a new object for the result, while the operands remain unchanged.
        Parameters:
        left - a Character
        right - a Character
        Returns:
        the Number corresponding to the addition of left and right
        Since:
        1.0
        See Also:
        plus(java.lang.Number, java.lang.Character)
      • compareTo

        public static int compareTo​(java.lang.Character left,
                                    java.lang.Number right)
        Compare a Character and a Number. The ordinal value of the Character is used in the comparison (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Character
        right - a Number
        Returns:
        the result of the comparison
        Since:
        1.0
      • compareTo

        public static int compareTo​(java.lang.Number left,
                                    java.lang.Character right)
        Compare a Number and a Character. The ordinal value of the Character is used in the comparison (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Number
        right - a Character
        Returns:
        the result of the comparison
        Since:
        1.0
      • compareTo

        public static int compareTo​(java.lang.Character left,
                                    java.lang.Character right)
        Compare two Characters. The ordinal values of the Characters are compared (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Character
        right - a Character
        Returns:
        the result of the comparison
        Since:
        1.0
      • compareTo

        public static int compareTo​(java.lang.Number left,
                                    java.lang.Number right)
        Compare two Numbers. Equality (==) for numbers dispatches to this.
        Parameters:
        left - a Number
        right - another Number to compare to
        Returns:
        the comparison of both numbers
        Since:
        1.0
      • minus

        public static java.lang.Number minus​(java.lang.Character left,
                                             java.lang.Number right)
        Subtract a Number from a Character. The ordinal value of the Character is used in the subtraction (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Character
        right - a Number
        Returns:
        the Number corresponding to the subtraction of right from left
        Since:
        1.0
      • minus

        public static java.lang.Number minus​(java.lang.Number left,
                                             java.lang.Character right)
        Subtract a Character from a Number. The ordinal value of the Character is used in the subtraction (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Number
        right - a Character
        Returns:
        the Number corresponding to the subtraction of right from left
        Since:
        1.0
      • minus

        public static java.lang.Number minus​(java.lang.Character left,
                                             java.lang.Character right)
        Subtract one Character from another. The ordinal values of the Characters is used in the comparison (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Character
        right - a Character
        Returns:
        the Number corresponding to the subtraction of right from left
        Since:
        1.0
      • multiply

        public static java.lang.Number multiply​(java.lang.Character left,
                                                java.lang.Number right)
        Multiply a Character by a Number. The ordinal value of the Character is used in the multiplication (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Character
        right - a Number
        Returns:
        the Number corresponding to the multiplication of left by right
        Since:
        1.0
      • multiply

        public static java.lang.Number multiply​(java.lang.Number left,
                                                java.lang.Character right)
        Multiply a Number by a Character. The ordinal value of the Character is used in the multiplication (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Number
        right - a Character
        Returns:
        the multiplication of left by right
        Since:
        1.0
      • multiply

        public static java.lang.Number multiply​(java.lang.Character left,
                                                java.lang.Character right)
        Multiply two Characters. The ordinal values of the Characters are used in the multiplication (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Character
        right - another Character
        Returns:
        the Number corresponding to the multiplication of left by right
        Since:
        1.0
      • multiply

        public static java.lang.Number multiply​(java.math.BigDecimal left,
                                                java.lang.Double right)
        Multiply a BigDecimal and a Double. Note: This method was added to enforce the Groovy rule of BigDecimal*Double == Double. Without this method, the multiply(BigDecimal) method in BigDecimal would respond and return a BigDecimal instead. Since BigDecimal is preferred over Number, the Number*Number method is not chosen as in older versions of Groovy.
        Parameters:
        left - a BigDecimal
        right - a Double
        Returns:
        the multiplication of left by right
        Since:
        1.0
      • multiply

        public static java.lang.Number multiply​(java.math.BigDecimal left,
                                                java.math.BigInteger right)
        Multiply a BigDecimal and a BigInteger. Note: This method was added to enforce the Groovy rule of BigDecimal*long == long. Without this method, the multiply(BigDecimal) method in BigDecimal would respond and return a BigDecimal instead. Since BigDecimal is preferred over Number, the Number*Number method is not chosen as in older versions of Groovy. BigInteger is the fallback for all integer types in Groovy
        Parameters:
        left - a BigDecimal
        right - a BigInteger
        Returns:
        the multiplication of left by right
        Since:
        1.0
      • power

        public static java.lang.Number power​(java.lang.Number self,
                                             java.lang.Number exponent)
        Power of a Number to a certain exponent. Called by the '**' operator.
        Parameters:
        self - a Number
        exponent - a Number exponent
        Returns:
        a Number to the power of a certain exponent
        Since:
        1.0
      • power

        public static java.lang.Number power​(java.math.BigDecimal self,
                                             java.lang.Integer exponent)
        Power of a BigDecimal to an integer certain exponent. If the exponent is positive, call the BigDecimal.pow(int) method to maintain precision. Called by the '**' operator.
        Parameters:
        self - a BigDecimal
        exponent - an Integer exponent
        Returns:
        a Number to the power of a the exponent
      • power

        public static java.lang.Number power​(java.math.BigInteger self,
                                             java.lang.Integer exponent)
        Power of a BigInteger to an integer certain exponent. If the exponent is positive, call the BigInteger.pow(int) method to maintain precision. Called by the '**' operator.
        Parameters:
        self - a BigInteger
        exponent - an Integer exponent
        Returns:
        a Number to the power of a the exponent
      • power

        public static java.lang.Number power​(java.lang.Integer self,
                                             java.lang.Integer exponent)
        Power of an integer to an integer certain exponent. If the exponent is positive, convert to a BigInteger and call BigInteger.pow(int) method to maintain precision. Called by the '**' operator.
        Parameters:
        self - an Integer
        exponent - an Integer exponent
        Returns:
        a Number to the power of a the exponent
      • power

        public static java.lang.Number power​(java.lang.Long self,
                                             java.lang.Integer exponent)
        Power of a long to an integer certain exponent. If the exponent is positive, convert to a BigInteger and call BigInteger.pow(int) method to maintain precision. Called by the '**' operator.
        Parameters:
        self - a Long
        exponent - an Integer exponent
        Returns:
        a Number to the power of a the exponent
      • div

        public static java.lang.Number div​(java.lang.Character left,
                                           java.lang.Number right)
        Divide a Character by a Number. The ordinal value of the Character is used in the division (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Character
        right - a Number
        Returns:
        the Number corresponding to the division of left by right
        Since:
        1.0
      • div

        public static java.lang.Number div​(java.lang.Number left,
                                           java.lang.Character right)
        Divide a Number by a Character. The ordinal value of the Character is used in the division (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Number
        right - a Character
        Returns:
        the Number corresponding to the division of left by right
        Since:
        1.0
      • div

        public static java.lang.Number div​(java.lang.Character left,
                                           java.lang.Character right)
        Divide one Character by another. The ordinal values of the Characters are used in the division (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Character
        right - another Character
        Returns:
        the Number corresponding to the division of left by right
        Since:
        1.0
      • intdiv

        public static java.lang.Number intdiv​(java.lang.Character left,
                                              java.lang.Number right)
        Integer Divide a Character by a Number. The ordinal value of the Character is used in the division (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Character
        right - a Number
        Returns:
        a Number (an Integer) resulting from the integer division operation
        Since:
        1.0
      • intdiv

        public static java.lang.Number intdiv​(java.lang.Number left,
                                              java.lang.Character right)
        Integer Divide a Number by a Character. The ordinal value of the Character is used in the division (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Number
        right - a Character
        Returns:
        a Number (an Integer) resulting from the integer division operation
        Since:
        1.0
      • intdiv

        public static java.lang.Number intdiv​(java.lang.Character left,
                                              java.lang.Character right)
        Integer Divide two Characters. The ordinal values of the Characters are used in the division (the ordinal value is the unicode value which for simple character sets is the ASCII value).
        Parameters:
        left - a Character
        right - another Character
        Returns:
        a Number (an Integer) resulting from the integer division operation
        Since:
        1.0
      • intdiv

        public static java.lang.Number intdiv​(java.lang.Number left,
                                              java.lang.Number right)
        Integer Divide two Numbers.
        Parameters:
        left - a Number
        right - another Number
        Returns:
        a Number (an Integer) resulting from the integer division operation
        Since:
        1.0
      • or

        public static java.lang.Number or​(java.lang.Number left,
                                          java.lang.Number right)
        Bitwise OR together two numbers.
        Parameters:
        left - a Number
        right - another Number to bitwise OR
        Returns:
        the bitwise OR of both Numbers
        Since:
        1.0
      • and

        public static java.lang.Number and​(java.lang.Number left,
                                           java.lang.Number right)
        Bitwise AND together two Numbers.
        Parameters:
        left - a Number
        right - another Number to bitwise AND
        Returns:
        the bitwise AND of both Numbers
        Since:
        1.0
      • and

        public static java.util.BitSet and​(java.util.BitSet left,
                                           java.util.BitSet right)
        Bitwise AND together two BitSets.
        Parameters:
        left - a BitSet
        right - another BitSet to bitwise AND
        Returns:
        the bitwise AND of both BitSets
        Since:
        1.5.0
      • xor

        public static java.util.BitSet xor​(java.util.BitSet left,
                                           java.util.BitSet right)
        Bitwise XOR together two BitSets. Called when the '^' operator is used between two bit sets.
        Parameters:
        left - a BitSet
        right - another BitSet to bitwise AND
        Returns:
        the bitwise XOR of both BitSets
        Since:
        1.5.0
      • bitwiseNegate

        public static java.util.BitSet bitwiseNegate​(java.util.BitSet self)
        Bitwise NEGATE a BitSet.
        Parameters:
        self - a BitSet
        Returns:
        the bitwise NEGATE of the BitSet
        Since:
        1.5.0
      • or

        public static java.util.BitSet or​(java.util.BitSet left,
                                          java.util.BitSet right)
        Bitwise OR together two BitSets. Called when the '|' operator is used between two bit sets.
        Parameters:
        left - a BitSet
        right - another BitSet to bitwise AND
        Returns:
        the bitwise OR of both BitSets
        Since:
        1.5.0
      • xor

        public static java.lang.Number xor​(java.lang.Number left,
                                           java.lang.Number right)
        Bitwise XOR together two Numbers. Called when the '|' operator is used.
        Parameters:
        left - a Number
        right - another Number to bitwse XOR
        Returns:
        the bitwise XOR of both Numbers
        Since:
        1.0
      • mod

        public static java.lang.Number mod​(java.lang.Number left,
                                           java.lang.Number right)
        Performs a division modulus operation. Called by the '%' operator.
        Parameters:
        left - a Number
        right - another Number to mod
        Returns:
        the modulus result
        Since:
        1.0
      • unaryMinus

        public static java.lang.Number unaryMinus​(java.lang.Number left)
        Negates the number. Equivalent to the '-' operator when it preceeds a single operand, i.e. -10
        Parameters:
        left - a Number
        Returns:
        the negation of the number
        Since:
        1.5.0
      • times

        public static void times​(java.lang.Number self,
                                 Closure closure)
        Executes the closure this many times, starting from zero. The current index is passed to the closure each time. Example:
        10.times {
           println it
         }
        Prints the numbers 0 through 9.
        Parameters:
        self - a Number
        closure - the closure to call a number of times
        Since:
        1.0
      • upto

        public static void upto​(java.lang.Number self,
                                java.lang.Number to,
                                Closure closure)
        Iterates from this number up to the given number, inclusive, incrementing by one each time.
        Parameters:
        self - a Number
        to - another Number to go up to
        closure - the closure to call
        Since:
        1.0
      • upto

        public static void upto​(long self,
                                java.lang.Number to,
                                Closure closure)
        Iterates from this number up to the given number, inclusive, incrementing by one each time.
        Parameters:
        self - a long
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • upto

        public static void upto​(java.lang.Long self,
                                java.lang.Number to,
                                Closure closure)
        Iterates from this number up to the given number, inclusive, incrementing by one each time.
        Parameters:
        self - a Long
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • upto

        public static void upto​(float self,
                                java.lang.Number to,
                                Closure closure)
        Iterates from this number up to the given number, inclusive, incrementing by one each time.
        Parameters:
        self - a float
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • upto

        public static void upto​(java.lang.Float self,
                                java.lang.Number to,
                                Closure closure)
        Iterates from this number up to the given number, inclusive, incrementing by one each time.
        Parameters:
        self - a Float
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • upto

        public static void upto​(double self,
                                java.lang.Number to,
                                Closure closure)
        Iterates from this number up to the given number, inclusive, incrementing by one each time.
        Parameters:
        self - a double
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • upto

        public static void upto​(java.lang.Double self,
                                java.lang.Number to,
                                Closure closure)
        Iterates from this number up to the given number, inclusive, incrementing by one each time.
        Parameters:
        self - a Double
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • upto

        public static void upto​(java.math.BigInteger self,
                                java.lang.Number to,
                                Closure closure)
        Iterates from this number up to the given number, inclusive, incrementing by one each time. Example:
        0.upto( 10 ) {
           println it
         }
        Prints numbers 0 to 10
        Parameters:
        self - a BigInteger
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • upto

        public static void upto​(java.math.BigDecimal self,
                                java.lang.Number to,
                                Closure closure)
        Iterates from this number up to the given number, inclusive, incrementing by one each time.
        0.1.upto( 10 ) {
           println it
         }
        Prints numbers 0.1, 1.1, 2.1... to 9.1
        Parameters:
        self - a BigDecimal
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • downto

        public static void downto​(java.lang.Number self,
                                  java.lang.Number to,
                                  Closure closure)
        Iterates from this number down to the given number, inclusive, decrementing by one each time.
        Parameters:
        self - a Number
        to - another Number to go down to
        closure - the closure to call
        Since:
        1.0
      • downto

        public static void downto​(long self,
                                  java.lang.Number to,
                                  Closure closure)
        Iterates from this number down to the given number, inclusive, decrementing by one each time.
        Parameters:
        self - a long
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • downto

        public static void downto​(java.lang.Long self,
                                  java.lang.Number to,
                                  Closure closure)
        Iterates from this number down to the given number, inclusive, decrementing by one each time.
        Parameters:
        self - a Long
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • downto

        public static void downto​(float self,
                                  java.lang.Number to,
                                  Closure closure)
        Iterates from this number down to the given number, inclusive, decrementing by one each time.
        Parameters:
        self - a float
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • downto

        public static void downto​(java.lang.Float self,
                                  java.lang.Number to,
                                  Closure closure)
        Iterates from this number down to the given number, inclusive, decrementing by one each time.
        Parameters:
        self - a Float
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • downto

        public static void downto​(double self,
                                  java.lang.Number to,
                                  Closure closure)
        Iterates from this number down to the given number, inclusive, decrementing by one each time.
        Parameters:
        self - a double
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • downto

        public static void downto​(java.lang.Double self,
                                  java.lang.Number to,
                                  Closure closure)
        Iterates from this number down to the given number, inclusive, decrementing by one each time.
        Parameters:
        self - a Double
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • downto

        public static void downto​(java.math.BigInteger self,
                                  java.lang.Number to,
                                  Closure closure)
        Iterates from this number down to the given number, inclusive, decrementing by one each time.
        Parameters:
        self - a BigInteger
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • downto

        public static void downto​(java.math.BigDecimal self,
                                  java.lang.Number to,
                                  Closure closure)
        Iterates from this number down to the given number, inclusive, decrementing by one each time. Each number is passed to the closure. Example:
        10.5.downto(0) {
           println it
         }
        Prints numbers 10.5, 9.5 ... to 0.5.
        Parameters:
        self - a BigDecimal
        to - the end number
        closure - the code to execute for each number
        Since:
        1.0
      • step

        public static void step​(java.lang.Number self,
                                java.lang.Number to,
                                java.lang.Number stepNumber,
                                Closure closure)
        Iterates from this number up to the given number using a step increment. Each intermediate number is passed to the given closure. Example:
        0.step( 10, 2 ) {
           println it
         }
        Prints even numbers 0 through 8.
        Parameters:
        self - a Number to start with
        to - a Number to go up to, exclusive
        stepNumber - a Number representing the step increment
        closure - the closure to call
        Since:
        1.0
      • abs

        public static int abs​(java.lang.Number number)
        Get the absolute value
        Parameters:
        number - a Number
        Returns:
        the absolute value of that Number
        Since:
        1.0
      • abs

        public static long abs​(java.lang.Long number)
        Get the absolute value
        Parameters:
        number - a Long
        Returns:
        the absolute value of that Long
        Since:
        1.0
      • abs

        public static float abs​(java.lang.Float number)
        Get the absolute value
        Parameters:
        number - a Float
        Returns:
        the absolute value of that Float
        Since:
        1.0
      • abs

        public static double abs​(java.lang.Double number)
        Get the absolute value
        Parameters:
        number - a Double
        Returns:
        the absolute value of that Double
        Since:
        1.0
      • round

        public static int round​(java.lang.Float number)
        Round the value
        Parameters:
        number - a Float
        Returns:
        the rounded value of that Float
        Since:
        1.0
      • round

        public static float round​(java.lang.Float number,
                                  int precision)
        Round the value
        Parameters:
        number - a Float
        precision - the number of decimal places to keep
        Returns:
        the Float rounded to the number of decimal places specified by precision
        Since:
        1.6.0
      • trunc

        public static float trunc​(java.lang.Float number,
                                  int precision)
        Truncate the value
        Parameters:
        number - a Float
        precision - the number of decimal places to keep
        Returns:
        the Float truncated to the number of decimal places specified by precision
        Since:
        1.6.0
      • trunc

        public static float trunc​(java.lang.Float number)
        Truncate the value
        Parameters:
        number - a Double
        Returns:
        the Double truncated to 0 decimal places (i.e. a synonym for floor)
        Since:
        1.6.0
      • round

        public static long round​(java.lang.Double number)
        Round the value
        Parameters:
        number - a Double
        Returns:
        the rounded value of that Double
        Since:
        1.0
      • round

        public static double round​(java.lang.Double number,
                                   int precision)
        Round the value
        Parameters:
        number - a Double
        precision - the number of decimal places to keep
        Returns:
        the Double rounded to the number of decimal places specified by precision
        Since:
        1.6.4
      • trunc

        public static double trunc​(java.lang.Double number)
        Truncate the value
        Parameters:
        number - a Double
        Returns:
        the Double truncated to 0 decimal places (i.e. a synonym for floor)
        Since:
        1.6.4
      • trunc

        public static double trunc​(java.lang.Double number,
                                   int precision)
        Truncate the value
        Parameters:
        number - a Double
        precision - the number of decimal places to keep
        Returns:
        the Double truncated to the number of decimal places specified by precision
        Since:
        1.6.4
      • toInteger

        public static java.lang.Integer toInteger​(java.lang.String self)
        Parse a String into an Integer
        Parameters:
        self - a String
        Returns:
        an Integer
        Since:
        1.0
      • toLong

        public static java.lang.Long toLong​(java.lang.String self)
        Parse a String into a Long
        Parameters:
        self - a String
        Returns:
        a Long
        Since:
        1.0
      • toShort

        public static java.lang.Short toShort​(java.lang.String self)
        Parse a String into a Short
        Parameters:
        self - a String
        Returns:
        a Short
        Since:
        1.5.7
      • toFloat

        public static java.lang.Float toFloat​(java.lang.String self)
        Parse a String into a Float
        Parameters:
        self - a String
        Returns:
        a Float
        Since:
        1.0
      • toDouble

        public static java.lang.Double toDouble​(java.lang.String self)
        Parse a String into a Double
        Parameters:
        self - a String
        Returns:
        a Double
        Since:
        1.0
      • toBigInteger

        public static java.math.BigInteger toBigInteger​(java.lang.String self)
        Parse a String into a BigInteger
        Parameters:
        self - a String
        Returns:
        a BigInteger
        Since:
        1.0
      • toBigDecimal

        public static java.math.BigDecimal toBigDecimal​(java.lang.String self)
        Parse a String into a BigDecimal
        Parameters:
        self - a String
        Returns:
        a BigDecimal
        Since:
        1.0
      • isInteger

        public static boolean isInteger​(java.lang.String self)
        Determine if a String can be parsed into an Integer.
        Parameters:
        self - a String
        Returns:
        true if the string can be parsed
        Since:
        1.5.0
      • isLong

        public static boolean isLong​(java.lang.String self)
        Determine if a String can be parsed into a Long.
        Parameters:
        self - a String
        Returns:
        true if the string can be parsed
        Since:
        1.5.0
      • isFloat

        public static boolean isFloat​(java.lang.String self)
        Determine if a String can be parsed into a Float.
        Parameters:
        self - a String
        Returns:
        true if the string can be parsed
        Since:
        1.5.0
      • isDouble

        public static boolean isDouble​(java.lang.String self)
        Determine if a String can be parsed into a Double.
        Parameters:
        self - a String
        Returns:
        true if the string can be parsed
        Since:
        1.5.0
      • isBigInteger

        public static boolean isBigInteger​(java.lang.String self)
        Determine if a String can be parsed into a BigInteger.
        Parameters:
        self - a String
        Returns:
        true if the string can be parsed
        Since:
        1.5.0
      • isBigDecimal

        public static boolean isBigDecimal​(java.lang.String self)
        Determine if a String can be parsed into a BigDecimal.
        Parameters:
        self - a String
        Returns:
        true if the string can be parsed
        Since:
        1.5.0
      • isNumber

        public static boolean isNumber​(java.lang.String self)
        Determine if a String can be parsed into a Number. Synonym for 'isBigDecimal()'.
        Parameters:
        self - a String
        Returns:
        true if the string can be parsed
        Since:
        1.5.0
        See Also:
        isBigDecimal(java.lang.String)
      • toInteger

        public static java.lang.Integer toInteger​(java.lang.CharSequence self)
        Parse a CharSequence into an Integer
        Parameters:
        self - a CharSequence
        Returns:
        an Integer
        Since:
        1.8.2
        See Also:
        toInteger(java.lang.String)
      • toLong

        public static java.lang.Long toLong​(java.lang.CharSequence self)
        Parse a CharSequence into a Long
        Parameters:
        self - a CharSequence
        Returns:
        a Long
        Since:
        1.8.2
        See Also:
        toLong(java.lang.String)
      • toShort

        public static java.lang.Short toShort​(java.lang.CharSequence self)
        Parse a CharSequence into a Short
        Parameters:
        self - a CharSequence
        Returns:
        a Short
        Since:
        1.8.2
        See Also:
        toShort(java.lang.String)
      • toFloat

        public static java.lang.Float toFloat​(java.lang.CharSequence self)
        Parse a CharSequence into a Float
        Parameters:
        self - a CharSequence
        Returns:
        a Float
        Since:
        1.8.2
        See Also:
        toFloat(java.lang.String)
      • toDouble

        public static java.lang.Double toDouble​(java.lang.CharSequence self)
        Parse a CharSequence into a Double
        Parameters:
        self - a CharSequence
        Returns:
        a Double
        Since:
        1.8.2
        See Also:
        toDouble(java.lang.String)
      • toBigInteger

        public static java.math.BigInteger toBigInteger​(java.lang.CharSequence self)
        Parse a CharSequence into a BigInteger
        Parameters:
        self - a CharSequence
        Returns:
        a BigInteger
        Since:
        1.8.2
        See Also:
        toBigInteger(java.lang.String)
      • toBigDecimal

        public static java.math.BigDecimal toBigDecimal​(java.lang.CharSequence self)
        Parse a CharSequence into a BigDecimal
        Parameters:
        self - a CharSequence
        Returns:
        a BigDecimal
        Since:
        1.8.2
        See Also:
        toBigDecimal(java.lang.String)
      • isInteger

        public static boolean isInteger​(java.lang.CharSequence self)
        Determine if a CharSequence can be parsed as an Integer.
        Parameters:
        self - a CharSequence
        Returns:
        true if the CharSequence can be parsed
        Since:
        1.8.2
        See Also:
        isInteger(java.lang.String)
      • isLong

        public static boolean isLong​(java.lang.CharSequence self)
        Determine if a CharSequence can be parsed as a Long.
        Parameters:
        self - a CharSequence
        Returns:
        true if the CharSequence can be parsed
        Since:
        1.8.2
        See Also:
        isLong(java.lang.String)
      • isFloat

        public static boolean isFloat​(java.lang.CharSequence self)
        Determine if a CharSequence can be parsed as a Float.
        Parameters:
        self - a CharSequence
        Returns:
        true if the CharSequence can be parsed
        Since:
        1.8.2
        See Also:
        isFloat(java.lang.String)
      • isDouble

        public static boolean isDouble​(java.lang.CharSequence self)
        Determine if a CharSequence can be parsed as a Double.
        Parameters:
        self - a CharSequence
        Returns:
        true if the CharSequence can be parsed
        Since:
        1.8.2
        See Also:
        isDouble(java.lang.String)
      • isBigInteger

        public static boolean isBigInteger​(java.lang.CharSequence self)
        Determine if a CharSequence can be parsed as a BigInteger.
        Parameters:
        self - a CharSequence
        Returns:
        true if the CharSequence can be parsed
        Since:
        1.8.2
        See Also:
        isBigInteger(java.lang.String)
      • isBigDecimal

        public static boolean isBigDecimal​(java.lang.CharSequence self)
        Determine if a CharSequence can be parsed as a BigDecimal.
        Parameters:
        self - a CharSequence
        Returns:
        true if the CharSequence can be parsed
        Since:
        1.8.2
        See Also:
        isBigDecimal(java.lang.String)
      • isNumber

        public static boolean isNumber​(java.lang.CharSequence self)
        Determine if a CharSequence can be parsed as a Number. Synonym for 'isBigDecimal()'.
        Parameters:
        self - a CharSequence
        Returns:
        true if the CharSequence can be parsed
        Since:
        1.8.2
        See Also:
        isNumber(java.lang.String)
      • isUpperCase

        public static boolean isUpperCase​(java.lang.Character self)
        Determine if a Character is uppercase. Synonym for 'Character.isUpperCase(this)'.
        Parameters:
        self - a Character
        Returns:
        true if the character is uppercase
        Since:
        1.5.7
        See Also:
        Character.isUpperCase(char)
      • isLowerCase

        public static boolean isLowerCase​(java.lang.Character self)
        Determine if a Character is lowercase. Synonym for 'Character.isLowerCase(this)'.
        Parameters:
        self - a Character
        Returns:
        true if the character is lowercase
        Since:
        1.5.7
        See Also:
        Character.isLowerCase(char)
      • isLetter

        public static boolean isLetter​(java.lang.Character self)
        Determines if a character is a letter. Synonym for 'Character.isLetter(this)'.
        Parameters:
        self - a Character
        Returns:
        true if the character is a letter
        Since:
        1.5.7
        See Also:
        Character.isLetter(char)
      • isDigit

        public static boolean isDigit​(java.lang.Character self)
        Determines if a character is a digit. Synonym for 'Character.isDigit(this)'.
        Parameters:
        self - a Character
        Returns:
        true if the character is a digit
        Since:
        1.5.7
        See Also:
        Character.isDigit(char)
      • isLetterOrDigit

        public static boolean isLetterOrDigit​(java.lang.Character self)
        Determines if a character is a letter or digit. Synonym for 'Character.isLetterOrDigit(this)'.
        Parameters:
        self - a Character
        Returns:
        true if the character is a letter or digit
        Since:
        1.5.7
        See Also:
        Character.isLetterOrDigit(char)
      • isWhitespace

        public static boolean isWhitespace​(java.lang.Character self)
        Determines if a character is a whitespace character. Synonym for 'Character.isWhitespace(this)'.
        Parameters:
        self - a Character
        Returns:
        true if the character is a whitespace character
        Since:
        1.5.7
        See Also:
        Character.isWhitespace(char)
      • toUpperCase

        public static char toUpperCase​(java.lang.Character self)
        Converts the character to uppercase. Synonym for 'Character.toUpperCase(this)'.
        Parameters:
        self - a Character to convert
        Returns:
        the uppercase equivalent of the character, if any; otherwise, the character itself.
        Since:
        1.5.7
        See Also:
        Character.isUpperCase(char), String.toUpperCase()
      • toLowerCase

        public static char toLowerCase​(java.lang.Character self)
        Converts the character to lowercase. Synonym for 'Character.toLowerCase(this)'.
        Parameters:
        self - a Character to convert
        Returns:
        the lowercase equivalent of the character, if any; otherwise, the character itself.
        Since:
        1.5.7
        See Also:
        Character.isLowerCase(char), String.toLowerCase()
      • toInteger

        public static java.lang.Integer toInteger​(java.lang.Number self)
        Transform a Number into an Integer
        Parameters:
        self - a Number
        Returns:
        an Integer
        Since:
        1.0
      • toLong

        public static java.lang.Long toLong​(java.lang.Number self)
        Transform a Number into a Long
        Parameters:
        self - a Number
        Returns:
        an Long
        Since:
        1.0
      • toFloat

        public static java.lang.Float toFloat​(java.lang.Number self)
        Transform a Number into a Float
        Parameters:
        self - a Number
        Returns:
        an Float
        Since:
        1.0
      • toDouble

        public static java.lang.Double toDouble​(java.lang.Number self)
        Transform a Number into a Double
        Parameters:
        self - a Number
        Returns:
        an Double
        Since:
        1.0
      • toBigDecimal

        public static java.math.BigDecimal toBigDecimal​(java.lang.Number self)
        Transform a Number into a BigDecimal
        Parameters:
        self - a Number
        Returns:
        an BigDecimal
        Since:
        1.0
      • asType

        public static <T> T asType​(java.lang.Number self,
                                   java.lang.Class<T> c)
        Transform this number to a the given type, using the 'as' operator. The following types are supported in addition to the default asType(java.lang.Object, java.lang.Class):
        • BigDecimal
        • BigInteger
        • Double
        • Float
        Parameters:
        self - this number
        c - the desired type of the transformed result
        Returns:
        an instance of the given type
        Since:
        1.0
      • toBigInteger

        public static java.math.BigInteger toBigInteger​(java.lang.Number self)
        Transform this Number into a BigInteger.
        Parameters:
        self - a Number
        Returns:
        an BigInteger
        Since:
        1.0
      • and

        public static java.lang.Boolean and​(java.lang.Boolean left,
                                            java.lang.Boolean right)
        Logical conjunction of two boolean operators.
        Parameters:
        left - left operator
        right - right operator
        Returns:
        result of logical conjunction
        Since:
        1.0
      • or

        public static java.lang.Boolean or​(java.lang.Boolean left,
                                           java.lang.Boolean right)
        Logical disjunction of two boolean operators
        Parameters:
        left - left operator
        right - right operator
        Returns:
        result of logical disjunction
        Since:
        1.0
      • implies

        public static java.lang.Boolean implies​(java.lang.Boolean left,
                                                java.lang.Boolean right)
        Logical implication of two boolean operators
        Parameters:
        left - left operator
        right - right operator
        Returns:
        result of logical implication
        Since:
        1.8.3
      • xor

        public static java.lang.Boolean xor​(java.lang.Boolean left,
                                            java.lang.Boolean right)
        Exclusive disjunction of two boolean operators
        Parameters:
        left - left operator
        right - right operator
        Returns:
        result of exclusive disjunction
        Since:
        1.0
      • newObjectOutputStream

        public static java.io.ObjectOutputStream newObjectOutputStream​(java.io.File file)
                                                                throws java.io.IOException
        Create an object output stream for this file.
        Parameters:
        file - a file
        Returns:
        an object output stream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • newObjectOutputStream

        public static java.io.ObjectOutputStream newObjectOutputStream​(java.io.OutputStream outputStream)
                                                                throws java.io.IOException
        Create an object output stream for this output stream.
        Parameters:
        outputStream - an output stream
        Returns:
        an object output stream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • withObjectOutputStream

        public static <T> T withObjectOutputStream​(java.io.File file,
                                                   Closure<T> closure)
                                            throws java.io.IOException
        Create a new ObjectOutputStream for this file and then pass it to the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        file - a File
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
        See Also:
        withStream(java.io.OutputStream, groovy.lang.Closure)
      • withObjectOutputStream

        public static <T> T withObjectOutputStream​(java.io.OutputStream outputStream,
                                                   Closure<T> closure)
                                            throws java.io.IOException
        Create a new ObjectOutputStream for this output stream and then pass it to the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        outputStream - am output stream
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
        See Also:
        withStream(java.io.OutputStream, groovy.lang.Closure)
      • newObjectInputStream

        public static java.io.ObjectInputStream newObjectInputStream​(java.io.File file)
                                                              throws java.io.IOException
        Create an object input stream for this file.
        Parameters:
        file - a file
        Returns:
        an object input stream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • newObjectInputStream

        public static java.io.ObjectInputStream newObjectInputStream​(java.io.InputStream inputStream)
                                                              throws java.io.IOException
        Create an object input stream for this input stream.
        Parameters:
        inputStream - an input stream
        Returns:
        an object input stream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • newObjectInputStream

        public static java.io.ObjectInputStream newObjectInputStream​(java.io.InputStream inputStream,
                                                                     java.lang.ClassLoader classLoader)
                                                              throws java.io.IOException
        Create an object input stream for this input stream using the given class loader.
        Parameters:
        inputStream - an input stream
        classLoader - the class loader to use when loading the class
        Returns:
        an object input stream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • newObjectInputStream

        public static java.io.ObjectInputStream newObjectInputStream​(java.io.File file,
                                                                     java.lang.ClassLoader classLoader)
                                                              throws java.io.IOException
        Create an object input stream for this file using the given class loader.
        Parameters:
        file - a file
        classLoader - the class loader to use when loading the class
        Returns:
        an object input stream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • eachObject

        public static void eachObject​(java.io.File self,
                                      Closure closure)
                               throws java.io.IOException,
                                      java.lang.ClassNotFoundException
        Iterates through the given file object by object.
        Parameters:
        self - a File
        closure - a closure
        Throws:
        java.io.IOException - if an IOException occurs.
        java.lang.ClassNotFoundException - if the class is not found.
        Since:
        1.0
        See Also:
        eachObject(java.io.ObjectInputStream, groovy.lang.Closure)
      • eachObject

        public static void eachObject​(java.io.ObjectInputStream ois,
                                      Closure closure)
                               throws java.io.IOException,
                                      java.lang.ClassNotFoundException
        Iterates through the given object stream object by object. The ObjectInputStream is closed afterwards.
        Parameters:
        ois - an ObjectInputStream, closed after the operation
        closure - a closure
        Throws:
        java.io.IOException - if an IOException occurs.
        java.lang.ClassNotFoundException - if the class is not found.
        Since:
        1.0
      • withObjectInputStream

        public static <T> T withObjectInputStream​(java.io.File file,
                                                  Closure<T> closure)
                                           throws java.io.IOException
        Create a new ObjectInputStream for this file and pass it to the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        file - a File
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
        See Also:
        withStream(java.io.InputStream, groovy.lang.Closure)
      • withObjectInputStream

        public static <T> T withObjectInputStream​(java.io.File file,
                                                  java.lang.ClassLoader classLoader,
                                                  Closure<T> closure)
                                           throws java.io.IOException
        Create a new ObjectInputStream for this file associated with the given class loader and pass it to the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        file - a File
        classLoader - the class loader to use when loading the class
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
        See Also:
        withStream(java.io.InputStream, groovy.lang.Closure)
      • withObjectInputStream

        public static <T> T withObjectInputStream​(java.io.InputStream inputStream,
                                                  Closure<T> closure)
                                           throws java.io.IOException
        Create a new ObjectInputStream for this file and pass it to the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        inputStream - an input stream
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
        See Also:
        withStream(java.io.InputStream, groovy.lang.Closure)
      • withObjectInputStream

        public static <T> T withObjectInputStream​(java.io.InputStream inputStream,
                                                  java.lang.ClassLoader classLoader,
                                                  Closure<T> closure)
                                           throws java.io.IOException
        Create a new ObjectInputStream for this file and pass it to the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        inputStream - an input stream
        classLoader - the class loader to use when loading the class
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
        See Also:
        withStream(java.io.InputStream, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.lang.String self,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this String line by line. Each line is passed to the given 1 or 2 arg closure. If a 2 arg closure is found the line count is passed as the second argument.
        Parameters:
        self - a String
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an error occurs
        Since:
        1.5.5
        See Also:
        eachLine(java.lang.String, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.lang.CharSequence self,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this CharSequence line by line. Each line is passed to the given 1 or 2 arg closure. If a 2 arg closure is found the line count is passed as the second argument.
        Parameters:
        self - a CharSequence
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an error occurs
        Since:
        1.8.2
        See Also:
        eachLine(java.lang.String, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.lang.String self,
                                     int firstLine,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this String line by line. Each line is passed to the given 1 or 2 arg closure. If a 2 arg closure is found the line count is passed as the second argument.
        Parameters:
        self - a String
        firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
        closure - a closure (arg 1 is line, optional arg 2 is line number)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an error occurs
        Since:
        1.5.7
      • eachLine

        public static <T> T eachLine​(java.lang.CharSequence self,
                                     int firstLine,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this CharSequence line by line. Each line is passed to the given 1 or 2 arg closure. If a 2 arg closure is found the line count is passed as the second argument.
        Parameters:
        self - a CharSequence
        firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
        closure - a closure (arg 1 is line, optional arg 2 is line number)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an error occurs
        Since:
        1.8.2
        See Also:
        eachLine(java.lang.String, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.io.File self,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file is read using a reader which is closed before this method returns.
        Parameters:
        self - a File
        closure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.5
        See Also:
        eachLine(java.io.File, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.io.File self,
                                     java.lang.String charset,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file is read using a reader which is closed before this method returns.
        Parameters:
        self - a File
        charset - opens the file with a specified charset
        closure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        eachLine(java.io.File, java.lang.String, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.io.File self,
                                     int firstLine,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file is read using a reader which is closed before this method returns.
        Parameters:
        self - a File
        firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
        closure - a closure (arg 1 is line, optional arg 2 is line number)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.7
        See Also:
        eachLine(java.io.Reader, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.io.File self,
                                     java.lang.String charset,
                                     int firstLine,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this file line by line. Each line is passed to the given 1 or 2 arg closure. The file is read using a reader which is closed before this method returns.
        Parameters:
        self - a File
        charset - opens the file with a specified charset
        firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
        closure - a closure (arg 1 is line, optional arg 2 is line number)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        eachLine(java.io.Reader, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.io.InputStream stream,
                                     java.lang.String charset,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
        Parameters:
        stream - a stream
        charset - opens the stream with a specified charset
        closure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.5
        See Also:
        eachLine(java.io.InputStream, java.lang.String, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.io.InputStream stream,
                                     java.lang.String charset,
                                     int firstLine,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this stream reading with the provided charset, passing each line to the given 1 or 2 arg closure. The stream is closed after this method returns.
        Parameters:
        stream - a stream
        charset - opens the stream with a specified charset
        firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
        closure - a closure (arg 1 is line, optional arg 2 is line number)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.7
        See Also:
        eachLine(java.io.Reader, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.io.InputStream stream,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this stream, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
        Parameters:
        stream - a stream
        closure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.6
        See Also:
        eachLine(java.io.InputStream, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.io.InputStream stream,
                                     int firstLine,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through this stream, passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
        Parameters:
        stream - a stream
        firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
        closure - a closure (arg 1 is line, optional arg 2 is line number)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.7
        See Also:
        eachLine(java.io.Reader, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.net.URL url,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
        Parameters:
        url - a URL to open and read
        closure - a closure to apply on each line (arg 1 is line, optional arg 2 is line number starting at line 1)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.6
        See Also:
        eachLine(java.net.URL, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.net.URL url,
                                     int firstLine,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
        Parameters:
        url - a URL to open and read
        firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
        closure - a closure to apply on each line (arg 1 is line, optional arg 2 is line number)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.7
        See Also:
        eachLine(java.io.InputStream, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.net.URL url,
                                     java.lang.String charset,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
        Parameters:
        url - a URL to open and read
        charset - opens the stream with a specified charset
        closure - a closure to apply on each line (arg 1 is line, optional arg 2 is line number starting at line 1)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.6
        See Also:
        eachLine(java.net.URL, java.lang.String, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.net.URL url,
                                     java.lang.String charset,
                                     int firstLine,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through the lines read from the URL's associated input stream passing each line to the given 1 or 2 arg closure. The stream is closed before this method returns.
        Parameters:
        url - a URL to open and read
        charset - opens the stream with a specified charset
        firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
        closure - a closure to apply on each line (arg 1 is line, optional arg 2 is line number)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.7
        See Also:
        eachLine(java.io.Reader, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.io.Reader self,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through the given reader line by line. Each line is passed to the given 1 or 2 arg closure. If the closure has two arguments, the line count is passed as the second argument. The Reader is closed before this method returns.
        Parameters:
        self - a Reader, closed after the method returns
        closure - a closure (arg 1 is line, optional arg 2 is line number starting at line 1)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.6
        See Also:
        eachLine(java.io.Reader, int, groovy.lang.Closure)
      • eachLine

        public static <T> T eachLine​(java.io.Reader self,
                                     int firstLine,
                                     Closure<T> closure)
                              throws java.io.IOException
        Iterates through the given reader line by line. Each line is passed to the given 1 or 2 arg closure. If the closure has two arguments, the line count is passed as the second argument. The Reader is closed before this method returns.
        Parameters:
        self - a Reader, closed after the method returns
        firstLine - the line number value used for the first line (default is 1, set to 0 to start counting from 0)
        closure - a closure which will be passed each line (or for 2 arg closures the line and line count)
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.7
      • splitEachLine

        public static <T> T splitEachLine​(java.io.File self,
                                          java.lang.String regex,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through this file line by line, splitting each line using the given regex separator. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the file are closed.
        Parameters:
        self - a File
        regex - the delimiting regular expression
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.5.5
        See Also:
        splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.io.File self,
                                          java.util.regex.Pattern pattern,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through this file line by line, splitting each line using the given separator Pattern. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression Pattern. Finally the resources used for processing the file are closed.
        Parameters:
        self - a File
        pattern - the regular expression Pattern for the delimiter
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.io.File self,
                                          java.lang.String regex,
                                          java.lang.String charset,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through this file line by line, splitting each line using the given regex separator. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the file are closed.
        Parameters:
        self - a File
        regex - the delimiting regular expression
        charset - opens the file with a specified charset
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.6.8
        See Also:
        splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.io.File self,
                                          java.util.regex.Pattern pattern,
                                          java.lang.String charset,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through this file line by line, splitting each line using the given regex separator Pattern. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the file are closed.
        Parameters:
        self - a File
        pattern - the regular expression Pattern for the delimiter
        charset - opens the file with a specified charset
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.net.URL self,
                                          java.lang.String regex,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the URL are closed.
        Parameters:
        self - a URL to open and read
        regex - the delimiting regular expression
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.6.8
        See Also:
        splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.net.URL self,
                                          java.util.regex.Pattern pattern,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the URL are closed.
        Parameters:
        self - a URL to open and read
        pattern - the regular expression Pattern for the delimiter
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.net.URL self,
                                          java.lang.String regex,
                                          java.lang.String charset,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the URL are closed.
        Parameters:
        self - a URL to open and read
        regex - the delimiting regular expression
        charset - opens the file with a specified charset
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.6.8
        See Also:
        splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.net.URL self,
                                          java.util.regex.Pattern pattern,
                                          java.lang.String charset,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the input stream associated with this URL line by line, splitting each line using the given regex separator Pattern. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. Finally the resources used for processing the URL are closed.
        Parameters:
        self - a URL to open and read
        pattern - the regular expression Pattern for the delimiter
        charset - opens the file with a specified charset
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.io.Reader self,
                                          java.lang.String regex,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the given reader line by line, splitting each line using the given regex separator. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. The Reader is closed afterwards.

        Here is an example:

         def s = 'The 3 quick\nbrown 4 fox'
         def result = ''
         new StringReader(s).splitEachLine(/\d/){ parts ->
             result += "${parts[0]}_${parts[1]}|"
         }
         assert result == 'The _ quick|brown _ fox|'
         
        Parameters:
        self - a Reader, closed after the method returns
        regex - the delimiting regular expression
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.5.5
        See Also:
        String.split(java.lang.String)
      • splitEachLine

        public static <T> T splitEachLine​(java.io.Reader self,
                                          java.util.regex.Pattern pattern,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the given reader line by line, splitting each line using the given regex separator Pattern. For each line, the given closure is called with a single parameter being the list of strings computed by splitting the line around matches of the given regular expression. The Reader is closed afterwards.

        Here is an example:

         def s = 'The 3 quick\nbrown 4 fox'
         def result = ''
         new StringReader(s).splitEachLine(~/\d/){ parts ->
             result += "${parts[0]}_${parts[1]}|"
         }
         assert result == 'The _ quick|brown _ fox|'
         
        Parameters:
        self - a Reader, closed after the method returns
        pattern - the regular expression Pattern for the delimiter
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.6.8
        See Also:
        String.split(java.lang.String)
      • splitEachLine

        public static <T> T splitEachLine​(java.io.InputStream stream,
                                          java.lang.String regex,
                                          java.lang.String charset,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure. Finally, the stream is closed.
        Parameters:
        stream - an InputStream
        regex - the delimiting regular expression
        charset - opens the stream with a specified charset
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.5.5
        See Also:
        splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.io.InputStream stream,
                                          java.util.regex.Pattern pattern,
                                          java.lang.String charset,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the given InputStream line by line using the specified encoding, splitting each line using the given separator Pattern. The list of tokens for each line is then passed to the given closure. Finally, the stream is closed.
        Parameters:
        stream - an InputStream
        pattern - the regular expression Pattern for the delimiter
        charset - opens the stream with a specified charset
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.io.InputStream stream,
                                          java.lang.String regex,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the given InputStream line by line, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure. The stream is closed before the method returns.
        Parameters:
        stream - an InputStream
        regex - the delimiting regular expression
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.5.6
        See Also:
        splitEachLine(java.io.Reader, java.lang.String, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.io.InputStream stream,
                                          java.util.regex.Pattern pattern,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the given InputStream line by line, splitting each line using the given separator Pattern. The list of tokens for each line is then passed to the given closure. The stream is closed before the method returns.
        Parameters:
        stream - an InputStream
        pattern - the regular expression Pattern for the delimiter
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        splitEachLine(java.io.Reader, java.util.regex.Pattern, groovy.lang.Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.lang.String self,
                                          java.lang.String regex,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the given String line by line, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure.
        Parameters:
        self - a String
        regex - the delimiting regular expression
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an error occurs
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.5.5
        See Also:
        String.split(java.lang.String)
      • splitEachLine

        public static <T> T splitEachLine​(java.lang.CharSequence self,
                                          java.lang.CharSequence regex,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the given CharSequence line by line, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure.
        Parameters:
        self - a CharSequence
        regex - the delimiting regular expression
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an error occurs
        java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid
        Since:
        1.8.2
        See Also:
        splitEachLine(String, String, Closure)
      • splitEachLine

        public static <T> T splitEachLine​(java.lang.String self,
                                          java.util.regex.Pattern pattern,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the given String line by line, splitting each line using the given separator Pattern. The list of tokens for each line is then passed to the given closure.
        Parameters:
        self - a String
        pattern - the regular expression Pattern for the delimiter
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an error occurs
        Since:
        1.6.8
        See Also:
        Pattern.split(java.lang.CharSequence)
      • splitEachLine

        public static <T> T splitEachLine​(java.lang.CharSequence self,
                                          java.util.regex.Pattern pattern,
                                          Closure<T> closure)
                                   throws java.io.IOException
        Iterates through the given CharSequence line by line, splitting each line using the given separator Pattern. The list of tokens for each line is then passed to the given closure.
        Parameters:
        self - a CharSequence
        pattern - the regular expression Pattern for the delimiter
        closure - a closure
        Returns:
        the last value returned by the closure
        Throws:
        java.io.IOException - if an error occurs
        Since:
        1.8.2
        See Also:
        splitEachLine(String, Pattern, Closure)
      • readLine

        public static java.lang.String readLine​(java.io.Reader self)
                                         throws java.io.IOException
        Read a single, whole line from the given Reader.
        Parameters:
        self - a Reader
        Returns:
        a line
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • denormalize

        public static java.lang.String denormalize​(java.lang.String self)
        Return a String with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator.
        Parameters:
        self - a String object
        Returns:
        the denormalized string
        Since:
        1.6.0
      • denormalize

        public static java.lang.CharSequence denormalize​(java.lang.CharSequence self)
        Return a CharSequence with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator.
        Parameters:
        self - a CharSequence object
        Returns:
        the denormalized CharSequence
        Since:
        1.8.2
        See Also:
        denormalize(String)
      • normalize

        public static java.lang.String normalize​(java.lang.String self)
        Return a String with linefeeds and carriage returns normalized to linefeeds.
        Parameters:
        self - a String object
        Returns:
        the normalized string
        Since:
        1.6.0
      • normalize

        public static java.lang.CharSequence normalize​(java.lang.CharSequence self)
        Return a CharSequence with linefeeds and carriage returns normalized to linefeeds.
        Parameters:
        self - a CharSequence object
        Returns:
        the normalized CharSequence
        Since:
        1.8.2
        See Also:
        normalize(String)
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.lang.String self)
                                                          throws java.io.IOException
        Return the lines of a String as a List of Strings.
        Parameters:
        self - a String object
        Returns:
        a list of lines
        Throws:
        java.io.IOException - if an error occurs
        Since:
        1.5.5
      • readLines

        public static java.util.List<java.lang.CharSequence> readLines​(java.lang.CharSequence self)
                                                                throws java.io.IOException
        Return the lines of a CharSequence as a List of CharSequence.
        Parameters:
        self - a CharSequence object
        Returns:
        a list of lines
        Throws:
        java.io.IOException - if an error occurs
        Since:
        1.8.2
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.io.File file)
                                                          throws java.io.IOException
        Reads the file into a list of Strings, with one item for each line.
        Parameters:
        file - a File
        Returns:
        a List of lines
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
        See Also:
        readLines(java.io.Reader)
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.io.File file,
                                                                 java.lang.String charset)
                                                          throws java.io.IOException
        Reads the file into a list of Strings, with one item for each line.
        Parameters:
        file - a File
        charset - opens the file with a specified charset
        Returns:
        a List of lines
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        readLines(java.io.Reader)
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.io.InputStream stream)
                                                          throws java.io.IOException
        Reads the stream into a list, with one element for each line.
        Parameters:
        stream - a stream
        Returns:
        a List of lines
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
        See Also:
        readLines(java.io.Reader)
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.io.InputStream stream,
                                                                 java.lang.String charset)
                                                          throws java.io.IOException
        Reads the stream into a list, with one element for each line.
        Parameters:
        stream - a stream
        charset - opens the stream with a specified charset
        Returns:
        a List of lines
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        readLines(java.io.Reader)
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.net.URL self)
                                                          throws java.io.IOException
        Reads the URL contents into a list, with one element for each line.
        Parameters:
        self - a URL
        Returns:
        a List of lines
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        readLines(java.io.Reader)
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.net.URL self,
                                                                 java.lang.String charset)
                                                          throws java.io.IOException
        Reads the URL contents into a list, with one element for each line.
        Parameters:
        self - a URL
        charset - opens the URL with a specified charset
        Returns:
        a List of lines
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        readLines(java.io.Reader)
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.io.Reader reader)
                                                          throws java.io.IOException
        Reads the reader into a list of Strings, with one entry for each line. The reader is closed before this method returns.
        Parameters:
        reader - a Reader
        Returns:
        a List of lines
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • getText

        public static java.lang.String getText​(java.io.File file,
                                               java.lang.String charset)
                                        throws java.io.IOException
        Read the content of the File using the specified encoding and return it as a String.
        Parameters:
        file - the file whose content we want to read
        charset - the charset used to read the content of the file
        Returns:
        a String containing the content of the file
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • getText

        public static java.lang.String getText​(java.io.File file)
                                        throws java.io.IOException
        Read the content of the File and returns it as a String.
        Parameters:
        file - the file whose content we want to read
        Returns:
        a String containing the content of the file
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • getText

        public static java.lang.String getText​(java.net.URL url)
                                        throws java.io.IOException
        Read the content of this URL and returns it as a String.
        Parameters:
        url - URL to read content from
        Returns:
        the text from that URL
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • getText

        public static java.lang.String getText​(java.net.URL url,
                                               java.util.Map parameters)
                                        throws java.io.IOException
        Read the content of this URL and returns it as a String.
        Parameters:
        url - URL to read content from
        parameters - connection parameters
        Returns:
        the text from that URL
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.8.1
      • getText

        public static java.lang.String getText​(java.net.URL url,
                                               java.lang.String charset)
                                        throws java.io.IOException
        Read the data from this URL and return it as a String. The connection stream is closed before this method returns.
        Parameters:
        url - URL to read content from
        charset - opens the stream with a specified charset
        Returns:
        the text from that URL
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
        See Also:
        URLConnection.getInputStream()
      • getText

        public static java.lang.String getText​(java.net.URL url,
                                               java.util.Map parameters,
                                               java.lang.String charset)
                                        throws java.io.IOException
        Read the data from this URL and return it as a String. The connection stream is closed before this method returns.
        Parameters:
        url - URL to read content from
        parameters - connection parameters
        charset - opens the stream with a specified charset
        Returns:
        the text from that URL
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.8.1
        See Also:
        URLConnection.getInputStream()
      • getText

        public static java.lang.String getText​(java.io.InputStream is)
                                        throws java.io.IOException
        Read the content of this InputStream and return it as a String. The stream is closed before this method returns.
        Parameters:
        is - an input stream
        Returns:
        the text from that URL
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • getText

        public static java.lang.String getText​(java.io.InputStream is,
                                               java.lang.String charset)
                                        throws java.io.IOException
        Read the content of this InputStream using specified charset and return it as a String. The stream is closed before this method returns.
        Parameters:
        is - an input stream
        charset - opens the stream with a specified charset
        Returns:
        the text from that URL
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • getText

        public static java.lang.String getText​(java.io.Reader reader)
                                        throws java.io.IOException
        Read the content of the Reader and return it as a String. The reader is closed before this method returns.
        Parameters:
        reader - a Reader whose content we want to read
        Returns:
        a String containing the content of the buffered reader
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
        See Also:
        getText(java.io.BufferedReader)
      • getText

        public static java.lang.String getText​(java.io.BufferedReader reader)
                                        throws java.io.IOException
        Read the content of the BufferedReader and return it as a String. The BufferedReader is closed afterwards.
        Parameters:
        reader - a BufferedReader whose content we want to read
        Returns:
        a String containing the content of the buffered reader
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • getBytes

        public static byte[] getBytes​(java.io.File file)
                               throws java.io.IOException
        Read the content of the File and returns it as a byte[].
        Parameters:
        file - the file whose content we want to read
        Returns:
        a String containing the content of the file
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.1
      • getBytes

        public static byte[] getBytes​(java.net.URL url)
                               throws java.io.IOException
        Read the content of this URL and returns it as a byte[].
        Parameters:
        url - URL to read content from
        Returns:
        the byte[] from that URL
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.1
      • getBytes

        public static byte[] getBytes​(java.io.InputStream is)
                               throws java.io.IOException
        Read the content of this InputStream and return it as a byte[]. The stream is closed before this method returns.
        Parameters:
        is - an input stream
        Returns:
        the byte[] from that InputStream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.1
      • setBytes

        public static void setBytes​(java.io.File file,
                                    byte[] bytes)
                             throws java.io.IOException
        Write the bytes from the byte array to the File.
        Parameters:
        file - the file to write to
        bytes - the byte[] to write to the file
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.1
      • setBytes

        public static void setBytes​(java.io.OutputStream os,
                                    byte[] bytes)
                             throws java.io.IOException
        Write the byte[] to the output stream. The stream is closed before this method returns.
        Parameters:
        os - an output stream
        bytes - the byte[] to write to the output stream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.1
      • writeLine

        public static void writeLine​(java.io.BufferedWriter writer,
                                     java.lang.String line)
                              throws java.io.IOException
        Write the text and append a newline (using the platform's line-ending).
        Parameters:
        writer - a BufferedWriter
        line - the line to write
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • write

        public static void write​(java.io.File file,
                                 java.lang.String text)
                          throws java.io.IOException
        Write the text to the File.
        Parameters:
        file - a File
        text - the text to write to the File
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • setText

        public static void setText​(java.io.File file,
                                   java.lang.String text)
                            throws java.io.IOException
        Synonym for write(text) allowing file.text = 'foo'.
        Parameters:
        file - a File
        text - the text to write to the File
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.1
        See Also:
        write(java.io.File, java.lang.String)
      • setText

        public static void setText​(java.io.File file,
                                   java.lang.String text,
                                   java.lang.String charset)
                            throws java.io.IOException
        Synonym for write(text, charset) allowing:
         myFile.setText('some text', charset)
         
        or with some help from ExpandoMetaClass, you could do something like:
         myFile.metaClass.setText = { String s -> delegate.setText(s, 'UTF-8') }
         myfile.text = 'some text'
         
        Parameters:
        file - A File
        charset - The charset used when writing to the file
        text - The text to write to the File
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.3
        See Also:
        write(java.io.File, java.lang.String, java.lang.String)
      • leftShift

        public static java.io.File leftShift​(java.io.File file,
                                             java.lang.Object text)
                                      throws java.io.IOException
        Write the text to the File.
        Parameters:
        file - a File
        text - the text to write to the File
        Returns:
        the original file
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • leftShift

        public static java.io.File leftShift​(java.io.File file,
                                             byte[] bytes)
                                      throws java.io.IOException
        Write bytes to a File.
        Parameters:
        file - a File
        bytes - the byte array to append to the end of the File
        Returns:
        the original file
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • leftShift

        public static java.io.File leftShift​(java.io.File file,
                                             java.io.InputStream data)
                                      throws java.io.IOException
        Append binary data to the file. See append(java.io.File, java.io.InputStream)
        Parameters:
        file - a File
        data - an InputStream of data to write to the file
        Returns:
        the file
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • write

        public static void write​(java.io.File file,
                                 java.lang.String text,
                                 java.lang.String charset)
                          throws java.io.IOException
        Write the text to the File, using the specified encoding.
        Parameters:
        file - a File
        text - the text to write to the File
        charset - the charset used
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • append

        public static void append​(java.io.File file,
                                  java.lang.Object text)
                           throws java.io.IOException
        Append the text at the end of the File.
        Parameters:
        file - a File
        text - the text to append at the end of the File
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • append

        public static void append​(java.io.File file,
                                  byte[] bytes)
                           throws java.io.IOException
        Append bytes to the end of a File.
        Parameters:
        file - a File
        bytes - the byte array to append to the end of the File
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.1
      • append

        public static void append​(java.io.File self,
                                  java.io.InputStream stream)
                           throws java.io.IOException
        Append binary data to the file. It will not be interpreted as text.
        Parameters:
        self - a File
        stream - stream to read data from.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • append

        public static void append​(java.io.File file,
                                  java.lang.Object text,
                                  java.lang.String charset)
                           throws java.io.IOException
        Append the text at the end of the File, using a specified encoding.
        Parameters:
        file - a File
        text - the text to append at the end of the File
        charset - the charset used
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • eachFile

        public static void eachFile​(java.io.File self,
                                    FileType fileType,
                                    Closure closure)
                             throws java.io.FileNotFoundException,
                                    java.lang.IllegalArgumentException
        Invokes the closure for each 'child' file in this 'parent' folder/directory. Both regular files and subfolders/subdirectories can be processed depending on the fileType enum value.
        Parameters:
        self - a file object
        fileType - if normal files or directories or both should be processed
        closure - the closure to invoke
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory
        Since:
        1.7.1
      • eachFile

        public static void eachFile​(java.io.File self,
                                    Closure closure)
                             throws java.io.FileNotFoundException,
                                    java.lang.IllegalArgumentException
        Invokes the closure for each 'child' file in this 'parent' folder/directory. Both regular files and subfolders/subdirectories are processed.
        Parameters:
        self - a File (that happens to be a folder/directory)
        closure - a closure (first parameter is the 'child' file)
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory
        Since:
        1.5.0
        See Also:
        File.listFiles(), eachFile(java.io.File, groovy.io.FileType, groovy.lang.Closure)
      • eachDir

        public static void eachDir​(java.io.File self,
                                   Closure closure)
                            throws java.io.FileNotFoundException,
                                   java.lang.IllegalArgumentException
        Invokes the closure for each subdirectory in this directory, ignoring regular files.
        Parameters:
        self - a File (that happens to be a folder/directory)
        closure - a closure (first parameter is the subdirectory file)
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory
        Since:
        1.0
        See Also:
        File.listFiles(), eachFile(java.io.File, groovy.io.FileType, groovy.lang.Closure)
      • eachFileRecurse

        public static void eachFileRecurse​(java.io.File self,
                                           FileType fileType,
                                           Closure closure)
                                    throws java.io.FileNotFoundException,
                                           java.lang.IllegalArgumentException
        Invokes the closure for each descendant file in this directory. Sub-directories are recursively searched in a depth-first fashion. Both regular files and subdirectories may be passed to the closure depending on the value of fileType.
        Parameters:
        self - a file object
        fileType - if normal files or directories or both should be processed
        closure - the closure to invoke on each file
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory
        Since:
        1.7.1
      • traverse

        public static void traverse​(java.io.File self,
                                    java.util.Map<java.lang.String,​java.lang.Object> options,
                                    Closure closure)
                             throws java.io.FileNotFoundException,
                                    java.lang.IllegalArgumentException
        Invokes closure for each descendant file in this directory tree. Sub-directories are recursively traversed as found. The traversal can be adapted by providing various options in the options Map according to the following keys:
        type
        A FileType enum to determine if normal files or directories or both are processed
        preDir
        A Closure run before each directory is processed and optionally returning a FileVisitResult value which can be used to control subsequent processing.
        preRoot
        A boolean indicating that the 'preDir' closure should be applied at the root level
        postDir
        A Closure run after each directory is processed and optionally returning a FileVisitResult value which can be used to control subsequent processing.
        postRoot
        A boolean indicating that the 'postDir' closure should be applied at the root level
        visitRoot
        A boolean indicating that the given closure should be applied for the root dir (not applicable if the 'type' is set to FileType.FILES)
        maxDepth
        The maximum number of directory levels when recursing (default is -1 which means infinite, set to 0 for no recursion)
        filter
        A filter to perform on traversed files/directories (using the isCase(java.lang.Object, java.lang.Object) method). If set, only files/dirs which match are candidates for visiting.
        nameFilter
        A filter to perform on the name of traversed files/directories (using the isCase(java.lang.Object, java.lang.Object) method). If set, only files/dirs which match are candidates for visiting. (Must not be set if 'filter' is set)
        excludeFilter
        A filter to perform on traversed files/directories (using the isCase(java.lang.Object, java.lang.Object) method). If set, any candidates which match won't be visited.
        excludeNameFilter
        A filter to perform on the names of traversed files/directories (using the isCase(java.lang.Object, java.lang.Object) method). If set, any candidates which match won't be visited. (Must not be set if 'excludeFilter' is set)
        sort
        A Closure which if set causes the files and subdirectories for each directory to be processed in sorted order. Note that even when processing only files, the order of visited subdirectories will be affected by this parameter.
        This example prints out file counts and size aggregates for groovy source files within a directory tree:
         def totalSize = 0
         def count = 0
         def sortByTypeThenName = { a, b ->
             a.isFile() != b.isFile() ? a.isFile() <=> b.isFile() : a.name <=> b.name
         }
         rootDir.traverse(
                 type         : FILES,
                 nameFilter   : ~/.*\.groovy/,
                 preDir       : { if (it.name == '.svn') return SKIP_SUBTREE },
                 postDir      : { println "Found $count files in $it.name totalling $totalSize bytes"
                                 totalSize = 0; count = 0 },
                 postRoot     : true
                 sort         : sortByTypeThenName
         ) {it -> totalSize += it.size(); count++ }
         
        Parameters:
        self - a File
        options - a Map of options to alter the traversal behavior
        closure - the Closure to invoke on each file/directory and optionally returning a FileVisitResult value which can be used to control subsequent processing
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory or illegal filter combinations are supplied
        Since:
        1.7.1
        See Also:
        sort(java.util.Collection, groovy.lang.Closure), FileVisitResult, FileType
      • traverse

        public static void traverse​(java.io.File self,
                                    Closure closure)
                             throws java.io.FileNotFoundException,
                                    java.lang.IllegalArgumentException
        Invokes the closure for each descendant file in this directory tree. Sub-directories are recursively traversed in a depth-first fashion. Convenience method for traverse(java.io.File, java.util.Map, groovy.lang.Closure) when no options to alter the traversal behavior are required.
        Parameters:
        self - a File
        closure - the Closure to invoke on each file/directory and optionally returning a FileVisitResult value which can be used to control subsequent processing
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory
        Since:
        1.7.1
        See Also:
        traverse(java.io.File, java.util.Map, groovy.lang.Closure)
      • traverse

        public static void traverse​(java.io.File self,
                                    java.util.Map<java.lang.String,​java.lang.Object> options)
                             throws java.io.FileNotFoundException,
                                    java.lang.IllegalArgumentException
        Invokes the closure specified with key 'visit' in the options Map for each descendant file in this directory tree. Convenience method for traverse(java.io.File, java.util.Map, groovy.lang.Closure) allowing the 'visit' closure to be included in the options Map rather than as a parameter.
        Parameters:
        self - a File
        options - a Map of options to alter the traversal behavior
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory or illegal filter combinations are supplied
        Since:
        1.7.1
        See Also:
        traverse(java.io.File, java.util.Map, groovy.lang.Closure)
      • eachFileRecurse

        public static void eachFileRecurse​(java.io.File self,
                                           Closure closure)
                                    throws java.io.FileNotFoundException,
                                           java.lang.IllegalArgumentException
        Invokes the closure for each descendant file in this directory. Sub-directories are recursively searched in a depth-first fashion. Both regular files and subdirectories are passed to the closure.
        Parameters:
        self - a File
        closure - a closure
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory
        Since:
        1.0
        See Also:
        eachFileRecurse(java.io.File, groovy.io.FileType, groovy.lang.Closure)
      • eachDirRecurse

        public static void eachDirRecurse​(java.io.File self,
                                          Closure closure)
                                   throws java.io.FileNotFoundException,
                                          java.lang.IllegalArgumentException
        Invokes the closure for each descendant directory of this directory. Sub-directories are recursively searched in a depth-first fashion. Only subdirectories are passed to the closure; regular files are ignored.
        Parameters:
        self - a directory
        closure - a closure
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory
        Since:
        1.5.0
        See Also:
        eachFileRecurse(java.io.File, groovy.io.FileType, groovy.lang.Closure)
      • eachFileMatch

        public static void eachFileMatch​(java.io.File self,
                                         FileType fileType,
                                         java.lang.Object nameFilter,
                                         Closure closure)
                                  throws java.io.FileNotFoundException,
                                         java.lang.IllegalArgumentException
        Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Both regular files and subdirectories may be candidates for matching depending on the value of fileType.
         // collect names of files in baseDir matching supplied regex pattern
         import static groovy.io.FileType.*
         def names = []
         baseDir.eachFileMatch FILES, ~/foo\d\.txt/, { names << it.name }
         assert names == ['foo1.txt', 'foo2.txt']
        
         // remove all *.bak files in baseDir
         baseDir.eachFileMatch FILES, ~/.*\.bak/, { File bak -> bak.delete() }
        
         // print out files > 4K in size from baseDir
         baseDir.eachFileMatch FILES, { new File(baseDir, it).size() > 4096 }, { println "$it.name ${it.size()}" }
         
        Parameters:
        self - a file
        fileType - whether normal files or directories or both should be processed
        nameFilter - the filter to perform on the name of the file/directory (using the isCase(java.lang.Object, java.lang.Object) method)
        closure - the closure to invoke
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory
        Since:
        1.7.1
      • eachFileMatch

        public static void eachFileMatch​(java.io.File self,
                                         java.lang.Object nameFilter,
                                         Closure closure)
                                  throws java.io.FileNotFoundException,
                                         java.lang.IllegalArgumentException
        Invokes the closure for each file whose name (file.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Both regular files and subdirectories are matched.
        Parameters:
        self - a file
        nameFilter - the nameFilter to perform on the name of the file (using the isCase(java.lang.Object, java.lang.Object) method)
        closure - the closure to invoke
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory
        Since:
        1.5.0
        See Also:
        eachFileMatch(java.io.File, groovy.io.FileType, java.lang.Object, groovy.lang.Closure)
      • eachDirMatch

        public static void eachDirMatch​(java.io.File self,
                                        java.lang.Object nameFilter,
                                        Closure closure)
                                 throws java.io.FileNotFoundException,
                                        java.lang.IllegalArgumentException
        Invokes the closure for each subdirectory whose name (dir.name) matches the given nameFilter in the given directory - calling the isCase(java.lang.Object, java.lang.Object) method to determine if a match occurs. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Only subdirectories are matched; regular files are ignored.
        Parameters:
        self - a file
        nameFilter - the nameFilter to perform on the name of the directory (using the isCase(java.lang.Object, java.lang.Object) method)
        closure - the closure to invoke
        Throws:
        java.io.FileNotFoundException - if the given directory does not exist
        java.lang.IllegalArgumentException - if the provided File object does not represent a directory
        Since:
        1.5.0
        See Also:
        eachFileMatch(java.io.File, groovy.io.FileType, java.lang.Object, groovy.lang.Closure)
      • deleteDir

        public static boolean deleteDir​(java.io.File self)
        Deletes a directory with all contained files and subdirectories.

        The method returns

        • true, when deletion was successful
        • true, when it is called for a non existing directory
        • false, when it is called for a file which isn't a directory
        • false, when directory couldn't be deleted

        Parameters:
        self - a File
        Returns:
        true if the file doesn't exist or deletion was successful
        Since:
        1.6.0
      • renameTo

        public static boolean renameTo​(java.io.File self,
                                       java.lang.String newPathName)
        Renames the file. It's a shortcut for File.renameTo(File)
        Parameters:
        self - a File
        newPathName - The new pathname for the named file
        Returns:
        true if and only if the renaming succeeded; false otherwise
        Since:
        1.7.4
      • runAfter

        public static java.util.TimerTask runAfter​(java.util.Timer timer,
                                                   int delay,
                                                   Closure closure)
        Allows a simple syntax for using timers. This timer will execute the given closure after the given delay.
        Parameters:
        timer - a timer object
        delay - the delay in milliseconds before running the closure code
        closure - the closure to invoke
        Returns:
        The timer task which has been scheduled.
        Since:
        1.5.0
      • newReader

        public static java.io.BufferedReader newReader​(java.io.File file)
                                                throws java.io.IOException
        Create a buffered reader for this file.
        Parameters:
        file - a File
        Returns:
        a BufferedReader
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • newReader

        public static java.io.BufferedReader newReader​(java.io.File file,
                                                       java.lang.String charset)
                                                throws java.io.FileNotFoundException,
                                                       java.io.UnsupportedEncodingException
        Create a buffered reader for this file, using the specified charset as the encoding.
        Parameters:
        file - a File
        charset - the charset for this File
        Returns:
        a BufferedReader
        Throws:
        java.io.FileNotFoundException - if the File was not found
        java.io.UnsupportedEncodingException - if the encoding specified is not supported
        Since:
        1.0
      • newReader

        public static java.io.BufferedReader newReader​(java.io.InputStream self)
        Creates a reader for this input stream.
        Parameters:
        self - an input stream
        Returns:
        a reader
        Since:
        1.0
      • newReader

        public static java.io.BufferedReader newReader​(java.io.InputStream self,
                                                       java.lang.String charset)
                                                throws java.io.UnsupportedEncodingException
        Creates a reader for this input stream, using the specified charset as the encoding.
        Parameters:
        self - an input stream
        charset - the charset for this input stream
        Returns:
        a reader
        Throws:
        java.io.UnsupportedEncodingException - if the encoding specified is not supported
        Since:
        1.6.0
      • withReader

        public static <T> T withReader​(java.io.File file,
                                       Closure<T> closure)
                                throws java.io.IOException
        Create a new BufferedReader for this file and then passes it into the closure, ensuring the reader is closed after the closure returns.
        Parameters:
        file - a file object
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withReader

        public static <T> T withReader​(java.io.File file,
                                       java.lang.String charset,
                                       Closure<T> closure)
                                throws java.io.IOException
        Create a new BufferedReader for this file using the specified charset and then passes it into the closure, ensuring the reader is closed after the closure returns.
        Parameters:
        file - a file object
        charset - the charset for this input stream
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.0
      • newOutputStream

        public static java.io.BufferedOutputStream newOutputStream​(java.io.File file)
                                                            throws java.io.IOException
        Create a buffered output stream for this file.
        Parameters:
        file - a file object
        Returns:
        the created OutputStream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • newDataOutputStream

        public static java.io.DataOutputStream newDataOutputStream​(java.io.File file)
                                                            throws java.io.IOException
        Creates a new data output stream for this file.
        Parameters:
        file - a file object
        Returns:
        the created DataOutputStream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • withOutputStream

        public static java.lang.Object withOutputStream​(java.io.File file,
                                                        Closure closure)
                                                 throws java.io.IOException
        Creates a new OutputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        file - a File
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
        See Also:
        withStream(java.io.OutputStream, groovy.lang.Closure)
      • withInputStream

        public static java.lang.Object withInputStream​(java.io.File file,
                                                       Closure closure)
                                                throws java.io.IOException
        Create a new InputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        file - a File
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
        See Also:
        withStream(java.io.InputStream, groovy.lang.Closure)
      • withInputStream

        public static <T> T withInputStream​(java.net.URL url,
                                            Closure<T> closure)
                                     throws java.io.IOException
        Creates a new InputStream for this URL and passes it into the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        url - a URL
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
        See Also:
        withStream(java.io.InputStream, groovy.lang.Closure)
      • withDataOutputStream

        public static <T> T withDataOutputStream​(java.io.File file,
                                                 Closure<T> closure)
                                          throws java.io.IOException
        Create a new DataOutputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        file - a File
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
        See Also:
        withStream(java.io.OutputStream, groovy.lang.Closure)
      • withDataInputStream

        public static <T> T withDataInputStream​(java.io.File file,
                                                Closure<T> closure)
                                         throws java.io.IOException
        Create a new DataInputStream for this file and passes it into the closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        file - a File
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
        See Also:
        withStream(java.io.InputStream, groovy.lang.Closure)
      • newWriter

        public static java.io.BufferedWriter newWriter​(java.io.File file)
                                                throws java.io.IOException
        Create a buffered writer for this file.
        Parameters:
        file - a File
        Returns:
        a BufferedWriter
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • newWriter

        public static java.io.BufferedWriter newWriter​(java.io.File file,
                                                       boolean append)
                                                throws java.io.IOException
        Creates a buffered writer for this file, optionally appending to the existing file content.
        Parameters:
        file - a File
        append - true if data should be appended to the file
        Returns:
        a BufferedWriter
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • newWriter

        public static java.io.BufferedWriter newWriter​(java.io.File file,
                                                       java.lang.String charset,
                                                       boolean append)
                                                throws java.io.IOException
        Helper method to create a buffered writer for a file. If the given charset is "UTF-16BE" or "UTF-16LE", the requisite byte order mark is written to the stream before the writer is returned.
        Parameters:
        file - a File
        charset - the name of the encoding used to write in this file
        append - true if in append mode
        Returns:
        a BufferedWriter
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • newWriter

        public static java.io.BufferedWriter newWriter​(java.io.File file,
                                                       java.lang.String charset)
                                                throws java.io.IOException
        Creates a buffered writer for this file, writing data using the given encoding.
        Parameters:
        file - a File
        charset - the name of the encoding used to write in this file
        Returns:
        a BufferedWriter
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • withWriter

        public static <T> T withWriter​(java.io.File file,
                                       Closure<T> closure)
                                throws java.io.IOException
        Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns.
        Parameters:
        file - a File
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withWriter

        public static <T> T withWriter​(java.io.File file,
                                       java.lang.String charset,
                                       Closure<T> closure)
                                throws java.io.IOException
        Creates a new BufferedWriter for this file, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. The writer will use the given charset encoding.
        Parameters:
        file - a File
        charset - the charset used
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withWriterAppend

        public static <T> T withWriterAppend​(java.io.File file,
                                             java.lang.String charset,
                                             Closure<T> closure)
                                      throws java.io.IOException
        Create a new BufferedWriter which will append to this file. The writer is passed to the closure and will be closed before this method returns.
        Parameters:
        file - a File
        charset - the charset used
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withWriterAppend

        public static <T> T withWriterAppend​(java.io.File file,
                                             Closure<T> closure)
                                      throws java.io.IOException
        Create a new BufferedWriter for this file in append mode. The writer is passed to the closure and is closed after the closure returns.
        Parameters:
        file - a File
        closure - a closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • newPrintWriter

        public static java.io.PrintWriter newPrintWriter​(java.io.File file)
                                                  throws java.io.IOException
        Create a new PrintWriter for this file.
        Parameters:
        file - a File
        Returns:
        the created PrintWriter
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • newPrintWriter

        public static java.io.PrintWriter newPrintWriter​(java.io.File file,
                                                         java.lang.String charset)
                                                  throws java.io.IOException
        Create a new PrintWriter for this file, using specified charset.
        Parameters:
        file - a File
        charset - the charset
        Returns:
        a PrintWriter
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • newPrintWriter

        public static java.io.PrintWriter newPrintWriter​(java.io.Writer writer)
        Create a new PrintWriter for this file, using specified charset.
        Parameters:
        writer - a writer
        Returns:
        a PrintWriter
        Since:
        1.6.0
      • withPrintWriter

        public static <T> T withPrintWriter​(java.io.File file,
                                            Closure<T> closure)
                                     throws java.io.IOException
        Create a new PrintWriter for this file which is then passed it into the given closure. This method ensures its the writer is closed after the closure returns.
        Parameters:
        file - a File
        closure - the closure to invoke with the PrintWriter
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withPrintWriter

        public static <T> T withPrintWriter​(java.io.File file,
                                            java.lang.String charset,
                                            Closure<T> closure)
                                     throws java.io.IOException
        Create a new PrintWriter with a specified charset for this file. The writer is passed to the closure, and will be closed before this method returns.
        Parameters:
        file - a File
        charset - the charset
        closure - the closure to invoke with the PrintWriter
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withPrintWriter

        public static <T> T withPrintWriter​(java.io.Writer writer,
                                            Closure<T> closure)
                                     throws java.io.IOException
        Create a new PrintWriter with a specified charset for this file. The writer is passed to the closure, and will be closed before this method returns.
        Parameters:
        writer - a writer
        closure - the closure to invoke with the PrintWriter
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.0
      • withWriter

        public static <T> T withWriter​(java.io.Writer writer,
                                       Closure<T> closure)
                                throws java.io.IOException
        Allows this writer to be used within the closure, ensuring that it is flushed and closed before this method returns.
        Parameters:
        writer - the writer which is used and then closed
        closure - the closure that the writer is passed into
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withReader

        public static <T> T withReader​(java.io.Reader reader,
                                       Closure<T> closure)
                                throws java.io.IOException
        Allows this reader to be used within the closure, ensuring that it is closed before this method returns.
        Parameters:
        reader - the reader which is used and then closed
        closure - the closure that the writer is passed into
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withStream

        public static <T> T withStream​(java.io.InputStream stream,
                                       Closure<T> closure)
                                throws java.io.IOException
        Allows this input stream to be used within the closure, ensuring that it is flushed and closed before this method returns.
        Parameters:
        stream - the stream which is used and then closed
        closure - the closure that the stream is passed into
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withReader

        public static <T> T withReader​(java.net.URL url,
                                       Closure<T> closure)
                                throws java.io.IOException
        Helper method to create a new BufferedReader for a URL and then passes it to the closure. The reader is closed after the closure returns.
        Parameters:
        url - a URL
        closure - the closure to invoke with the reader
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withReader

        public static <T> T withReader​(java.net.URL url,
                                       java.lang.String charset,
                                       Closure<T> closure)
                                throws java.io.IOException
        Helper method to create a new Reader for a URL and then passes it to the closure. The reader is closed after the closure returns.
        Parameters:
        url - a URL
        charset - the charset used
        closure - the closure to invoke with the reader
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.6
      • withReader

        public static <T> T withReader​(java.io.InputStream in,
                                       Closure<T> closure)
                                throws java.io.IOException
        Helper method to create a new Reader for a stream and then passes it into the closure. The reader (and this stream) is closed after the closure returns.
        Parameters:
        in - a stream
        closure - the closure to invoke with the InputStream
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
        See Also:
        InputStreamReader
      • withReader

        public static <T> T withReader​(java.io.InputStream in,
                                       java.lang.String charset,
                                       Closure<T> closure)
                                throws java.io.IOException
        Helper method to create a new Reader for a stream and then passes it into the closure. The reader (and this stream) is closed after the closure returns.
        Parameters:
        in - a stream
        charset - the charset used to decode the stream
        closure - the closure to invoke with the reader
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.6
        See Also:
        InputStreamReader
      • withWriter

        public static <T> T withWriter​(java.io.OutputStream stream,
                                       Closure<T> closure)
                                throws java.io.IOException
        Creates a writer from this stream, passing it to the given closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        stream - the stream which is used and then closed
        closure - the closure that the writer is passed into
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
        See Also:
        withWriter(java.io.Writer, groovy.lang.Closure)
      • withWriter

        public static <T> T withWriter​(java.io.OutputStream stream,
                                       java.lang.String charset,
                                       Closure<T> closure)
                                throws java.io.IOException
        Creates a writer from this stream, passing it to the given closure. This method ensures the stream is closed after the closure returns.
        Parameters:
        stream - the stream which is used and then closed
        charset - the charset used
        closure - the closure that the writer is passed into
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
        See Also:
        withWriter(java.io.Writer, groovy.lang.Closure)
      • withStream

        public static <T> T withStream​(java.io.OutputStream os,
                                       Closure<T> closure)
                                throws java.io.IOException
        Passes this OutputStream to the closure, ensuring that the stream is closed after the closure returns, regardless of errors.
        Parameters:
        os - the stream which is used and then closed
        closure - the closure that the stream is passed into
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • newInputStream

        public static java.io.BufferedInputStream newInputStream​(java.io.File file)
                                                          throws java.io.FileNotFoundException
        Creates a buffered input stream for this file.
        Parameters:
        file - a File
        Returns:
        a BufferedInputStream of the file
        Throws:
        java.io.FileNotFoundException - if the file is not found.
        Since:
        1.0
      • newInputStream

        public static java.io.BufferedInputStream newInputStream​(java.net.URL url)
                                                          throws java.net.MalformedURLException,
                                                                 java.io.IOException
        Creates a buffered input stream for this URL.
        Parameters:
        url - a URL
        Returns:
        a BufferedInputStream for the URL
        Throws:
        java.net.MalformedURLException - is thrown if the URL is not well formed
        java.io.IOException - if an I/O error occurs while creating the input stream
        Since:
        1.5.2
      • newInputStream

        public static java.io.BufferedInputStream newInputStream​(java.net.URL url,
                                                                 java.util.Map parameters)
                                                          throws java.net.MalformedURLException,
                                                                 java.io.IOException
        Creates a buffered input stream for this URL.
        Parameters:
        url - a URL
        parameters - connection parameters
        Returns:
        a BufferedInputStream for the URL
        Throws:
        java.net.MalformedURLException - is thrown if the URL is not well formed
        java.io.IOException - if an I/O error occurs while creating the input stream
        Since:
        1.8.1
      • newReader

        public static java.io.BufferedReader newReader​(java.net.URL url)
                                                throws java.net.MalformedURLException,
                                                       java.io.IOException
        Creates a buffered reader for this URL.
        Parameters:
        url - a URL
        Returns:
        a BufferedReader for the URL
        Throws:
        java.net.MalformedURLException - is thrown if the URL is not well formed
        java.io.IOException - if an I/O error occurs while creating the input stream
        Since:
        1.5.5
      • newReader

        public static java.io.BufferedReader newReader​(java.net.URL url,
                                                       java.util.Map parameters)
                                                throws java.net.MalformedURLException,
                                                       java.io.IOException
        Creates a buffered reader for this URL.
        Parameters:
        url - a URL
        parameters - connection parameters
        Returns:
        a BufferedReader for the URL
        Throws:
        java.net.MalformedURLException - is thrown if the URL is not well formed
        java.io.IOException - if an I/O error occurs while creating the input stream
        Since:
        1.8.1
      • newReader

        public static java.io.BufferedReader newReader​(java.net.URL url,
                                                       java.lang.String charset)
                                                throws java.net.MalformedURLException,
                                                       java.io.IOException
        Creates a buffered reader for this URL using the given encoding.
        Parameters:
        url - a URL
        charset - opens the stream with a specified charset
        Returns:
        a BufferedReader for the URL
        Throws:
        java.net.MalformedURLException - is thrown if the URL is not well formed
        java.io.IOException - if an I/O error occurs while creating the input stream
        Since:
        1.5.5
      • newReader

        public static java.io.BufferedReader newReader​(java.net.URL url,
                                                       java.util.Map parameters,
                                                       java.lang.String charset)
                                                throws java.net.MalformedURLException,
                                                       java.io.IOException
        Creates a buffered reader for this URL using the given encoding.
        Parameters:
        url - a URL
        parameters - connection parameters
        charset - opens the stream with a specified charset
        Returns:
        a BufferedReader for the URL
        Throws:
        java.net.MalformedURLException - is thrown if the URL is not well formed
        java.io.IOException - if an I/O error occurs while creating the input stream
        Since:
        1.8.1
      • newDataInputStream

        public static java.io.DataInputStream newDataInputStream​(java.io.File file)
                                                          throws java.io.FileNotFoundException
        Create a data input stream for this file
        Parameters:
        file - a File
        Returns:
        a DataInputStream of the file
        Throws:
        java.io.FileNotFoundException - if the file is not found.
        Since:
        1.5.0
      • eachByte

        public static void eachByte​(java.io.File self,
                                    Closure closure)
                             throws java.io.IOException
        Traverse through each byte of this File
        Parameters:
        self - a File
        closure - a closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
        See Also:
        eachByte(java.io.InputStream, groovy.lang.Closure)
      • eachByte

        public static void eachByte​(java.io.File self,
                                    int bufferLen,
                                    Closure closure)
                             throws java.io.IOException
        Traverse through the bytes of this File, bufferLen bytes at a time.
        Parameters:
        self - a File
        bufferLen - the length of the buffer to use.
        closure - a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.4
        See Also:
        eachByte(java.io.InputStream, int, groovy.lang.Closure)
      • eachByte

        public static void eachByte​(java.lang.Byte[] self,
                                    Closure closure)
        Traverse through each byte of this Byte array. Alias for each.
        Parameters:
        self - a Byte array
        closure - a closure
        Since:
        1.5.5
        See Also:
        each(java.lang.Object, groovy.lang.Closure)
      • eachByte

        public static void eachByte​(byte[] self,
                                    Closure closure)
        Traverse through each byte of this byte array. Alias for each.
        Parameters:
        self - a byte array
        closure - a closure
        Since:
        1.5.5
        See Also:
        each(java.lang.Object, groovy.lang.Closure)
      • eachByte

        public static void eachByte​(java.io.InputStream is,
                                    Closure closure)
                             throws java.io.IOException
        Traverse through each byte of the specified stream. The stream is closed after the closure returns.
        Parameters:
        is - stream to iterate over, closed after the method call
        closure - closure to apply to each byte
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • eachByte

        public static void eachByte​(java.io.InputStream is,
                                    int bufferLen,
                                    Closure closure)
                             throws java.io.IOException
        Traverse through each the specified stream reading bytes into a buffer and calling the 2 parameter closure with this buffer and the number of bytes.
        Parameters:
        is - stream to iterate over, closed after the method call.
        bufferLen - the length of the buffer to use.
        closure - a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.8
      • eachByte

        public static void eachByte​(java.net.URL url,
                                    Closure closure)
                             throws java.io.IOException
        Reads the InputStream from this URL, passing each byte to the given closure. The URL stream will be closed before this method returns.
        Parameters:
        url - url to iterate over
        closure - closure to apply to each byte
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
        See Also:
        eachByte(java.io.InputStream, groovy.lang.Closure)
      • eachByte

        public static void eachByte​(java.net.URL url,
                                    int bufferLen,
                                    Closure closure)
                             throws java.io.IOException
        Reads the InputStream from this URL, passing a byte[] and a number of bytes to the given closure. The URL stream will be closed before this method returns.
        Parameters:
        url - url to iterate over
        bufferLen - the length of the buffer to use.
        closure - a 2 parameter closure which is passed the byte[] and a number of bytes successfully read.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.8
        See Also:
        eachByte(java.io.InputStream, int, groovy.lang.Closure)
      • transformChar

        public static void transformChar​(java.io.Reader self,
                                         java.io.Writer writer,
                                         Closure closure)
                                  throws java.io.IOException
        Transforms each character from this reader by passing it to the given closure. The Closure should return each transformed character, which will be passed to the Writer. The reader and writer will be both be closed before this method returns.
        Parameters:
        self - a Reader object
        writer - a Writer to receive the transformed characters
        closure - a closure that performs the required transformation
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • transformLine

        public static void transformLine​(java.io.Reader reader,
                                         java.io.Writer writer,
                                         Closure closure)
                                  throws java.io.IOException
        Transforms the lines from a reader with a Closure and write them to a writer. Both Reader and Writer are closed after the operation.
        Parameters:
        reader - Lines of text to be transformed. Reader is closed afterwards.
        writer - Where transformed lines are written. Writer is closed afterwards.
        closure - Single parameter closure that is called to transform each line of text from the reader, before writing it to the writer.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • filterLine

        public static void filterLine​(java.io.Reader reader,
                                      java.io.Writer writer,
                                      Closure closure)
                               throws java.io.IOException
        Filter the lines from a reader and write them on the writer, according to a closure which returns true if the line should be included. Both Reader and Writer are closed after the operation.
        Parameters:
        reader - a reader, closed after the call
        writer - a writer, closed after the call
        closure - the closure which returns booleans
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • filterLine

        public static Writable filterLine​(java.io.File self,
                                          Closure closure)
                                   throws java.io.IOException
        Filters the lines of a File and creates a Writable in return to stream the filtered lines.
        Parameters:
        self - a File
        closure - a closure which returns a boolean indicating to filter the line or not
        Returns:
        a Writable closure
        Throws:
        java.io.IOException - if self is not readable
        Since:
        1.0
        See Also:
        filterLine(java.io.Reader, groovy.lang.Closure)
      • filterLine

        public static Writable filterLine​(java.io.File self,
                                          java.lang.String charset,
                                          Closure closure)
                                   throws java.io.IOException
        Filters the lines of a File and creates a Writable in return to stream the filtered lines.
        Parameters:
        self - a File
        charset - opens the file with a specified charset
        closure - a closure which returns a boolean indicating to filter the line or not
        Returns:
        a Writable closure
        Throws:
        java.io.IOException - if an IOException occurs
        Since:
        1.6.8
        See Also:
        filterLine(java.io.Reader, groovy.lang.Closure)
      • filterLine

        public static void filterLine​(java.io.File self,
                                      java.io.Writer writer,
                                      Closure closure)
                               throws java.io.IOException
        Filter the lines from this File, and write them to the given writer based on the given closure predicate.
        Parameters:
        self - a File
        writer - a writer destination to write filtered lines to
        closure - a closure which takes each line as a parameter and returns true if the line should be written to this writer.
        Throws:
        java.io.IOException - if self is not readable
        Since:
        1.0
        See Also:
        filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
      • filterLine

        public static void filterLine​(java.io.File self,
                                      java.io.Writer writer,
                                      java.lang.String charset,
                                      Closure closure)
                               throws java.io.IOException
        Filter the lines from this File, and write them to the given writer based on the given closure predicate.
        Parameters:
        self - a File
        writer - a writer destination to write filtered lines to
        charset - opens the file with a specified charset
        closure - a closure which takes each line as a parameter and returns true if the line should be written to this writer.
        Throws:
        java.io.IOException - if an IO error occurs
        Since:
        1.6.8
        See Also:
        filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
      • filterLine

        public static Writable filterLine​(java.io.Reader reader,
                                          Closure closure)
        Filter the lines from this Reader, and return a Writable which can be used to stream the filtered lines to a destination. The closure should return true if the line should be passed to the writer.
        Parameters:
        reader - this reader
        closure - a closure used for filtering
        Returns:
        a Writable which will use the closure to filter each line from the reader when the Writable#writeTo(Writer) is called.
        Since:
        1.0
      • filterLine

        public static Writable filterLine​(java.io.InputStream self,
                                          Closure predicate)
        Filter lines from an input stream using a closure predicate. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
        Parameters:
        self - an input stream
        predicate - a closure which returns boolean and takes a line
        Returns:
        a writable which writes out the filtered lines
        Since:
        1.0
        See Also:
        filterLine(java.io.Reader, groovy.lang.Closure)
      • filterLine

        public static Writable filterLine​(java.io.InputStream self,
                                          java.lang.String charset,
                                          Closure predicate)
                                   throws java.io.UnsupportedEncodingException
        Filter lines from an input stream using a closure predicate. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
        Parameters:
        self - an input stream
        charset - opens the stream with a specified charset
        predicate - a closure which returns boolean and takes a line
        Returns:
        a writable which writes out the filtered lines
        Throws:
        java.io.UnsupportedEncodingException - if the encoding specified is not supported
        Since:
        1.6.8
        See Also:
        filterLine(java.io.Reader, groovy.lang.Closure)
      • filterLine

        public static void filterLine​(java.io.InputStream self,
                                      java.io.Writer writer,
                                      Closure predicate)
                               throws java.io.IOException
        Uses a closure to filter lines from this InputStream and pass them to the given writer. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
        Parameters:
        self - the InputStream
        writer - a writer to write output to
        predicate - a closure which returns true if a line should be accepted
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
        See Also:
        filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
      • filterLine

        public static void filterLine​(java.io.InputStream self,
                                      java.io.Writer writer,
                                      java.lang.String charset,
                                      Closure predicate)
                               throws java.io.IOException
        Uses a closure to filter lines from this InputStream and pass them to the given writer. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
        Parameters:
        self - the InputStream
        writer - a writer to write output to
        charset - opens the stream with a specified charset
        predicate - a closure which returns true if a line should be accepted
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
      • filterLine

        public static Writable filterLine​(java.net.URL self,
                                          Closure predicate)
                                   throws java.io.IOException
        Filter lines from a URL using a closure predicate. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
        Parameters:
        self - a URL
        predicate - a closure which returns boolean and takes a line
        Returns:
        a writable which writes out the filtered lines
        Throws:
        java.io.IOException - if an IO exception occurs
        Since:
        1.6.8
        See Also:
        filterLine(java.io.Reader, groovy.lang.Closure)
      • filterLine

        public static Writable filterLine​(java.net.URL self,
                                          java.lang.String charset,
                                          Closure predicate)
                                   throws java.io.IOException
        Filter lines from a URL using a closure predicate. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
        Parameters:
        self - the URL
        charset - opens the URL with a specified charset
        predicate - a closure which returns boolean and takes a line
        Returns:
        a writable which writes out the filtered lines
        Throws:
        java.io.IOException - if an IO exception occurs
        Since:
        1.6.8
        See Also:
        filterLine(java.io.Reader, groovy.lang.Closure)
      • filterLine

        public static void filterLine​(java.net.URL self,
                                      java.io.Writer writer,
                                      Closure predicate)
                               throws java.io.IOException
        Uses a closure to filter lines from this URL and pass them to the given writer. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
        Parameters:
        self - the URL
        writer - a writer to write output to
        predicate - a closure which returns true if a line should be accepted
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
      • filterLine

        public static void filterLine​(java.net.URL self,
                                      java.io.Writer writer,
                                      java.lang.String charset,
                                      Closure predicate)
                               throws java.io.IOException
        Uses a closure to filter lines from this URL and pass them to the given writer. The closure will be passed each line as a String, and it should return true if the line should be passed to the writer.
        Parameters:
        self - the URL
        writer - a writer to write output to
        charset - opens the URL with a specified charset
        predicate - a closure which returns true if a line should be accepted
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.6.8
        See Also:
        filterLine(java.io.Reader, java.io.Writer, groovy.lang.Closure)
      • readBytes

        public static byte[] readBytes​(java.io.File file)
                                throws java.io.IOException
        Reads the content of the file into a byte array.
        Parameters:
        file - a File
        Returns:
        a byte array with the contents of the file.
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • withStreams

        public static <T> T withStreams​(java.net.Socket socket,
                                        Closure<T> closure)
                                 throws java.io.IOException
        Passes the Socket's InputStream and OutputStream to the closure. The streams will be closed after the closure returns, even if an exception is thrown.
        Parameters:
        socket - a Socket
        closure - a Closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.2
      • withObjectStreams

        public static <T> T withObjectStreams​(java.net.Socket socket,
                                              Closure<T> closure)
                                       throws java.io.IOException
        Creates an InputObjectStream and an OutputObjectStream from a Socket, and passes them to the closure. The streams will be closed after the closure returns, even if an exception is thrown.
        Parameters:
        socket - this Socket
        closure - a Closure
        Returns:
        the value returned by the closure
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.5.0
      • leftShift

        public static java.io.Writer leftShift​(java.net.Socket self,
                                               java.lang.Object value)
                                        throws java.io.IOException
        Overloads the left shift operator to provide an append mechanism to add things to the output stream of a socket
        Parameters:
        self - a Socket
        value - a value to append
        Returns:
        a Writer
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • leftShift

        public static java.io.OutputStream leftShift​(java.net.Socket self,
                                                     byte[] value)
                                              throws java.io.IOException
        Overloads the left shift operator to provide an append mechanism to add bytes to the output stream of a socket
        Parameters:
        self - a Socket
        value - a value to append
        Returns:
        an OutputStream
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
      • accept

        public static java.net.Socket accept​(java.net.ServerSocket serverSocket,
                                             Closure closure)
                                      throws java.io.IOException
        Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread.
        Parameters:
        serverSocket - a ServerSocket
        closure - a Closure
        Returns:
        a Socket
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.0
        See Also:
        ServerSocket.accept()
      • accept

        public static java.net.Socket accept​(java.net.ServerSocket serverSocket,
                                             boolean runInANewThread,
                                             Closure closure)
                                      throws java.io.IOException
        Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread or the calling thread, as needed.
        Parameters:
        serverSocket - a ServerSocket
        runInANewThread - This flag should be true, if the closure should be invoked in a new thread, else false.
        closure - a Closure
        Returns:
        a Socket
        Throws:
        java.io.IOException - if an IOException occurs.
        Since:
        1.7.6
        See Also:
        ServerSocket.accept()
      • asWritable

        public static java.io.File asWritable​(java.io.File file)
        Converts this File to a Writable.
        Parameters:
        file - a File
        Returns:
        a File which wraps the input file and which implements Writable
        Since:
        1.0
      • asType

        public static <T> T asType​(java.io.File f,
                                   java.lang.Class<T> c)
        Converts this File to a Writable or delegates to default asType(java.lang.Object, java.lang.Class).
        Parameters:
        f - a File
        c - the desired class
        Returns:
        the converted object
        Since:
        1.0
      • asWritable

        public static java.io.File asWritable​(java.io.File file,
                                              java.lang.String encoding)
        Allows a file to return a Writable implementation that can output itself to a Writer stream.
        Parameters:
        file - a File
        encoding - the encoding to be used when reading the file's contents
        Returns:
        File which wraps the input file and which implements Writable
        Since:
        1.0
      • toList

        public static java.util.List<java.lang.String> toList​(java.lang.String self)
        Converts the given String into a List of strings of one character.
        Parameters:
        self - a String
        Returns:
        a List of characters (a 1-character String)
        Since:
        1.0
      • toList

        public static java.util.List<java.lang.CharSequence> toList​(java.lang.CharSequence self)
        Converts the given CharSequence into a List of CharSequence of one character.
        Parameters:
        self - a CharSequence
        Returns:
        a List of characters (a 1-character CharSequence)
        Since:
        1.8.2
        See Also:
        toSet(String)
      • toSet

        public static java.util.Set<java.lang.String> toSet​(java.lang.String self)
        Converts the given String into a Set of unique strings of one character.

        Example usage:

         assert 'groovy'.toSet() == ['v', 'g', 'r', 'o', 'y'] as Set
         assert "abc".toSet().iterator()[0] instanceof String
         
        Parameters:
        self - a String
        Returns:
        a Set of unique character Strings (each a 1-character String)
        Since:
        1.8.0
      • toSet

        public static java.util.Set<java.lang.CharSequence> toSet​(java.lang.CharSequence self)
        Converts the given CharSequence into a Set of unique CharSequence of one character.
        Parameters:
        self - a CharSequence
        Returns:
        a Set of unique character CharSequence (each a 1-character CharSequence)
        Since:
        1.8.2
        See Also:
        toSet(String)
      • getChars

        public static char[] getChars​(java.lang.String self)
        Converts the given String into an array of characters. Alias for toCharArray.
        Parameters:
        self - a String
        Returns:
        an array of characters
        Since:
        1.6.0
        See Also:
        String.toCharArray()
      • getChars

        public static char[] getChars​(java.lang.CharSequence self)
        Converts the given CharSequence into an array of characters.
        Parameters:
        self - a CharSequence
        Returns:
        an array of characters
        Since:
        1.8.2
        See Also:
        getChars(String)
      • asType

        public static <T> T asType​(GString self,
                                   java.lang.Class<T> c)
        Converts the GString to a File, or delegates to the default asType(java.lang.Object, java.lang.Class)
        Parameters:
        self - a GString
        c - the desired class
        Returns:
        the converted object
        Since:
        1.5.0
      • asType

        public static <T> T asType​(java.lang.String self,
                                   java.lang.Class<T> c)

        Provides a method to perform custom 'dynamic' type conversion to the given class using the as operator.

        Example: '123' as Double

        By default, the following types are supported:

        • List
        • BigDecimal
        • BigInteger
        • Long
        • Integer
        • Short
        • Byte
        • Character
        • Double
        • Float
        • File
        • Subclasses of Enum (Java 5 and above)
        If any other type is given, the call is delegated to asType(java.lang.Object, java.lang.Class).
        Parameters:
        self - a String
        c - the desired class
        Returns:
        the converted object
        Since:
        1.0
      • asType

        public static <T> T asType​(java.lang.CharSequence self,
                                   java.lang.Class<T> c)

        Provides a method to perform custom 'dynamic' type conversion to the given class using the as operator.

        Parameters:
        self - a CharSequence
        c - the desired class
        Returns:
        the converted object
        Since:
        1.8.2
        See Also:
        asType(String, Class)
      • eachMatch

        public static java.lang.String eachMatch​(java.lang.String self,
                                                 java.lang.String regex,
                                                 Closure closure)
        Process each regex group matched substring of the given string. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.
        Parameters:
        self - the source string
        regex - a Regex string
        closure - a closure with one parameter or as much parameters as groups
        Returns:
        the source string
        Since:
        1.6.0
      • eachMatch

        public static java.lang.String eachMatch​(java.lang.CharSequence self,
                                                 java.lang.CharSequence regex,
                                                 Closure closure)
        Process each regex group matched substring of the given CharSequence. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.
        Parameters:
        self - the source CharSequence
        regex - a Regex CharSequence
        closure - a closure with one parameter or as much parameters as groups
        Returns:
        the source CharSequence
        Since:
        1.8.2
        See Also:
        eachMatch(String, String, groovy.lang.Closure)
      • eachMatch

        public static java.lang.String eachMatch​(java.lang.String self,
                                                 java.util.regex.Pattern pattern,
                                                 Closure closure)
        Process each regex group matched substring of the given pattern. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.
        Parameters:
        self - the source string
        pattern - a regex Pattern
        closure - a closure with one parameter or as much parameters as groups
        Returns:
        the source string
        Since:
        1.6.1
      • eachMatch

        public static java.lang.String eachMatch​(java.lang.CharSequence self,
                                                 java.util.regex.Pattern pattern,
                                                 Closure closure)
        Process each regex group matched substring of the given pattern. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.
        Parameters:
        self - the source CharSequence
        pattern - a regex Pattern
        closure - a closure with one parameter or as much parameters as groups
        Returns:
        the source CharSequence
        Since:
        1.8.2
        See Also:
        eachMatch(String, Pattern, groovy.lang.Closure)
      • findIndexOf

        public static int findIndexOf​(java.lang.Object self,
                                      Closure closure)
        Iterates over the elements of an iterable collection of items and returns the index of the first item that matches the condition specified in the closure.
        Parameters:
        self - the iteration object over which to iterate
        closure - the filter to perform a match on the collection
        Returns:
        an integer that is the index of the first matched object or -1 if no match was found
        Since:
        1.0
      • findIndexOf

        public static int findIndexOf​(java.lang.Object self,
                                      int startIndex,
                                      Closure closure)
        Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index of the first item that matches the condition specified in the closure.
        Parameters:
        self - the iteration object over which to iterate
        startIndex - start matching from this index
        closure - the filter to perform a match on the collection
        Returns:
        an integer that is the index of the first matched object or -1 if no match was found
        Since:
        1.5.0
      • findLastIndexOf

        public static int findLastIndexOf​(java.lang.Object self,
                                          Closure closure)
        Iterates over the elements of an iterable collection of items and returns the index of the last item that matches the condition specified in the closure.
        Parameters:
        self - the iteration object over which to iterate
        closure - the filter to perform a match on the collection
        Returns:
        an integer that is the index of the last matched object or -1 if no match was found
        Since:
        1.5.2
      • findLastIndexOf

        public static int findLastIndexOf​(java.lang.Object self,
                                          int startIndex,
                                          Closure closure)
        Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index of the last item that matches the condition specified in the closure.
        Parameters:
        self - the iteration object over which to iterate
        startIndex - start matching from this index
        closure - the filter to perform a match on the collection
        Returns:
        an integer that is the index of the last matched object or -1 if no match was found
        Since:
        1.5.2
      • findIndexValues

        public static java.util.List<java.lang.Number> findIndexValues​(java.lang.Object self,
                                                                       Closure closure)
        Iterates over the elements of an iterable collection of items and returns the index values of the items that match the condition specified in the closure.
        Parameters:
        self - the iteration object over which to iterate
        closure - the filter to perform a match on the collection
        Returns:
        a list of numbers corresponding to the index values of all matched objects
        Since:
        1.5.2
      • findIndexValues

        public static java.util.List<java.lang.Number> findIndexValues​(java.lang.Object self,
                                                                       java.lang.Number startIndex,
                                                                       Closure closure)
        Iterates over the elements of an iterable collection of items, starting from a specified startIndex, and returns the index values of the items that match the condition specified in the closure.
        Parameters:
        self - the iteration object over which to iterate
        startIndex - start matching from this index
        closure - the filter to perform a match on the collection
        Returns:
        a list of numbers corresponding to the index values of all matched objects
        Since:
        1.5.2
      • getRootLoader

        public static java.lang.ClassLoader getRootLoader​(java.lang.ClassLoader self)
        Iterates through the classloader parents until it finds a loader with a class named "org.codehaus.groovy.tools.RootLoader". If there is no such class null will be returned. The name is used for comparison because a direct comparison using == may fail as the class may be loaded through different classloaders.
        Parameters:
        self - a ClassLoader
        Returns:
        the rootLoader for the ClassLoader
        Since:
        1.5.0
        See Also:
        RootLoader
      • asType

        public static <T> T asType​(java.lang.Object obj,
                                   java.lang.Class<T> type)
        Converts a given object to a type. This method is used through the "as" operator and is overloadable as any other operator.
        Parameters:
        obj - the object to convert
        type - the goal type
        Returns:
        the resulting object
        Since:
        1.0
      • newInstance

        public static <T> T newInstance​(java.lang.Class<T> c)
        Convenience method to dynamically create a new instance of this class. Calls the default constructor.
        Parameters:
        c - a class
        Returns:
        a new instance of this class
        Since:
        1.0
      • newInstance

        public static <T> T newInstance​(java.lang.Class<T> c,
                                        java.lang.Object[] args)
        Helper to construct a new instance from the given arguments. The constructor is called based on the number and types in the args array. Use newInstance(null) or simply newInstance() for the default (no-arg) constructor.
        Parameters:
        c - a class
        args - the constructor arguments
        Returns:
        a new instance of this class.
        Since:
        1.0
      • getMetaClass

        public static MetaClass getMetaClass​(java.lang.Class c)
        Adds a "metaClass" property to all class objects so you can use the syntax String.metaClass.myMethod = { println "foo" }
        Parameters:
        c - The java.lang.Class instance
        Returns:
        An MetaClass instance
        Since:
        1.5.0
      • getMetaClass

        public static MetaClass getMetaClass​(java.lang.Object obj)
        Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself.
        Parameters:
        obj - The object in question
        Returns:
        The MetaClass
        Since:
        1.5.0
      • getMetaClass

        public static MetaClass getMetaClass​(GroovyObject obj)
        Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself.
        Parameters:
        obj - The object in question
        Returns:
        The MetaClass
        Since:
        1.6.0
      • setMetaClass

        public static void setMetaClass​(java.lang.Class self,
                                        MetaClass metaClass)
        Sets the metaclass for a given class.
        Parameters:
        self - the class whose metaclass we wish to set
        metaClass - the new MetaClass
        Since:
        1.6.0
      • setMetaClass

        public static void setMetaClass​(java.lang.Object self,
                                        MetaClass metaClass)
        Set the metaclass for an object
        Parameters:
        self - the object whose metaclass we want to set
        metaClass - the new metaclass value
        Since:
        1.6.0
      • metaClass

        public static MetaClass metaClass​(java.lang.Class self,
                                          Closure closure)
        Sets/updates the metaclass for a given class to a closure.
        Parameters:
        self - the class whose metaclass we wish to update
        closure - the closure representing the new metaclass
        Returns:
        the new metaclass value
        Throws:
        GroovyRuntimeException - if the metaclass can't be set for this class
        Since:
        1.6.0
      • metaClass

        public static MetaClass metaClass​(java.lang.Object self,
                                          Closure closure)
        Sets/updates the metaclass for a given object to a closure.
        Parameters:
        self - the object whose metaclass we wish to update
        closure - the closure representing the new metaclass
        Returns:
        the new metaclass value
        Throws:
        GroovyRuntimeException - if the metaclass can't be set for this object
        Since:
        1.6.0
      • iterator

        public static <T> java.util.Iterator<T> iterator​(T[] a)
        Attempts to create an Iterator for the given object by first converting it to a Collection.
        Parameters:
        a - an array
        Returns:
        an Iterator for the given Array.
        Since:
        1.6.4
        See Also:
        DefaultTypeTransformation.asCollection(java.lang.Object[])
      • iterator

        public static java.util.Iterator iterator​(java.lang.Object o)
        Attempts to create an Iterator for the given object by first converting it to a Collection.
        Parameters:
        o - an object
        Returns:
        an Iterator for the given Object.
        Since:
        1.0
        See Also:
        DefaultTypeTransformation.asCollection(java.lang.Object)
      • iterator

        public static <T> java.util.Iterator<T> iterator​(java.util.Enumeration<T> enumeration)
        Allows an Enumeration to behave like an Iterator. Note that the remove() method is unsupported since the underlying Enumeration does not provide a mechanism for removing items.
        Parameters:
        enumeration - an Enumeration object
        Returns:
        an Iterator for the given Enumeration
        Since:
        1.0
      • iterator

        public static java.util.Iterator iterator​(java.util.regex.Matcher matcher)
        Returns an Iterator which traverses each match.
        Parameters:
        matcher - a Matcher object
        Returns:
        an Iterator for a Matcher
        Since:
        1.0
        See Also:
        Matcher.group()
      • iterator

        public static java.util.Iterator<java.lang.String> iterator​(java.io.Reader self)
        Creates an iterator which will traverse through the reader a line at a time.
        Parameters:
        self - a Reader object
        Returns:
        an Iterator for the Reader
        Since:
        1.5.0
        See Also:
        BufferedReader.readLine()
      • iterator

        public static java.util.Iterator<java.lang.Byte> iterator​(java.io.InputStream self)
        Standard iterator for a input stream which iterates through the stream content in a byte-based fashion.
        Parameters:
        self - an InputStream object
        Returns:
        an Iterator for the InputStream
        Since:
        1.5.0
      • iterator

        public static java.util.Iterator<java.lang.Byte> iterator​(java.io.DataInputStream self)
        Standard iterator for a data input stream which iterates through the stream content a Byte at a time.
        Parameters:
        self - a DataInputStream object
        Returns:
        an Iterator for the DataInputStream
        Since:
        1.5.0
      • iterator

        public static <T> java.util.Iterator<T> iterator​(java.util.Iterator<T> self)
        An identity function for iterators, supporting 'duck-typing' when trying to get an iterator for each object within a collection, some of which may already be iterators.
        Parameters:
        self - an iterator object
        Returns:
        itself
        Since:
        1.5.0
      • respondsTo

        public static java.util.List<MetaMethod> respondsTo​(java.lang.Object self,
                                                            java.lang.String name,
                                                            java.lang.Object[] argTypes)

        Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.

        Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing

        This method is "safe" in that it will always return a value and never throw an exception

        Parameters:
        self - The object to inspect
        name - The name of the method of interest
        argTypes - The argument types to match against
        Returns:
        A List of MetaMethods matching the argument types which will be empty if no matching methods exist
        Since:
        1.6.0
        See Also:
        MetaObjectProtocol.respondsTo(java.lang.Object, java.lang.String, java.lang.Object[])
      • respondsTo

        public static java.util.List<MetaMethod> respondsTo​(java.lang.Object self,
                                                            java.lang.String name)

        Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of the arguments.

        Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing

        This method is "safe" in that it will always return a value and never throw an exception

        Parameters:
        self - The object to inspect
        name - The name of the method of interest
        Returns:
        A List of MetaMethods matching the given name or an empty list if no matching methods exist
        Since:
        1.6.1
        See Also:
        MetaObjectProtocol.respondsTo(java.lang.Object, java.lang.String)
      • hasProperty

        public static MetaProperty hasProperty​(java.lang.Object self,
                                               java.lang.String name)

        Returns true of the implementing MetaClass has a property of the given name

        Note that this method will only return true for realised properties and does not take into account implementation of getProperty or propertyMissing

        Parameters:
        self - The object to inspect
        name - The name of the property of interest
        Returns:
        The found MetaProperty or null if it doesn't exist
        Since:
        1.6.1
        See Also:
        MetaObjectProtocol.hasProperty(java.lang.Object, java.lang.String)