1 package org.apache.maven.surefire.booter;
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 final class ProcessInfo
34 {
35 static final ProcessInfo INVALID_PROCESS_INFO = new ProcessInfo( null, null );
36 static final ProcessInfo ERR_PROCESS_INFO = new ProcessInfo( null, null );
37
38
39
40
41
42
43 static ProcessInfo unixProcessInfo( long pid, long etime )
44 {
45 return new ProcessInfo( pid, etime );
46 }
47
48 static ProcessInfo windowsProcessInfo( long pid, long startTimestamp )
49 {
50 return new ProcessInfo( pid, startTimestamp );
51 }
52
53 private final Long pid;
54 private final Comparable time;
55
56 private ProcessInfo( Long pid, Comparable time )
57 {
58 this.pid = pid;
59 this.time = time;
60 }
61
62 boolean canUse()
63 {
64 return !isInvalid() && !isError();
65 }
66
67 boolean isInvalid()
68 {
69 return this == INVALID_PROCESS_INFO;
70 }
71
72 boolean isError()
73 {
74 return this == ERR_PROCESS_INFO;
75 }
76
77 long getPID()
78 {
79 checkValid();
80 return pid;
81 }
82
83 Comparable getTime()
84 {
85 checkValid();
86 return time;
87 }
88
89 @SuppressWarnings( "unchecked" )
90 boolean isTimeEqualTo( ProcessInfo that )
91 {
92 checkValid();
93 that.checkValid();
94 return this.time.compareTo( that.time ) == 0;
95 }
96
97 @SuppressWarnings( "unchecked" )
98 boolean isTimeBefore( ProcessInfo that )
99 {
100 checkValid();
101 that.checkValid();
102 return this.time.compareTo( that.time ) < 0;
103 }
104
105 private void checkValid()
106 {
107 if ( !canUse() )
108 {
109 throw new IllegalStateException( "invalid process info" );
110 }
111 }
112 }