blob: 69f252949522477e0e76fb87db08fdcffa104170 [file] [log] [blame]
Sho SHIMIZU31f37ed2016-01-08 18:45:54 -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.onlab.util;
17
18import java.util.Objects;
19
20/**
21 * Representation of bandwidth.
22 * Use the static factory method corresponding to the unit (like Kbps) you desire on instantiation.
23 */
24final class DoubleBandwidth implements Bandwidth {
25
26 private final double bps;
27
28 /**
29 * Creates a new instance with given bandwidth.
30 *
31 * @param bps bandwidth value to be assigned
32 */
33 DoubleBandwidth(double bps) {
34 this.bps = bps;
35 }
36
37 // Constructor for serialization
38 private DoubleBandwidth() {
39 this.bps = 0;
40 }
41 /**
42 * Returns bandwidth in bps.
43 *
44 * @return bandwidth in bps.
45 */
46 public double bps() {
47 return bps;
48 }
49
50 @Override
51 public boolean equals(Object obj) {
52 if (obj == this) {
53 return true;
54 }
55
56 if (!(obj instanceof DoubleBandwidth)) {
57 return false;
58 }
59
60 DoubleBandwidth that = (DoubleBandwidth) obj;
61 return Objects.equals(this.bps, that.bps);
62 }
63
64 @Override
65 public int hashCode() {
66 return Long.hashCode(Double.doubleToLongBits(bps));
67 }
68
69 @Override
70 public String toString() {
71 return String.valueOf(this.bps);
72 }
73}