forked from coding-new-talking/java-code-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethods.java
More file actions
64 lines (50 loc) · 1.42 KB
/
Copy pathMethods.java
File metadata and controls
64 lines (50 loc) · 1.42 KB
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
package org.cnt.java.utils;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import java.util.concurrent.TimeUnit;
/**
* @author lixinjie
* @since 2019-05-25
*/
public class Methods {
public static DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss");
public static int random(int max) {
return random(0, max);
}
public static int random(int min, int max) {
return min + new Random().nextInt(max - min + 1);
}
public static void doingLongTime() {
int second = random(5, 10);
sleep(second);
}
public static void doingLongTime(int second) {
sleep(second);
}
public static void sleep(int second) {
try {
TimeUnit.SECONDS.sleep(second);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void sleep2(int second) throws InterruptedException {
TimeUnit.SECONDS.sleep(second);
}
public static void println3(Object obj) {
System.out.println(time() + ", " + obj);
}
public static void println2(String text, Object... args) {
System.out.println(String.format(text, args));
}
public static void println(String text, Object... args) {
System.out.println(String.format(time() + ", " + text, args));
}
public static void println(Object obj) {
System.out.println(obj);
}
public static String time() {
return LocalTime.now().format(dtf);
}
}