How can I compare two lists in Groovy

I’d just use the arithmetic operators, I think it’s much more obvious what’s going on: def a = [“foo”, “bar”, “baz”, “baz”] def b = [“foo”, “qux”] assert [“bar”, “baz”, “baz”, “qux”] == ((a – b) + (b – a))

How do I print a Groovy stack trace?

Solution: org.codehaus.groovy.runtime.StackTraceUtils.sanitize(new Exception()).printStackTrace() Original answer: A Google search returns the following information: Apparently, there is a method in org.codehaus.groovy.runtime.StackTraceUtils called printSanitizedStackTrace. There isn’t much documentation for the method, though there is a method called sanitize which is described as remove all apparently groovy-internal trace entries from the exception instance This modifies the original instance and … Read more

Groovy ‘assert’: How to display the value?

An assertion is similar to an if, it verifies the expression you provide: if the expression is true it continues the execution to the next statement (and prints nothing), if the expression is false, it raises an AssertionError. You can customize the error message providing a message separated by a colon like this: assert 4 … Read more

Groovy property iteration

I haven’t yet found a good approach for excluding the read-only properties (i.e., metaClass, class), but if you want to set the value of all properties in the Foo instance that are also in the Foo2 instance you could do the following. class Foo { def feck = “fe” def arse = “ar” def drink … Read more

EachWithIndex groovy statement

These are plain methods but they follow quite a specific pattern – they take a Closure as their last argument. A Closure is a piece of functionality that you can pass around and call when applicable. For example, method eachWithIndex might look like this (roughly): void eachWithIndex(Closure operation) { for (int i = 0; this.hasNext(); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)