锘??xml version="1.0" encoding="utf-8" standalone="yes"?>最近中文字幕mv免费高清在线,亚洲精华一区二区三区,黄页网址大全在线播放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 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 同心县| 宜章县| 连云港市| 大庆市| 都安| 龙陵县| 翁牛特旗| 漾濞| 大连市| 宽城| 商河县| 双柏县| 谢通门县| 磐安县| 古田县| 和平区| 彰武县| 福州市| 东乌珠穆沁旗| 老河口市| 津市市| 龙岩市| 丰台区| 海晏县| 白河县| 偃师市| 七台河市| 湘西| 武穴市| 黑河市| 大方县| 丰城市| 澳门| 河津市| 北京市| 苍南县| 桓仁| 郓城县| 奎屯市| 桦南县| 夏津县|