blob: bd0ba23bab6a24081fe21527ebf3c59d2ec61a2e [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;
19
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.
Toshio Koidec9051db2014-10-20 15:18:37 -070026 */
Sho SHIMIZU63feca72015-05-07 10:44:25 -070027public final class BandwidthResource extends LinkResource {
Toshio Koidec9051db2014-10-20 15:18:37 -070028
Sho SHIMIZUf81725b2015-05-08 13:36:02 -070029 private final Bandwidth bandwidth;
Toshio Koidec9051db2014-10-20 15:18:37 -070030
31 /**
32 * Creates a new instance with given bandwidth.
33 *
34 * @param bandwidth bandwidth value to be assigned
35 */
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -070036 public BandwidthResource(Bandwidth bandwidth) {
Sho SHIMIZUf81725b2015-05-08 13:36:02 -070037 this.bandwidth = checkNotNull(bandwidth);
Toshio Koidec9051db2014-10-20 15:18:37 -070038 }
39
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080040 // Constructor for serialization
Sho SHIMIZU63feca72015-05-07 10:44:25 -070041 private BandwidthResource() {
Sho SHIMIZUf81725b2015-05-08 13:36:02 -070042 this.bandwidth = null;
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080043 }
44
Toshio Koidec9051db2014-10-20 15:18:37 -070045 /**
Toshio Koidec9051db2014-10-20 15:18:37 -070046 * Returns bandwidth as a double value.
47 *
48 * @return bandwidth as a double value
49 */
50 public double toDouble() {
Sho SHIMIZUf81725b2015-05-08 13:36:02 -070051 return bandwidth.bps();
Toshio Koidec9051db2014-10-20 15:18:37 -070052 }
53
54 @Override
55 public boolean equals(Object obj) {
Sho SHIMIZU63feca72015-05-07 10:44:25 -070056 if (obj instanceof BandwidthResource) {
57 BandwidthResource that = (BandwidthResource) obj;
Toshio Koidec9051db2014-10-20 15:18:37 -070058 return Objects.equals(this.bandwidth, that.bandwidth);
59 }
60 return false;
61 }
62
63 @Override
64 public int hashCode() {
65 return Objects.hashCode(this.bandwidth);
66 }
67
68 @Override
69 public String toString() {
70 return String.valueOf(this.bandwidth);
71 }
72}