-
Notifications
You must be signed in to change notification settings - Fork 3
/
useitLikeBuilderpattern.java
68 lines (53 loc) · 1.82 KB
/
useitLikeBuilderpattern.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package Example.generate;
import com.hosseini.persian.dt.PersianDT;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
/**
* Created by abbas on 3/30/16.
*/
public class useitLikeBuilderpattern {
static int day;
static int year;
static int month;
public static void main(String[] s) {
// in java 8
/*
* if you wanna use method refrence like System.out::println
* no need implment callback or create anonymous Callbacks Objects
* */
int random = new Random().nextInt(49);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, random);
//Lambda
PersianDT
.Instance()
.generate(new Date(), "{DATE}")
.CallBack(date -> System.out.println(date))
.Separator("_")
.generateFullDate();
random = new Random().nextInt(49);
cal = Calendar.getInstance();
cal.add(Calendar.DATE, random);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());
//method reference
PersianDT
.Instance()
.generate(format, "{DATE}")
.CallBack(System.out::println)
.Separator("--")
.generateWithMonthName();
random = new Random().nextInt(500);
cal = Calendar.getInstance();
cal.add(Calendar.DATE, random);
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());
////use for other JDK version
PersianDT
.Instance()
.generate(format, "{DATE}")
.CallBack(date -> System.out.println(date))
.Separator(" | ")
.generateWithMonthName();
}
}