blob: 2093e0b3b76abb6cb7b77e116c60d8b77ae208e5 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.resource;
Toshio Koidec9051db2014-10-20 15:18:37 -070017
18import java.util.Objects;
19
20/**
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080021 * Representation of bandwidth resource in bps.
Toshio Koidec9051db2014-10-20 15:18:37 -070022 */
Sho SHIMIZU63feca72015-05-07 10:44:25 -070023public final class BandwidthResource extends LinkResource {
Toshio Koidec9051db2014-10-20 15:18:37 -070024
25 private final double bandwidth;
26
27 /**
28 * Creates a new instance with given bandwidth.
29 *
30 * @param bandwidth bandwidth value to be assigned
31 */
Sho SHIMIZU63feca72015-05-07 10:44:25 -070032 private BandwidthResource(double bandwidth) {
Toshio Koidec9051db2014-10-20 15:18:37 -070033 this.bandwidth = bandwidth;
34 }
35
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080036 // Constructor for serialization
Sho SHIMIZU63feca72015-05-07 10:44:25 -070037 private BandwidthResource() {
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080038 this.bandwidth = 0;
39 }
40
Toshio Koidec9051db2014-10-20 15:18:37 -070041 /**
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080042 * Creates a new instance with given bandwidth in bps.
Toshio Koidec9051db2014-10-20 15:18:37 -070043 *
44 * @param bandwidth bandwidth value to be assigned
Sho SHIMIZU63feca72015-05-07 10:44:25 -070045 * @return {@link BandwidthResource} instance with given bandwidth
Toshio Koidec9051db2014-10-20 15:18:37 -070046 */
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080047 @Deprecated
Sho SHIMIZU63feca72015-05-07 10:44:25 -070048 public static BandwidthResource valueOf(double bandwidth) {
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080049 return bps(bandwidth);
50 }
51
52 /**
53 * Creates a new instance with given bandwidth in bps.
54 *
Sho SHIMIZU9a6ae382015-05-08 13:32:19 -070055 * @param bps bandwidth value to be assigned
Sho SHIMIZU63feca72015-05-07 10:44:25 -070056 * @return {@link BandwidthResource} instance with given bandwidth
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080057 */
Sho SHIMIZU9a6ae382015-05-08 13:32:19 -070058 public static BandwidthResource bps(double bps) {
59 return new BandwidthResource(bps);
Toshio Koidec9051db2014-10-20 15:18:37 -070060 }
61
62 /**
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080063 * Creates a new instance with given bandwidth in Kbps.
64 *
Sho SHIMIZU9a6ae382015-05-08 13:32:19 -070065 * @param kbps bandwidth value to be assigned
Sho SHIMIZU63feca72015-05-07 10:44:25 -070066 * @return {@link BandwidthResource} instance with given bandwidth
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080067 */
Sho SHIMIZU9a6ae382015-05-08 13:32:19 -070068 public static BandwidthResource kbps(double kbps) {
69 return new BandwidthResource(kbps * 1_000L);
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080070 }
71
72 /**
73 * Creates a new instance with given bandwidth in Mbps.
74 *
Sho SHIMIZU9a6ae382015-05-08 13:32:19 -070075 * @param mbps bandwidth value to be assigned
Sho SHIMIZU63feca72015-05-07 10:44:25 -070076 * @return {@link BandwidthResource} instance with given bandwidth
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080077 */
Sho SHIMIZU9a6ae382015-05-08 13:32:19 -070078 public static BandwidthResource mbps(double mbps) {
79 return new BandwidthResource(mbps * 1_000_000L);
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080080 }
81
82 /**
83 * Creates a new instance with given bandwidth in Gbps.
84 *
Sho SHIMIZU9a6ae382015-05-08 13:32:19 -070085 * @param gbps bandwidth value to be assigned
Sho SHIMIZU63feca72015-05-07 10:44:25 -070086 * @return {@link BandwidthResource} instance with given bandwidth
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080087 */
Sho SHIMIZU9a6ae382015-05-08 13:32:19 -070088 public static BandwidthResource gbps(double gbps) {
89 return new BandwidthResource(gbps * 1_000_000_000L);
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080090 }
91
92 /**
Toshio Koidec9051db2014-10-20 15:18:37 -070093 * Returns bandwidth as a double value.
94 *
95 * @return bandwidth as a double value
96 */
97 public double toDouble() {
98 return bandwidth;
99 }
100
101 @Override
102 public boolean equals(Object obj) {
Sho SHIMIZU63feca72015-05-07 10:44:25 -0700103 if (obj instanceof BandwidthResource) {
104 BandwidthResource that = (BandwidthResource) obj;
Toshio Koidec9051db2014-10-20 15:18:37 -0700105 return Objects.equals(this.bandwidth, that.bandwidth);
106 }
107 return false;
108 }
109
110 @Override
111 public int hashCode() {
112 return Objects.hashCode(this.bandwidth);
113 }
114
115 @Override
116 public String toString() {
117 return String.valueOf(this.bandwidth);
118 }
119}