blob: 8b8405914f91a3633ef79c8b055b697b1519549c [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
Toshio Koidec9051db2014-10-20 15:18:37 -070016package org.onlab.onos.net.resource;
17
18import java.util.Objects;
19
Yuta HIGUCHI35242292014-11-12 18:53:15 -080020// FIXME: Document what is the unit? Mbps?
Toshio Koidec9051db2014-10-20 15:18:37 -070021/**
22 * Representation of bandwidth resource.
23 */
24public final class Bandwidth extends LinkResource {
25
26 private final double bandwidth;
27
28 /**
29 * Creates a new instance with given bandwidth.
30 *
31 * @param bandwidth bandwidth value to be assigned
32 */
33 private Bandwidth(double bandwidth) {
34 this.bandwidth = bandwidth;
35 }
36
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080037 // Constructor for serialization
38 private Bandwidth() {
39 this.bandwidth = 0;
40 }
41
Toshio Koidec9051db2014-10-20 15:18:37 -070042 /**
43 * Creates a new instance with given bandwidth.
44 *
45 * @param bandwidth bandwidth value to be assigned
46 * @return {@link Bandwidth} instance with given bandwidth
47 */
48 public static Bandwidth valueOf(double bandwidth) {
49 return new Bandwidth(bandwidth);
50 }
51
52 /**
53 * Returns bandwidth as a double value.
54 *
55 * @return bandwidth as a double value
56 */
57 public double toDouble() {
58 return bandwidth;
59 }
60
61 @Override
62 public boolean equals(Object obj) {
63 if (obj instanceof Bandwidth) {
64 Bandwidth that = (Bandwidth) obj;
65 return Objects.equals(this.bandwidth, that.bandwidth);
66 }
67 return false;
68 }
69
70 @Override
71 public int hashCode() {
72 return Objects.hashCode(this.bandwidth);
73 }
74
75 @Override
76 public String toString() {
77 return String.valueOf(this.bandwidth);
78 }
79}