blob: d3bd2d7bc652f1750b1f4eb29cc824fa2c69a79e [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'Connor6de2e202015-05-21 14:30:41 -070016package org.onosproject.net.resource.link;
Toshio Koidec9051db2014-10-20 15:18:37 -070017
Sho SHIMIZUf81725b2015-05-08 13:36:02 -070018import org.onlab.util.Bandwidth;
HIGUCHI Yuta501c4652015-10-29 14:21:48 -070019import org.onlab.util.DataRateUnit;
Toshio Koidec9051db2014-10-20 15:18:37 -070020import java.util.Objects;
21
Sho SHIMIZUf81725b2015-05-08 13:36:02 -070022import static com.google.common.base.Preconditions.checkNotNull;
23
Toshio Koidec9051db2014-10-20 15:18:37 -070024/**
Sho SHIMIZU0ce220a2015-01-23 15:54:47 -080025 * Representation of bandwidth resource in bps.
Sho SHIMIZU364cbac2015-10-29 15:47:35 -070026 *
27 * @deprecated in Emu Release
Toshio Koidec9051db2014-10-20 15:18:37 -070028 */
Sho SHIMIZU364cbac2015-10-29 15:47:35 -070029@Deprecated
Sho SHIMIZU1c221ad2015-07-02 10:08:08 -070030public final class BandwidthResource implements LinkResource {
Toshio Koidec9051db2014-10-20 15:18:37 -070031
Sho SHIMIZUf81725b2015-05-08 13:36:02 -070032 private final Bandwidth bandwidth;
Toshio Koidec9051db2014-10-20 15:18:37 -070033
34 /**
35 * Creates a new instance with given bandwidth.
36 *
37 * @param bandwidth bandwidth value to be assigned
38 */
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -070039 public BandwidthResource(Bandwidth bandwidth) {
Sho SHIMIZUf81725b2015-05-08 13:36:02 -070040 this.bandwidth = checkNotNull(bandwidth);
Toshio Koidec9051db2014-10-20 15:18:37 -070041 }
42
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080043 // Constructor for serialization
Sho SHIMIZU63feca72015-05-07 10:44:25 -070044 private BandwidthResource() {
Sho SHIMIZUf81725b2015-05-08 13:36:02 -070045 this.bandwidth = null;
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080046 }
47
Toshio Koidec9051db2014-10-20 15:18:37 -070048 /**
HIGUCHI Yuta501c4652015-10-29 14:21:48 -070049 * Creates a new bandwidth resource.
50 *
51 * @param v amount of bandwidth to request
52 * @param unit {@link DataRateUnit} of {@code v}
53 * @return {@link BandwidthResource} instance with given bandwidth
54 */
55 public static BandwidthResource of(double v, DataRateUnit unit) {
56 return new BandwidthResource(Bandwidth.of(v, unit));
57 }
58
59 /**
Toshio Koidec9051db2014-10-20 15:18:37 -070060 * Returns bandwidth as a double value.
61 *
62 * @return bandwidth as a double value
63 */
64 public double toDouble() {
Sho SHIMIZUf81725b2015-05-08 13:36:02 -070065 return bandwidth.bps();
Toshio Koidec9051db2014-10-20 15:18:37 -070066 }
67
68 @Override
69 public boolean equals(Object obj) {
Sho SHIMIZU63feca72015-05-07 10:44:25 -070070 if (obj instanceof BandwidthResource) {
71 BandwidthResource that = (BandwidthResource) obj;
Toshio Koidec9051db2014-10-20 15:18:37 -070072 return Objects.equals(this.bandwidth, that.bandwidth);
73 }
74 return false;
75 }
76
77 @Override
78 public int hashCode() {
79 return Objects.hashCode(this.bandwidth);
80 }
81
82 @Override
83 public String toString() {
84 return String.valueOf(this.bandwidth);
85 }
86}