| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.cloudwatch.domain; |
| 20 | |
| 21 | import java.util.Date; |
| 22 | |
| 23 | import org.jclouds.javax.annotation.Nullable; |
| 24 | |
| 25 | /** |
| 26 | * @see <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/index.html?DT_Datapoint.html" |
| 27 | * /> |
| 28 | * |
| 29 | * @author Adrian Cole |
| 30 | */ |
| 31 | public class Datapoint { |
| 32 | |
| 33 | private final Double average; |
| 34 | private final Double maximum; |
| 35 | private final Double minimum; |
| 36 | private final Date timestamp; |
| 37 | private final Double samples; |
| 38 | private final Double sum; |
| 39 | private final StandardUnit unit; |
| 40 | private final String customUnit; |
| 41 | |
| 42 | public Datapoint(@Nullable Double average, @Nullable Double maximum, @Nullable Double minimum, |
| 43 | @Nullable Date timestamp, @Nullable Double samples, @Nullable Double sum, @Nullable StandardUnit unit, |
| 44 | @Nullable String customUnit) { |
| 45 | this.average = average; |
| 46 | this.maximum = maximum; |
| 47 | this.minimum = minimum; |
| 48 | this.timestamp = timestamp; |
| 49 | this.samples = samples; |
| 50 | this.sum = sum; |
| 51 | this.unit = unit; |
| 52 | this.customUnit = customUnit; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * return Average of samples for the datapoint. |
| 57 | */ |
| 58 | @Nullable |
| 59 | Double getAverage() { |
| 60 | return average; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * return Maximum of the samples used for the datapoint. |
| 65 | */ |
| 66 | @Nullable |
| 67 | Double getMaximum() { |
| 68 | return maximum; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * return Minimum of samples for the datapoint. |
| 73 | */ |
| 74 | @Nullable |
| 75 | Double getMinimum() { |
| 76 | return minimum; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * return Indicates the beginning of the time aggregation for this value and samples. |
| 81 | */ |
| 82 | @Nullable |
| 83 | Date getTimestamp() { |
| 84 | return timestamp; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * return The number of Measurements that contributed to the aggregate value of this datapoint. |
| 89 | */ |
| 90 | @Nullable |
| 91 | Double getSamples() { |
| 92 | return samples; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * return Sum of samples for the datapoint. |
| 97 | */ |
| 98 | @Nullable |
| 99 | Double getSum() { |
| 100 | return sum; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * return Standard unit used for the datapoint. |
| 105 | */ |
| 106 | @Nullable |
| 107 | StandardUnit getUnit() { |
| 108 | return unit; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * return CustomUnit defined for the datapoint. |
| 113 | */ |
| 114 | @Nullable |
| 115 | String getCustomUnit() { |
| 116 | return customUnit; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public int hashCode() { |
| 121 | final int prime = 31; |
| 122 | int result = 1; |
| 123 | result = prime * result + ((average == null) ? 0 : average.hashCode()); |
| 124 | result = prime * result + ((customUnit == null) ? 0 : customUnit.hashCode()); |
| 125 | result = prime * result + ((maximum == null) ? 0 : maximum.hashCode()); |
| 126 | result = prime * result + ((minimum == null) ? 0 : minimum.hashCode()); |
| 127 | result = prime * result + ((samples == null) ? 0 : samples.hashCode()); |
| 128 | result = prime * result + ((sum == null) ? 0 : sum.hashCode()); |
| 129 | result = prime * result + ((timestamp == null) ? 0 : timestamp.hashCode()); |
| 130 | result = prime * result + ((unit == null) ? 0 : unit.hashCode()); |
| 131 | return result; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public boolean equals(Object obj) { |
| 136 | if (this == obj) |
| 137 | return true; |
| 138 | if (obj == null) |
| 139 | return false; |
| 140 | if (getClass() != obj.getClass()) |
| 141 | return false; |
| 142 | Datapoint other = (Datapoint) obj; |
| 143 | if (average == null) { |
| 144 | if (other.average != null) |
| 145 | return false; |
| 146 | } else if (!average.equals(other.average)) |
| 147 | return false; |
| 148 | if (customUnit == null) { |
| 149 | if (other.customUnit != null) |
| 150 | return false; |
| 151 | } else if (!customUnit.equals(other.customUnit)) |
| 152 | return false; |
| 153 | if (maximum == null) { |
| 154 | if (other.maximum != null) |
| 155 | return false; |
| 156 | } else if (!maximum.equals(other.maximum)) |
| 157 | return false; |
| 158 | if (minimum == null) { |
| 159 | if (other.minimum != null) |
| 160 | return false; |
| 161 | } else if (!minimum.equals(other.minimum)) |
| 162 | return false; |
| 163 | if (samples == null) { |
| 164 | if (other.samples != null) |
| 165 | return false; |
| 166 | } else if (!samples.equals(other.samples)) |
| 167 | return false; |
| 168 | if (sum == null) { |
| 169 | if (other.sum != null) |
| 170 | return false; |
| 171 | } else if (!sum.equals(other.sum)) |
| 172 | return false; |
| 173 | if (timestamp == null) { |
| 174 | if (other.timestamp != null) |
| 175 | return false; |
| 176 | } else if (!timestamp.equals(other.timestamp)) |
| 177 | return false; |
| 178 | if (unit == null) { |
| 179 | if (other.unit != null) |
| 180 | return false; |
| 181 | } else if (!unit.equals(other.unit)) |
| 182 | return false; |
| 183 | return true; |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public String toString() { |
| 188 | return "[average=" + average + ", customUnit=" + customUnit + ", maximum=" + maximum + ", minimum=" + minimum |
| 189 | + ", samples=" + samples + ", sum=" + sum + ", timestamp=" + timestamp + ", unit=" + unit + "]"; |
| 190 | } |
| 191 | |
| 192 | } |