锘??xml version="1.0" encoding="utf-8" standalone="yes"?>日韩亚洲一区在线播放,久久久另类综合,最新97超碰在线http://www.aygfsteel.com/mstar/category/29976.html鎼炶蔣浠跺紑鍙戝氨鍍忚寮哄ジ,濡傛灉涓嶈兘鍙嶆姉,灝變韓鍙楀畠鍚э紒zh-cnMon, 07 Sep 2009 09:39:37 GMTMon, 07 Sep 2009 09:39:37 GMT60[ZZ]Groovy Goodness: Date and Time Durations and the TimeCategoryhttp://www.aygfsteel.com/mstar/archive/2009/09/07/294145.html榛戠伒榛戠伒Mon, 07 Sep 2009 02:54:00 GMThttp://www.aygfsteel.com/mstar/archive/2009/09/07/294145.htmlhttp://www.aygfsteel.com/mstar/comments/294145.htmlhttp://www.aygfsteel.com/mstar/archive/2009/09/07/294145.html#Feedback0http://www.aygfsteel.com/mstar/comments/commentRss/294145.htmlhttp://www.aygfsteel.com/mstar/services/trackbacks/294145.htmlGroovy 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 some sample code:


import groovy.time.*
import org.codehaus.groovy.runtime.TimeCategory

// Define period of 2 years, 3 months, 15 days, 0 hours, 23 minutes, 2 seconds and 0 milliseconds.
def period = new DatumDependentDuration(231502320)
assert '2 years, 3 months, 15 days, 23 minutes, 2.000 seconds' == period.toString()
def year2000 
= new Date(10000)  // Jan 1, 2000
assert 'Mon Apr 15 00:23:02 UTC 2002' == (period + year2000).toString()

// Define time period of 5 hours, 54 minutes and 30 milliseconds.
def time = new TimeDuration(554030)
assert '5 hours, 54 minutes, 0.030 seconds' == time.toString()

use (TimeCategory) {
    
assert period.toString() == (2.years + 3.months + 15.days + 0.hour + 23.minutes + 2.seconds).toString()
    
assert time.toString() == (5.hours + 54.minutes + 30.milliseconds).toString()

    
// We can use period.from.now syntax.    
    def d1 = 1.week - 1.day
    def d2 
= new Date() + 6.days
    
assert d2.format('yyyy-MM-dd'== d1.from.now.toString()
    
    
// We can use period.ago syntax.
    def d3 = 3.days.ago
    def d4 
= new Date() - 3
    
assert d4.format('yyyy-MM-dd'== d3.toString()
}


榛戠伒 2009-09-07 10:54 鍙戣〃璇勮
]]>
[ZZ]Groovy Goodness: Multiple Assignmentshttp://www.aygfsteel.com/mstar/archive/2009/09/07/294144.html榛戠伒榛戠伒Mon, 07 Sep 2009 02:52:00 GMThttp://www.aygfsteel.com/mstar/archive/2009/09/07/294144.htmlhttp://www.aygfsteel.com/mstar/comments/294144.htmlhttp://www.aygfsteel.com/mstar/archive/2009/09/07/294144.html#Feedback0http://www.aygfsteel.com/mstar/comments/commentRss/294144.htmlhttp://www.aygfsteel.com/mstar/services/trackbacks/294144.html
// Assign and declare variables.
def (username, email) = ['mrhaki''email@host.com']
assert 'mrhaki' == username
assert 'email@host.com' == email

// We can assign later than the definition of the variables.
int housenr
String streetname
(streetname, housenr) 
= ['Old Street'42]
assert 42 == housenr
assert 'Old Street' == streetname

// Return value of method can be assigned to multiple variables.
def iAmHere() {
    [
29.2009012.90391]
}
def (coordX, coordY) 
= iAmHere()
assert coordX == 29.20090
assert coordY == 12.90391

// More values than variables: extra values are ignored.
def (a, b, c) = ['a''b''c''d']
assert 'a' == a
assert 'b' == b
assert 'c' == c

// Less values than variables: variable is not set.
def (x, y, z) = [100200]
assert 100 == x
assert 200 == y
assert !z



榛戠伒 2009-09-07 10:52 鍙戣〃璇勮
]]>
[ZZ]Groovy Goodness: the With Methodhttp://www.aygfsteel.com/mstar/archive/2009/09/07/294143.html榛戠伒榛戠伒Mon, 07 Sep 2009 02:51:00 GMThttp://www.aygfsteel.com/mstar/archive/2009/09/07/294143.htmlhttp://www.aygfsteel.com/mstar/comments/294143.htmlhttp://www.aygfsteel.com/mstar/archive/2009/09/07/294143.html#Feedback0http://www.aygfsteel.com/mstar/comments/commentRss/294143.htmlhttp://www.aygfsteel.com/mstar/services/trackbacks/294143.html to the java.lang.Object class. Let's see this with an example:

class Sample {
    String username
    String email
    List
<String> labels = []
    def speakUp() { 
"I am $username" }
    def addLabel(value) { labels 
<< value }
}

def sample 
= new Sample()
sample.with {
    username 
= 'mrhaki'
    email 
= 'email@host.com'
    println speakUp()  
// Output: I am mrhaki
    addLabel 'Groovy' 
    addLabel 
'Java'    
}
assert 2 == sample.labels.size()
assert 'Groovy' == sample.labels[0]
assert 'Java' == sample.labels[1]
assert 'mrhaki' == sample.username
assert 'email@host.com' == sample.email

def sb 
= new StringBuilder()
sb.with {
    append 
'Just another way to add '
    append 
'strings to the StringBuilder '
    append 
'object.'    
}

assert 'Just another way to add strings to the StringBuilder object.' == sb.toString()

// Another example as seen at 
// http://javajeff.blogspot.com/2008/11/getting-groovy-with-with.html
def cal = Calendar.instance
cal.with {
    clear()
    set(YEAR, 
2009)
    set MONTH, SEPTEMBER
    set DATE, 
4    
    add DATE, 
2
}
assert'September 6, 2009' == cal.time.format('MMMM d, yyyy')



榛戠伒 2009-09-07 10:51 鍙戣〃璇勮
]]>
gbk_to_utf8http://www.aygfsteel.com/mstar/archive/2008/03/11/gbk_to_utf8_use_groovy.html榛戠伒榛戠伒Tue, 11 Mar 2008 01:44:00 GMThttp://www.aygfsteel.com/mstar/archive/2008/03/11/gbk_to_utf8_use_groovy.htmlhttp://www.aygfsteel.com/mstar/comments/185259.htmlhttp://www.aygfsteel.com/mstar/archive/2008/03/11/gbk_to_utf8_use_groovy.html#Feedback2http://www.aygfsteel.com/mstar/comments/commentRss/185259.htmlhttp://www.aygfsteel.com/mstar/services/trackbacks/185259.html闃呰鍏ㄦ枃

榛戠伒 2008-03-11 09:44 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 满洲里市| 马关县| 九江市| 宜章县| 津市市| 永修县| 涞水县| 西乡县| 铁力市| 西昌市| 天镇县| 东阳市| 阳江市| 吴堡县| 禄劝| 吴桥县| 太谷县| 桐柏县| 来凤县| 湘潭市| 谷城县| 句容市| 梅河口市| 寿阳县| 新巴尔虎左旗| 南木林县| 贞丰县| 文登市| 吐鲁番市| 思茅市| 舟山市| 正蓝旗| 云浮市| 社会| 西平县| 泽库县| 白城市| 枝江市| 汉阴县| 湟中县| 额济纳旗|