[ZZ]Groovy Goodness: Date and Time Durations and the TimeCategory
摘要: Groovy has some elegant ways to work with date and time values. One of them is the support of durations. We can define a duration to denote a certain time amount, like 7 days, 2 hours and 50 minutes. We can use these durations to add or subtract them from date and time objects.
The TimeCategory provides an even Groovier way to work with durations. We can use constructs like 7.days + 12.minutes to create a duration. When we read this code it is just like reading English text. Here is som
閱讀全文
[ZZ]Groovy Goodness: Multiple Assignments
摘要: Since Groovy 1.6 we can define and assign values to several variables at once. This is especially useful when a method returns multiple values and we want to assign them to separate variables.
閱讀全文
[ZZ]Groovy Goodness: the With Method
摘要: Groovy has a with method we can use to group method calls and property access to an object. The with method accepts a closure and every method call or property access in the closure applies to the object if applicable. The method is part of Groovy's extensions to the java.lang.Object class. Let's see this with an example:
閱讀全文
gbk_to_utf8
摘要: 前些時(shí)候需要把項(xiàng)目中的文本文件都從GBK編碼轉(zhuǎn)換為UTF-8編碼. 如果要手動(dòng)的一個(gè)個(gè)的改, 那可費(fèi)事了. 反正想學(xué)學(xué)Groovy, 就用Groovy做的轉(zhuǎn)換腳本吧.
閱讀全文