1
2
3
4
5 package oshi.util;
6
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 import com.sun.jna.Memory;
11 import com.sun.jna.Pointer;
12
13 import oshi.annotation.concurrent.ThreadSafe;
14
15
16
17
18 @ThreadSafe
19 public final class Util {
20 private static final Logger LOG = LoggerFactory.getLogger(Util.class);
21
22 private Util() {
23 }
24
25
26
27
28
29
30 public static void sleep(long ms) {
31 try {
32 LOG.trace("Sleeping for {} ms", ms);
33 Thread.sleep(ms);
34 } catch (InterruptedException e) {
35 LOG.warn("Interrupted while sleeping for {} ms: {}", ms, e.getMessage());
36 Thread.currentThread().interrupt();
37 }
38 }
39
40
41
42
43
44
45
46
47
48
49 public static boolean wildcardMatch(String text, String pattern) {
50 if (pattern.length() > 0 && pattern.charAt(0) == '^') {
51 return !wildcardMatch(text, pattern.substring(1));
52 }
53 return text.matches(pattern.replace("?", ".?").replace("*", ".*?"));
54 }
55
56
57
58
59
60
61
62 public static boolean isBlank(String s) {
63 return s == null || s.isEmpty();
64 }
65
66
67
68
69
70
71
72 public static boolean isBlankOrUnknown(String s) {
73 return isBlank(s) || Constants.UNKNOWN.equals(s);
74 }
75
76
77
78
79
80
81 public static void freeMemory(Pointer p) {
82 if (p instanceof Memory) {
83 ((Memory) p).close();
84 }
85 }
86
87
88
89
90
91
92
93
94
95
96 public static boolean isSessionValid(String user, String device, Long loginTime) {
97 return !(user.isEmpty() || device.isEmpty() || loginTime < 0 || loginTime > System.currentTimeMillis());
98 }
99 }