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