View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.wait;
17  
18  import static org.kuali.common.util.base.Precondition.checkMin;
19  
20  public final class WaitResult {
21  
22  	private final long start;
23  	private final long stop;
24  	private final long elapsed;
25  
26  	public static WaitResult create(long start, long stop) {
27  		return builder(start, stop).build();
28  	}
29  
30  	public static Builder builder(long start, long stop) {
31  		return new Builder(start, stop);
32  	}
33  
34  	public static class Builder {
35  
36  		private final long start;
37  		private final long stop;
38  		private final long elapsed;
39  
40  		public Builder(long start, long stop) {
41  			this.start = start;
42  			this.stop = stop;
43  			this.elapsed = stop - start;
44  		}
45  
46  		public WaitResult build() {
47  			WaitResult instance = new WaitResult(this);
48  			validate(instance);
49  			return instance;
50  		}
51  
52  		private static void validate(WaitResult instance) {
53  			checkMin(instance.start, 0, "start");
54  			checkMin(instance.stop, instance.start, "stop");
55  			checkMin(instance.elapsed, 0, "elapsed");
56  		}
57  
58  	}
59  
60  	private WaitResult(Builder builder) {
61  		this.start = builder.start;
62  		this.stop = builder.stop;
63  		this.elapsed = builder.elapsed;
64  	}
65  
66  	public long getStart() {
67  		return start;
68  	}
69  
70  	public long getElapsed() {
71  		return elapsed;
72  	}
73  
74  	public long getStop() {
75  		return stop;
76  	}
77  
78  }