001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.common.util.wait;
017
018import static org.kuali.common.util.base.Precondition.checkMin;
019
020public final class WaitResult {
021
022        private final long start;
023        private final long stop;
024        private final long elapsed;
025
026        public static WaitResult create(long start, long stop) {
027                return builder(start, stop).build();
028        }
029
030        public static Builder builder(long start, long stop) {
031                return new Builder(start, stop);
032        }
033
034        public static class Builder {
035
036                private final long start;
037                private final long stop;
038                private final long elapsed;
039
040                public Builder(long start, long stop) {
041                        this.start = start;
042                        this.stop = stop;
043                        this.elapsed = stop - start;
044                }
045
046                public WaitResult build() {
047                        WaitResult instance = new WaitResult(this);
048                        validate(instance);
049                        return instance;
050                }
051
052                private static void validate(WaitResult instance) {
053                        checkMin(instance.start, 0, "start");
054                        checkMin(instance.stop, instance.start, "stop");
055                        checkMin(instance.elapsed, 0, "elapsed");
056                }
057
058        }
059
060        private WaitResult(Builder builder) {
061                this.start = builder.start;
062                this.stop = builder.stop;
063                this.elapsed = builder.elapsed;
064        }
065
066        public long getStart() {
067                return start;
068        }
069
070        public long getElapsed() {
071                return elapsed;
072        }
073
074        public long getStop() {
075                return stop;
076        }
077
078}