1 /* 2 * Copyright (C) 2012 Google Inc. 3 * 4 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0 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 17 package com.google.caliper.model; 18 19 import static com.google.common.base.Preconditions.checkNotNull; 20 import static com.google.common.base.Preconditions.checkState; 21 22 import com.google.common.base.MoreObjects; 23 import com.google.common.base.Objects; 24 25 import org.joda.time.Instant; 26 27 import java.util.UUID; 28 29 /** 30 * A single invocation of caliper. 31 * 32 * @author gak@google.com (Gregory Kick) 33 */ 34 public final class Run { 35 static final Run DEFAULT = new Run(); 36 37 private UUID id; 38 private String label; 39 private Instant startTime; 40 Run()41 private Run() { 42 this.id = Defaults.UUID; 43 this.label = ""; 44 this.startTime = Defaults.INSTANT; 45 } 46 Run(Builder builder)47 private Run(Builder builder) { 48 this.id = builder.id; 49 this.label = builder.label; 50 this.startTime = builder.startTime; 51 } 52 id()53 public UUID id() { 54 return id; 55 } 56 label()57 public String label() { 58 return label; 59 } 60 startTime()61 public Instant startTime() { 62 return startTime; 63 } 64 equals(Object obj)65 @Override public boolean equals(Object obj) { 66 if (obj == this) { 67 return true; 68 } else if (obj instanceof Run) { 69 Run that = (Run) obj; 70 return this.id.equals(that.id) 71 && this.label.equals(that.label) 72 && this.startTime.equals(that.startTime); 73 } else { 74 return false; 75 } 76 } 77 hashCode()78 @Override public int hashCode() { 79 return Objects.hashCode(id, label, startTime); 80 } 81 toString()82 @Override public String toString() { 83 return MoreObjects.toStringHelper(this) 84 .add("id", id) 85 .add("label", label) 86 .add("startTime", startTime) 87 .toString(); 88 } 89 90 public static final class Builder { 91 private UUID id; 92 private String label = ""; 93 private Instant startTime; 94 Builder(UUID id)95 public Builder(UUID id) { 96 this.id = checkNotNull(id); 97 } 98 label(String label)99 public Builder label(String label) { 100 this.label = checkNotNull(label); 101 return this; 102 } 103 startTime(Instant startTime)104 public Builder startTime(Instant startTime) { 105 this.startTime = checkNotNull(startTime); 106 return this; 107 } 108 build()109 public Run build() { 110 checkState(id != null); 111 checkState(startTime != null); 112 return new Run(this); 113 } 114 } 115 } 116