blob: b0573dc302d939c071b26873b44e251d281967ae [file] [log] [blame]
Sho SHIMIZUf33b8932016-01-25 18:43:32 -08001/*
2 * Copyright 2016 Open Networking Laboratory
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 */
16package org.onosproject.net.newresource;
17
18import com.google.common.annotations.Beta;
19
20import java.util.Objects;
21
22/**
23 * Represents a resource path which specifies a resource which can be measured
24 * as continuous value. Bandwidth of a link is an example of the resource.
25 * <p>
26 * Note: This class is exposed to the public, but intended to be used in the resource API
27 * implementation only. It is not for resource API user.
28 */
29@Beta
30// TODO: consider how to restrict the visibility
31public final class ContinuousResource extends Resource {
32 private final double value;
33
34 ContinuousResource(ResourceId id, double value) {
35 super(id);
36 this.value = value;
37 }
38
39 /**
40 * The user of this methods must receive the return value as Double or double.
41 * Otherwise, this methods throws an exception.
42 *
43 * @param <T> type of the return value
44 * @return the volume of this resource
45 */
46 @SuppressWarnings("unchecked")
47 @Override
48 public <T> T volume() {
49 return (T) Double.valueOf(value);
50 }
51
52 @Override
53 public int hashCode() {
54 return Objects.hash(id(), value);
55 }
56
57 @Override
58 public boolean equals(Object obj) {
59 if (this == obj) {
60 return true;
61 }
62 if (obj == null || getClass() != obj.getClass()) {
63 return false;
64 }
65 final ContinuousResource other = (ContinuousResource) obj;
66 return Objects.equals(this.id(), other.id())
67 && Objects.equals(this.value, other.value);
68 }
69
70 /**
71 * Returns the value of the resource amount.
72 *
73 * @return the value of the resource amount
74 */
75 // FIXME: overlapping a purpose with volume()
76 public double value() {
77 return value;
78 }
79}