Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.resource; |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | /** |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 21 | * Representation of bandwidth resource in bps. |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 22 | */ |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 23 | public final class BandwidthResource extends LinkResource { |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 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 | */ |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 32 | private BandwidthResource(double bandwidth) { |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 33 | this.bandwidth = bandwidth; |
| 34 | } |
| 35 | |
Thomas Vachuska | 7d0032b | 2014-11-04 17:39:57 -0800 | [diff] [blame] | 36 | // Constructor for serialization |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 37 | private BandwidthResource() { |
Thomas Vachuska | 7d0032b | 2014-11-04 17:39:57 -0800 | [diff] [blame] | 38 | this.bandwidth = 0; |
| 39 | } |
| 40 | |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 41 | /** |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 42 | * Creates a new instance with given bandwidth in bps. |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 43 | * |
| 44 | * @param bandwidth bandwidth value to be assigned |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 45 | * @return {@link BandwidthResource} instance with given bandwidth |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 46 | */ |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 47 | @Deprecated |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 48 | public static BandwidthResource valueOf(double bandwidth) { |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 49 | return bps(bandwidth); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Creates a new instance with given bandwidth in bps. |
| 54 | * |
Sho SHIMIZU | 9a6ae38 | 2015-05-08 13:32:19 -0700 | [diff] [blame^] | 55 | * @param bps bandwidth value to be assigned |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 56 | * @return {@link BandwidthResource} instance with given bandwidth |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 57 | */ |
Sho SHIMIZU | 9a6ae38 | 2015-05-08 13:32:19 -0700 | [diff] [blame^] | 58 | public static BandwidthResource bps(double bps) { |
| 59 | return new BandwidthResource(bps); |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 63 | * Creates a new instance with given bandwidth in Kbps. |
| 64 | * |
Sho SHIMIZU | 9a6ae38 | 2015-05-08 13:32:19 -0700 | [diff] [blame^] | 65 | * @param kbps bandwidth value to be assigned |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 66 | * @return {@link BandwidthResource} instance with given bandwidth |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 67 | */ |
Sho SHIMIZU | 9a6ae38 | 2015-05-08 13:32:19 -0700 | [diff] [blame^] | 68 | public static BandwidthResource kbps(double kbps) { |
| 69 | return new BandwidthResource(kbps * 1_000L); |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Creates a new instance with given bandwidth in Mbps. |
| 74 | * |
Sho SHIMIZU | 9a6ae38 | 2015-05-08 13:32:19 -0700 | [diff] [blame^] | 75 | * @param mbps bandwidth value to be assigned |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 76 | * @return {@link BandwidthResource} instance with given bandwidth |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 77 | */ |
Sho SHIMIZU | 9a6ae38 | 2015-05-08 13:32:19 -0700 | [diff] [blame^] | 78 | public static BandwidthResource mbps(double mbps) { |
| 79 | return new BandwidthResource(mbps * 1_000_000L); |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Creates a new instance with given bandwidth in Gbps. |
| 84 | * |
Sho SHIMIZU | 9a6ae38 | 2015-05-08 13:32:19 -0700 | [diff] [blame^] | 85 | * @param gbps bandwidth value to be assigned |
Sho SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 86 | * @return {@link BandwidthResource} instance with given bandwidth |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 87 | */ |
Sho SHIMIZU | 9a6ae38 | 2015-05-08 13:32:19 -0700 | [diff] [blame^] | 88 | public static BandwidthResource gbps(double gbps) { |
| 89 | return new BandwidthResource(gbps * 1_000_000_000L); |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 93 | * 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 SHIMIZU | 63feca7 | 2015-05-07 10:44:25 -0700 | [diff] [blame] | 103 | if (obj instanceof BandwidthResource) { |
| 104 | BandwidthResource that = (BandwidthResource) obj; |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 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 | } |