Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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 Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.resource; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | /** |
| 21 | * Representation of bandwidth resource. |
| 22 | */ |
| 23 | public 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 | |
| 36 | /** |
| 37 | * Creates a new instance with given bandwidth. |
| 38 | * |
| 39 | * @param bandwidth bandwidth value to be assigned |
| 40 | * @return {@link Bandwidth} instance with given bandwidth |
| 41 | */ |
| 42 | public static Bandwidth valueOf(double bandwidth) { |
| 43 | return new Bandwidth(bandwidth); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Returns bandwidth as a double value. |
| 48 | * |
| 49 | * @return bandwidth as a double value |
| 50 | */ |
| 51 | public double toDouble() { |
| 52 | return bandwidth; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public boolean equals(Object obj) { |
| 57 | if (obj instanceof Bandwidth) { |
| 58 | Bandwidth that = (Bandwidth) obj; |
| 59 | return Objects.equals(this.bandwidth, that.bandwidth); |
| 60 | } |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public int hashCode() { |
| 66 | return Objects.hashCode(this.bandwidth); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public String toString() { |
| 71 | return String.valueOf(this.bandwidth); |
| 72 | } |
| 73 | } |