Groovy grep

Groovy grep DEFAULT

Methods Detail

  • public boolean addAll(Iterable items)

    Adds all items from the iterable to the Collection.

    Parameters:
    - the items to add
    Returns:
    true if the collection changed
  • public boolean addAll(Object[] 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 or the '+' operator if wanting to produce a new collection containing additional items but while leaving the original collection unchanged.

    Parameters:
    - array containing elements to be added to this collection
    Returns:
    if this collection changed as a result of the call
    Since:
    1.7.2
    See Also:
    Collection#addAll(Collection)
  • public boolean addAll(Iterator items)

    Adds all items from the iterator to the Collection.

    Parameters:
    - the items to add
    Returns:
    true if the collection changed
  • public boolean asBoolean()

    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() == trueassert [].asBoolean() == false
    Returns:
    the boolean value
    Since:
    1.7.0
  • public ObjectasType(Class 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 Object#asType(Class). If this collection is already of the given type, the same instance is returned.

    Parameters:
    - the desired class
    Returns:
    the object resulting from this type conversion
    Since:
    1.0
    See Also:
    Object#asType(java.lang.Class)
  • public ListcollectNested(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:
    - the closure used to transform each item of the collection
    Returns:
    the resultant collection
    Since:
    1.8.1
  • public Collectioneach(Closure closure)

    Iterates through a Collection, passing each item to the given closure.

    Parameters:
    - the closure applied on each element found
    Returns:
    the self Collection
    Since:
    2.4.0
  • public CollectioneachWithIndex(Closure closure)

    Iterates through a Collection, passing each item and the item's index (a counter starting at zero) to the given closure.

    Parameters:
    - a Closure to operate on each item
    Returns:
    the self Collection
    Since:
    2.4.0
  • public Objectfind()

    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
    Returns:
    the first Object found or null if none was found
    Since:
    1.8.1
    See Also:
    Closure#IDENTITY
  • public Objectfind(Closure closure)

    Finds the first value matching the closure condition. Example:

    def list = [1,2,3] assert 2 == list.find { it 1 }
    Parameters:
    - a closure condition
    Returns:
    the first Object found, in the order of the collections iterator, or null if no element matches
    Since:
    1.0
  • public CollectionfindAll()

    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]]
    Returns:
    a Collection of the values found
    Since:
    1.8.1
    See Also:
    Closure#IDENTITY
  • public CollectionfindAll(Closure closure)

    Finds all values matching the closure condition.

    assert [2,4] == [1,2,3,4].findAll { it % 2 == 0 }
    Parameters:
    - a closure condition
    Returns:
    a Collection of matching values
    Since:
    1.5.6
  • public Collectionflatten()

    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()
    Returns:
    a flattened Collection
    Since:
    1.6.0
  • public ListgetAt(String property)

    Support the subscript operator for Collection.

    assert [String, Long, Integer] == ["a",5L,2]["class"]
    Parameters:
    - a String
    Returns:
    a List
    Since:
    1.0
  • public IntRangegetIndices()

    Returns indices of the collection.

    Example:

    assert 0..2 == [5, 6, 7].indices
    Returns:
    an index range
    Since:
    2.4.0
  • public Collectiongrep()

    Iterates over the collection returning each element 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]]
    Returns:
    a collection of elements satisfy Groovy truth
    Since:
    2.0
    See Also:
    Closure#IDENTITY
  • public Collectiongrep(Object filter)

    Iterates over the collection of items and returns each item that matches the given filter - calling the method used by switch statements. 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:
    - the filter to perform on each element of the collection (using the Object#isCase(java.lang.Object) method)
    Returns:
    a collection of objects which match the filter
    Since:
    2.0
  • public Objectinject(Closure 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:
    - a closure
    Returns:
    the result of the last closure call
    Since:
    1.8.7
    See Also:
    Collection#inject(Object, Closure)
  • public Objectinject(Object initialValue, Closure 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 or 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:
    - some initial value
    - a closure
    Returns:
    the result of the last closure call
    Since:
    1.0
  • public Collectionintersect(Collection right)

    Create a Collection composed of the intersection of both collections. Any elements that exist in both collections are added to the resultant collection. For collections of custom objects; the objects should implement java.lang.Comparable

    assert [4,5] == [1,2,3,4,5].intersect([4,5,6,7,8]) By default, Groovy uses a NumberAwareComparator when determining if an element exists in both collections.
    Parameters:
    - a Collection
    Returns:
    a Collection as an intersection of both collections
    Since:
    1.5.6
    See Also:
    Collection#intersect(Collection, Comparator)
  • public Collectionintersect(Collection right, Comparator comparator)

    Create a Collection composed of the intersection of both collections. Any elements that exist in both collections are added to the resultant collection. For collections of custom objects; the objects should implement java.lang.Comparable

    assert [3,4] == [1,2,3,4].intersect([3,4,5,6], Comparator.naturalOrder()) def one = ['a', 'B', 'c', 'd'] def two = ['b', 'C', 'd', 'e'] def compareIgnoreCase = { a, b a.toLowerCase() b.toLowerCase() } assert one.intersect(two) == ['d'] assert two.intersect(one) == ['d'] assert one.intersect(two, compareIgnoreCase) == ['b', 'C', 'd'] assert two.intersect(one, compareIgnoreCase) == ['B', 'c', 'd']
    Parameters:
    - a Collection
    - a Comparator
    Returns:
    a Collection as an intersection of both collections
    Since:
    2.5.0
  • public boolean isCase(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:
    - the switch value
    Returns:
    true if the caseValue is deemed to contain the switchValue
    Since:
    1.0
    See Also:
    Collection#contains(java.lang.Object)
  • public CollectionleftShift(Object 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:
    - an Object to be added to the collection.
    Returns:
    same collection, after the value was added to it.
    Since:
    1.0
  • public Collectionminus(Collection removeMe)

    Create a new Collection composed of the elements of the first Collection minus every occurrence of elements of the given Collection.

    assert [1, "a", true, true, false, 5.3] - [true, 5.3] == [1, "a", false]
    Parameters:
    - a Collection of elements to remove
    Returns:
    a Collection with the given elements removed
    Since:
    2.4.0
  • public Collectionplus(Iterable 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:
    - the right Iterable
    Returns:
    the merged Collection
    Since:
    1.8.7
    See Also:
    Collection#plus(Collection)
  • public Collectionplus(Object 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:
    - an object to add/append
    Returns:
    the resulting Collection
    Since:
    1.5.0
  • public Collectionplus(Collection 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:
    - the right Collection
    Returns:
    the merged Collection
    Since:
    1.5.0
  • public boolean removeAll(Closure condition)

    Modifies this collection by removing the elements that are matched according to the specified closure condition.

    def list = ['a', 'b'] list.removeAll { it == 'b' } assert list == ['a'] See also and when wanting to produce a new list containing items which match some criteria but leaving the original collection unchanged.
    Parameters:
    - a closure condition
    Returns:
    if this collection changed as a result of the call
    Since:
    1.7.2
    See Also:
    Iterator#remove()
  • public boolean removeAll(Object[] items)

    Modifies this collection by removing its elements that are contained within the specified object array. See also and when wanting to produce a new list containing items which don't match some criteria while leaving the original collection unchanged.

    Parameters:
    - array containing elements to be removed from this collection
    Returns:
    if this collection changed as a result of the call
    Since:
    1.7.2
    See Also:
    Collection#removeAll(Collection)
  • public boolean removeElement(Object o)

    Modifies this collection by removing a single instance of the specified element from this collection, if it is present. Essentially an alias for Collection#remove(Object) but with no ambiguity for Collection<Integer>.

    Example: def list = [1, 2, 3, 2] list.removeElement(2) assert [1, 3, 2] == list
    Parameters:
    - element to be removed from this collection, if present
    Returns:
    true if an element was removed as a result of this call
    Since:
    2.4.0
  • public boolean retainAll(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.

    def list = ['a', 'b'] list.retainAll { it == 'b' } assert list == ['b'] See also and when wanting to produce a new list containing items which match some criteria but leaving the original collection unchanged.
    Parameters:
    - a closure condition
    Returns:
    if this collection changed as a result of the call
    Since:
    1.7.2
    See Also:
    Iterator#remove()
  • public boolean retainAll(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 and when wanting to produce a new list containing items which match some specified items but leaving the original collection unchanged.

    Parameters:
    - array containing elements to be retained from this collection
    Returns:
    if this collection changed as a result of the call
    Since:
    1.7.2
    See Also:
    Collection#retainAll(Collection)
  • public Collectionsplit(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:
    - 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
  • public StringtoListString()

    Returns the string representation of the given list. The string displays the contents of the list, similar to a list literal, i.e. .

    Returns:
    the string representation
    Since:
    1.0
  • public StringtoListString(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. .

    Parameters:
    - stop after approximately this many characters and append '...'
    Returns:
    the string representation
    Since:
    1.7.3
  • public SettoSet()

    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
    Returns:
    a Set
    Since:
    1.8.0
  • public Collectionunique()

    Modifies this collection to remove all duplicated items, using Groovy's default number-aware comparator.

    assert [1,3] == [1,3,3].unique()
    Returns:
    the now modified collection
    Since:
    1.0
    See Also:
    Collection#unique(boolean)
  • public Collectionunique(boolean mutate)

    Remove all duplicates from a given Collection using Groovy's default number-aware 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:
    - 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
  • public Collectionunique(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, each element from the Collection will be passed to the closure. 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:
    - false will always cause a new list to be created, true will mutate lists in place
    - a 1 or 2 arg Closure used to determine unique items
    Returns:
    self without any duplicates
    Since:
    1.8.1
  • public Collectionunique(boolean mutate, Comparator 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:
    - false will always cause a new collection to be created, true will mutate collections in place
    - a Comparator
    Returns:
    self the collection without duplicates
    Since:
    1.8.1
  • public Collectionunique(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:
    - a 1 or 2 arg Closure used to determine unique items
    Returns:
    self without any duplicates
    Since:
    1.0
    See Also:
    Collection#unique(boolean, Closure)
  • public Collectionunique(Comparator 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:
    - a Comparator
    Returns:
    self the now modified collection without duplicates
    Since:
    1.0
    See Also:
    Collection#unique(boolean, java.util.Comparator)
Sours: https://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/Collection.html

Best Java code snippets using org.codehaus.groovy.runtime.DefaultGroovyMethods.grep(Showing top 8 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions

    private void myMethod () {

    OutputStreamWritero=
    • Codota IconOutputStream out;new OutputStreamWriter(out)
    • Codota IconOutputStream out;String charsetName;new OutputStreamWriter(out, charsetName)
    • Codota IconHttpURLConnection connection;new OutputStreamWriter(connection.getOutputStream())
    • Smart code suggestions by Tabnine

    }

    publicstatic Collection grep(Object self) { returngrep(self, Closure.IDENTITY); }
    publicstatic <T> Set<T> grep(Set<T> self) { returngrep(self, Closure.IDENTITY); }
    publicstatic <T> List<T> grep(List<T> self, Object filter) { return (List<T>) grep((Collection<T>) self, filter); }
    publicstatic <T> Collection<T> grep(Collection<T> self) { returngrep(self, Closure.IDENTITY); }
    publicstatic <T> List<T> grep(List<T> self) { returngrep(self, Closure.IDENTITY); }
    @SuppressWarnings("unchecked") publicstatic <T> Collection<T> grep(T[] self) { returngrep(self, Closure.IDENTITY); }
    publicstatic <T> Set<T> grep(Set<T> self, Object filter) { return (Set<T>) grep((Collection<T>) self, filter); }
    publicstatic Collection grep(Object self) { returngrep(self, Closure.IDENTITY); }
    Sours: https://www.tabnine.com/code/java/methods/org.codehaus.groovy.runtime.DefaultGroovyMethods/grep
    1. Airbnb chattanooga
    2. Kenmore dryer knob
    3. Pcc human resources
    4. Avian x decoys
    Return typeName and parameters
    Allows the usage of addShutdownHook without getting the runtime first.
    Iterates over the elements of a collection, and checks whether at least one element is true according to the Groovy Truth.
    Iterates over the contents of an object or collection, and checks whether a predicate is valid for at least one element.
    Coerce an object instance to a boolean value.
    Converts the given array to either a List, Set, or SortedSet.
    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.
    Iterates through this aggregate Object transforming each item into a new value using the closure, returning a list of transformed values.
    Iterates through this aggregate Object transforming each item into a new value using the closure and adding it to the supplied .
    Checks whether the array contains the given value.
    Counts the number of occurrences of the given value inside this array.
    Generates a detailed dump string of an object showing its class, hashCode and fields.
    Iterates through an aggregate type or data structure, passing each item to the given 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.
    Determines if the contents of this array are equal to the contents of the given list, in the same order.
    Iterates over every element of a collection, and checks whether all elements are according to the Groovy Truth.
    Used to determine if the given predicate closure is valid (i.e.
    Finds the first item matching the IDENTITY Closure (i.e. matching Groovy truth).
    Finds the first value matching the closure condition
    Finds all items matching the IDENTITY Closure (i.e. matching Groovy truth).
    Finds all items matching the closure condition.
    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.
    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.
    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.
    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.
    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.
    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.
    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.
    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.
    Flatten an array.
    Allows the subscript operator to be used to lookup dynamic property values.
    Obtains a MetaClass for an object either from the registry or in the case of a GroovyObject from the object itself.
    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'.
    Convenience method that calls Object#getMetaPropertyValues()(self) and provides the data in form of simple key/value pairs, i.e.
    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.
    Iterates over the collection of items which this Object represents and returns each item that matches the given filter - calling the method used by switch statements.
    Sorts all array members into (sub)groups determined by the supplied mapping closures as per the Iterable variant of this method.
    Sorts all array members into (sub)groups determined by the supplied mapping closures as per the list variant of this method.

    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


    Allows the closure to be called for the object reference self.
    Iterates through the given Object, passing in the first value to the closure along with the first item.
    Iterates through the given Object, passing in the initial value to the closure along with the first item.
    Inspects returns the String that matches what would be typed into a terminal to create this object.
    Provide a dynamic method invocation method which can be overloaded in classes to implement dynamic proxies easily.
    Identity check.
    Method for overloading the behavior of the 'case' method in switch statements.
    Attempts to create an Iterator for the given object by first converting it to a Collection.
    Concatenates the representation of each items in this array, with the given String as a separator between each item.
    Sets/updates the metaclass for a given object to a closure.
    Print to a console in interactive format.
    Print a value formatted Groovy style to self if it is a Writer, otherwise to the standard output stream.
    Prints a formatted string using the specified format string and arguments.
    Printf to a console.
    Print a linebreak to the standard output stream.
    Print to a console in interactive format.
    Print a value formatted Groovy style (followed by a newline) to self if it is a Writer, otherwise to the standard output stream.
    Allows the subscript operator to be used to set dynamically named property values.

    Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of the arguments.


    Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.


    Set the metaclass for an object.
    Provide the standard Groovy method for an array.
    Sleep for so many milliseconds, even if interrupted.
    Sleep for so many milliseconds, using a given closure for interrupt processing.
    Splits all items into two lists based on the closure condition.
    Returns a formatted string using the specified format string and arguments.
    Sprintf to a string.
    Sums the items in an array.
    Sums the result of apply a closure to each item of an array.
    Sums the items in an array, adding the result to some initial value.
    Sums the result of applying a closure to each item of an array to some initial value.
    Returns the string representation of the given array.
    Creates a spreadable map from this array.
    Returns the string representation of this array's contents.
    Scoped use method
    Allows you to use a list of categories, specifying the list as varargs.
    Scoped use method with list of categories.
    Allows the closure to be called for the object reference self.
    Dynamically wraps an instance into something which implements the supplied trait classes.
    Sours: http://docs.groovy-lang.org/docs/groovy-2.4.4/html/groovy-jdk/java/lang/Object.html
    Groovy The Martian \u0026 Phoebe - Are You Hungry? Groovy teaches to eat vegetables to kids

    grep command usage in groovy

    << edited in response to comment >>

    1. Pure Groovy Solution

    If you just want to implement the functionality in your bash script in groovy, you can do something like this:

    should be noted that if your log file is large, there are better ways of searching for a string that do not require you to load the entire file into memory.

    2. Process Management Solution

    If you were specifically looking to use the linux system command from within groovy, the above will naturally not help you. The following groovy code:

    will execute the command and should get you closer to what you want.

    It should be noted that the output redirection in your shell command is as far as I know hard to do on an external process from java/groovy and we are therefore writing the output to the file from within groovy instead of executing the command using output redirection.

    I also added a five second max timeout on the process execution. This is not required and that line can safely be removed, it's just there as a safeguard for cases where the grep blocks indefinitely.

    Sours: https://stackoverflow.com/questions/56015397/grep-command-usage-in-groovy

    Grep groovy

    .

    Groovy Fundamentals

    .

    Similar news:

    .



    757 758 759 760 761