blob: 15fe820bd1f983a7eca99d95a6fa83e58bcfe67c [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 */
23public final class Bandwidth extends LinkResource {
24
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 */
32 private Bandwidth(double bandwidth) {
33 this.bandwidth = bandwidth;
34 }
35
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080036 // Constructor for serialization
37 private Bandwidth() {
38 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
45 * @return {@link Bandwidth} instance with given bandwidth
46 */
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080047 @Deprecated
Toshio Koidec9051db2014-10-20 15:18:37 -070048 public static Bandwidth 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 *
55 * @param bandwidth bandwidth value to be assigned
56 * @return {@link Bandwidth} instance with given bandwidth
57 */
58 public static Bandwidth bps(double bandwidth) {
Toshio Koidec9051db2014-10-20 15:18:37 -070059 return new Bandwidth(bandwidth);
60 }
61
62 /**
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080063 * Creates a new instance with given bandwidth in Kbps.
64 *
65 * @param bandwidth bandwidth value to be assigned
66 * @return {@link Bandwidth} instance with given bandwidth
67 */
68 public static Bandwidth kbps(double bandwidth) {
69 return new Bandwidth(bandwidth * 1_000L);
70 }
71
72 /**
73 * Creates a new instance with given bandwidth in Mbps.
74 *
75 * @param bandwidth bandwidth value to be assigned
76 * @return {@link Bandwidth} instance with given bandwidth
77 */
78 public static Bandwidth mbps(double bandwidth) {
79 return new Bandwidth(bandwidth * 1_000_000L);
80 }
81
82 /**
83 * Creates a new instance with given bandwidth in Gbps.
84 *
85 * @param bandwidth bandwidth value to be assigned
86 * @return {@link Bandwidth} instance with given bandwidth
87 */
88 public static Bandwidth gbps(double bandwidth) {
89 return new Bandwidth(bandwidth * 1_000_000_000L);
90 }
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) {
103 if (obj instanceof Bandwidth) {
104 Bandwidth that = (Bandwidth) obj;
105 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}