Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 1 | /* |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 2 | * Copyright 2015-2016 Open Networking Laboratory |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 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 | package org.onosproject.net.newresource; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 19 | import com.google.common.base.MoreObjects; |
Sho SHIMIZU | b1f1625 | 2015-11-25 23:03:16 -0800 | [diff] [blame] | 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.PortNumber; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 22 | |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 23 | import java.util.List; |
| 24 | import java.util.Objects; |
| 25 | import java.util.Optional; |
| 26 | |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 27 | import static com.google.common.base.Preconditions.checkArgument; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 28 | import static com.google.common.base.Preconditions.checkNotNull; |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 29 | import static com.google.common.base.Preconditions.checkState; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 32 | * An object that represent a resource in a network. |
| 33 | * A Resource can represents path-like hierarchical structure with its ID. An ID of resource is |
| 34 | * composed of a sequence of elementary resources that are not globally identifiable. A Resource |
| 35 | * can be globally identifiable by its ID. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 36 | * |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 37 | * Two types of resource are considered. One is discrete type and the other is continuous type. |
| 38 | * Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and |
| 39 | * MPLS label are examples of discrete type resource. Continuous type resource is a resource whose |
| 40 | * amount is measured as a continuous value. Bandwidth is an example of continuous type resource. |
| 41 | * A double value is associated with a continuous type value. |
| 42 | * |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 43 | * Users of this class must keep the semantics of resources regarding the hierarchical structure. |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 44 | * For example, resource, Device:1/Port:1/VLAN ID:100, is valid, but resource, |
Sho SHIMIZU | b1f1625 | 2015-11-25 23:03:16 -0800 | [diff] [blame] | 45 | * VLAN ID:100/Device:1/Port:1 is not valid because a link is not a sub-component of a VLAN ID. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 46 | */ |
| 47 | @Beta |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 48 | public abstract class Resource { |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 49 | |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 50 | private final Discrete parent; |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 51 | private final ResourceId id; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 52 | |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 53 | public static final Discrete ROOT = new Discrete(); |
Sho SHIMIZU | ba41fc1 | 2015-08-12 15:43:22 -0700 | [diff] [blame] | 54 | |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 55 | public static Resource discrete(DeviceId device) { |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 56 | return new Discrete(ResourceId.discrete(device)); |
Sho SHIMIZU | b1f1625 | 2015-11-25 23:03:16 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 59 | /** |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 60 | * Creates an resource path which represents a discrete-type resource from the specified components. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 61 | * |
Sho SHIMIZU | b1f1625 | 2015-11-25 23:03:16 -0800 | [diff] [blame] | 62 | * @param device device ID which is the first component of the path |
| 63 | * @param components following components of the path. The order represents hierarchical structure of the resource. |
Sho SHIMIZU | e552456 | 2015-11-24 14:41:20 -0800 | [diff] [blame] | 64 | * @return resource path instance |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 65 | */ |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 66 | public static Resource discrete(DeviceId device, Object... components) { |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 67 | return new Discrete(ResourceId.discrete(device, components)); |
Sho SHIMIZU | b1f1625 | 2015-11-25 23:03:16 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Creates an resource path which represents a discrete-type resource from the specified components. |
| 72 | * |
| 73 | * @param device device ID which is the first component of the path |
| 74 | * @param port port number which is the second component of the path |
| 75 | * @param components following components of the path. The order represents hierarchical structure of the resource. |
| 76 | * @return resource path instance |
| 77 | */ |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 78 | public static Resource discrete(DeviceId device, PortNumber port, Object... components) { |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 79 | return new Discrete(ResourceId.discrete(device, port, components)); |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Creates an resource path which represents a continuous-type resource from the specified components. |
| 84 | * |
| 85 | * @param value amount of the resource |
Sho SHIMIZU | b1f1625 | 2015-11-25 23:03:16 -0800 | [diff] [blame] | 86 | * @param device device ID which is the first component of the path |
| 87 | * @param components following components of the path. The order represents hierarchical structure of the resource. |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 88 | * The last element of this list must be an {@link Class} instance. Otherwise, this method throws |
| 89 | * an IllegalArgumentException. |
Sho SHIMIZU | e552456 | 2015-11-24 14:41:20 -0800 | [diff] [blame] | 90 | * @return resource path instance |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 91 | */ |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 92 | public static Resource continuous(double value, DeviceId device, Object... components) { |
Sho SHIMIZU | b1f1625 | 2015-11-25 23:03:16 -0800 | [diff] [blame] | 93 | checkArgument(components.length > 0, |
| 94 | "Length of components must be greater thant 0, but " + components.length); |
| 95 | |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 96 | return new Continuous(ResourceId.continuous(device, components), value); |
Sho SHIMIZU | b1f1625 | 2015-11-25 23:03:16 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Creates an resource path which represents a continuous-type resource from the specified components. |
| 101 | * |
| 102 | * @param value amount of the resource |
| 103 | * @param device device ID which is the first component of the path. |
| 104 | * @param port port number which is the second component of the path. |
| 105 | * @param components following components of the path. The order represents hierarchical structure of the resource. |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 106 | * The last element of this list must be an {@link Class} instance. Otherwise, this method throws |
| 107 | * an IllegalArgumentException. |
Sho SHIMIZU | b1f1625 | 2015-11-25 23:03:16 -0800 | [diff] [blame] | 108 | * @return resource path instance |
| 109 | */ |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 110 | public static Resource continuous(double value, DeviceId device, PortNumber port, Object... components) { |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 111 | return new Continuous(ResourceId.continuous(device, port, components), value); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** |
Sho SHIMIZU | 5fb1ea3 | 2016-01-14 10:58:14 -0800 | [diff] [blame] | 115 | * Creates an resource path from the specified id. |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 116 | * |
Sho SHIMIZU | 5fb1ea3 | 2016-01-14 10:58:14 -0800 | [diff] [blame] | 117 | * @param id id of the path |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 118 | */ |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 119 | protected Resource(ResourceId id) { |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 120 | checkNotNull(id); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 121 | |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 122 | this.id = id; |
| 123 | if (id.components.size() == 1) { |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 124 | this.parent = ROOT; |
| 125 | } else { |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 126 | this.parent = new Discrete(id.parent()); |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 127 | } |
Sho SHIMIZU | c9546a3 | 2015-11-10 11:22:28 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 130 | // for serialization |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 131 | private Resource() { |
Sho SHIMIZU | c9546a3 | 2015-11-10 11:22:28 -0800 | [diff] [blame] | 132 | this.parent = null; |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 133 | this.id = ResourceId.ROOT; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Returns the components of this resource path. |
| 138 | * |
| 139 | * @return the components of this resource path |
| 140 | */ |
| 141 | public List<Object> components() { |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 142 | return id.components; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 146 | * Returns the volume of this resource. |
| 147 | * |
| 148 | * @return the volume of this resource |
| 149 | */ |
| 150 | // TODO: think about other naming possibilities. amount? quantity? |
| 151 | public abstract <T> T volume(); |
| 152 | |
| 153 | /** |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 154 | * Returns the parent resource path of this instance. |
| 155 | * E.g. if this path is Link:1/VLAN ID:100, the return value is the resource path for Link:1. |
| 156 | * |
| 157 | * @return the parent resource path of this instance. |
| 158 | * If there is no parent, empty instance will be returned. |
| 159 | */ |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 160 | public Optional<Discrete> parent() { |
Sho SHIMIZU | c9546a3 | 2015-11-10 11:22:28 -0800 | [diff] [blame] | 161 | return Optional.ofNullable(parent); |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 164 | /** |
| 165 | * Returns a child resource path of this instance with specifying the child object. |
| 166 | * The child resource path is discrete-type. |
| 167 | * |
| 168 | * @param child child object |
| 169 | * @return a child resource path |
| 170 | */ |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 171 | public Resource child(Object child) { |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 172 | checkState(this instanceof Discrete); |
| 173 | |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 174 | return new Discrete(id().child(child)); |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Sho SHIMIZU | 9e1e9de | 2015-11-25 15:48:48 -0800 | [diff] [blame] | 177 | /** |
| 178 | * Returns a child resource path of this instance with specifying a child object and |
| 179 | * value. The child resource path is continuous-type. |
| 180 | * |
| 181 | * @param child child object |
| 182 | * @param value value |
| 183 | * @return a child resource path |
| 184 | */ |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 185 | public Resource child(Object child, double value) { |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 186 | checkState(this instanceof Discrete); |
| 187 | |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 188 | return new Continuous(id.child(child), value); |
Sho SHIMIZU | 0112078 | 2015-08-21 15:48:43 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /** |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 192 | * Returns the last component of this instance. |
| 193 | * |
| 194 | * @return the last component of this instance. |
| 195 | * The return value is equal to the last object of {@code components()}. |
| 196 | */ |
Sho SHIMIZU | c9546a3 | 2015-11-10 11:22:28 -0800 | [diff] [blame] | 197 | public Object last() { |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 198 | if (id.components.isEmpty()) { |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 199 | return null; |
| 200 | } |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 201 | return id.components.get(id.components.size() - 1); |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /** |
Sho SHIMIZU | 5fb1ea3 | 2016-01-14 10:58:14 -0800 | [diff] [blame] | 205 | * Returns the ID of this resource path. |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 206 | * |
Sho SHIMIZU | 5fb1ea3 | 2016-01-14 10:58:14 -0800 | [diff] [blame] | 207 | * @return the ID of this resource path |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 208 | */ |
Sho SHIMIZU | 76b30f7 | 2016-01-11 14:08:35 -0800 | [diff] [blame] | 209 | public ResourceId id() { |
| 210 | return id; |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | @Override |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 214 | public String toString() { |
| 215 | return MoreObjects.toStringHelper(this) |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 216 | .add("id", id()) |
| 217 | .add("volume", volume()) |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 218 | .toString(); |
| 219 | } |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * Represents a resource path which specifies a resource which can be measured |
| 223 | * as a discrete unit. A VLAN ID and a MPLS label of a link are examples of the resource. |
| 224 | * <p> |
| 225 | * Note: This class is exposed to the public, but intended to be used in the resource API |
| 226 | * implementation only. It is not for resource API user. |
| 227 | * </p> |
| 228 | */ |
Sho SHIMIZU | 6196cae | 2015-11-25 12:02:12 -0800 | [diff] [blame] | 229 | @Beta |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 230 | public static final class Discrete extends Resource { |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 231 | private Discrete() { |
| 232 | super(); |
| 233 | } |
| 234 | |
Sho SHIMIZU | 5fb1ea3 | 2016-01-14 10:58:14 -0800 | [diff] [blame] | 235 | private Discrete(ResourceId id) { |
| 236 | super(id); |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 237 | } |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 238 | |
| 239 | /** |
| 240 | * The user of this methods must receive the return value as the correct type. |
| 241 | * Otherwise, this methods throws an exception. |
| 242 | * |
| 243 | * @param <T> type of the return value |
| 244 | * @return the volume of this resource |
| 245 | */ |
| 246 | @SuppressWarnings("unchecked") |
| 247 | @Override |
| 248 | // TODO: consider receiving Class<T> as an argument. Which approach is convenient? |
| 249 | public <T> T volume() { |
| 250 | return (T) last(); |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public int hashCode() { |
| 255 | // the value returing from volume() is excluded due to optimization |
| 256 | return id().hashCode(); |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public boolean equals(Object obj) { |
| 261 | if (this == obj) { |
| 262 | return true; |
| 263 | } |
| 264 | if (obj == null || getClass() != obj.getClass()) { |
| 265 | return false; |
| 266 | } |
| 267 | final Discrete other = (Discrete) obj; |
| 268 | // the value returing from volume() is excluded due to optimization |
| 269 | return Objects.equals(this.id(), other.id()); |
| 270 | } |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Represents a resource path which specifies a resource which can be measured |
| 275 | * as continuous value. Bandwidth of a link is an example of the resource. |
| 276 | * <p> |
| 277 | * Note: This class is exposed to the public, but intended to be used in the resource API |
| 278 | * implementation only. It is not for resource API user. |
| 279 | */ |
Sho SHIMIZU | 6196cae | 2015-11-25 12:02:12 -0800 | [diff] [blame] | 280 | @Beta |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 281 | public static final class Continuous extends Resource { |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 282 | private final double value; |
| 283 | |
Sho SHIMIZU | 5fb1ea3 | 2016-01-14 10:58:14 -0800 | [diff] [blame] | 284 | private Continuous(ResourceId id, double value) { |
| 285 | super(id); |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 286 | this.value = value; |
| 287 | } |
| 288 | |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 289 | /** |
| 290 | * The user of this methods must receive the return value as Double or double. |
| 291 | * Otherwise, this methods throws an exception. |
| 292 | * |
| 293 | * @param <T> type of the return value |
| 294 | * @return the volume of this resource |
| 295 | */ |
| 296 | @SuppressWarnings("unchecked") |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 297 | @Override |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 298 | public <T> T volume() { |
| 299 | return (T) Double.valueOf(value); |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 300 | } |
| 301 | |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 302 | @Override |
| 303 | public int hashCode() { |
| 304 | return Objects.hash(id(), value); |
| 305 | } |
| 306 | |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 307 | @Override |
| 308 | public boolean equals(Object obj) { |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 309 | if (this == obj) { |
| 310 | return true; |
| 311 | } |
| 312 | if (obj == null || getClass() != obj.getClass()) { |
| 313 | return false; |
| 314 | } |
| 315 | final Continuous other = (Continuous) obj; |
| 316 | return Objects.equals(this.id(), other.id()) |
| 317 | && Objects.equals(this.value, other.value); |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Returns the value of the resource amount. |
| 322 | * |
| 323 | * @return the value of the resource amount |
| 324 | */ |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame^] | 325 | // FIXME: overlapping a purpose with volume() |
Sho SHIMIZU | 60ac58e | 2015-11-11 12:16:38 -0800 | [diff] [blame] | 326 | public double value() { |
| 327 | return value; |
| 328 | } |
| 329 | } |
Sho SHIMIZU | 7e6d18e | 2016-01-07 18:44:33 -0800 | [diff] [blame] | 330 | |
Sho SHIMIZU | 1f5e591 | 2015-08-10 17:00:00 -0700 | [diff] [blame] | 331 | } |