Mark AD-SAL interfaces as deprecated
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / core / Bandwidth.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.sal.core;
11
12 import javax.xml.bind.annotation.XmlAccessType;
13 import javax.xml.bind.annotation.XmlAccessorType;
14 import javax.xml.bind.annotation.XmlElement;
15 import javax.xml.bind.annotation.XmlRootElement;
16
17 /**
18  * @file   BandWidth.java
19  *
20  * @brief  Class representing bandwidth
21  *
22  * Describe Bandwidth which could be of a link or whatever could have
23  * bandwidth as description. It's intended in multiple of bits per
24  * seconds.
25  */
26 @XmlRootElement
27 @XmlAccessorType(XmlAccessType.NONE)
28 @Deprecated
29 public class Bandwidth extends Property {
30     private static final long serialVersionUID = 1L;
31
32     @XmlElement(name="value")
33     protected long bandwidthValue;
34
35     public static final long BWUNK = 0;
36     public static final long BW1Kbps = (long) Math.pow(10, 3);
37     public static final long BW1Mbps = (long) Math.pow(10, 6);
38     public static final long BW10Mbps = (long) Math.pow(10, 7);
39     public static final long BW100Mbps = (long) Math.pow(10, 8);
40     public static final long BW1Gbps = (long) Math.pow(10, 9);
41     public static final long BW10Gbps = (long) Math.pow(10, 10);
42     public static final long BW40Gbps = 4 * (long) Math.pow(10, 10);
43     public static final long BW100Gbps = (long) Math.pow(10, 11);
44     public static final long BW400Gbps = 4 * (long) Math.pow(10, 11);
45     public static final long BW1Tbps = (long) Math.pow(10, 12);
46     public static final long BW1Pbps = (long) Math.pow(10, 15);
47
48     public static final String BandwidthPropName = "bandwidth";
49
50     /*
51      * Private constructor used for JAXB mapping
52      */
53     private Bandwidth() {
54         super(BandwidthPropName);
55         this.bandwidthValue = BWUNK;
56     }
57
58     public Bandwidth(long bandwidth) {
59         super(BandwidthPropName);
60         this.bandwidthValue = bandwidth;
61     }
62
63     public Bandwidth(int bandwidth) {
64         super(BandwidthPropName);
65         this.bandwidthValue = (long) bandwidth;
66     }
67
68     public Bandwidth(short bandwidth) {
69         super(BandwidthPropName);
70         this.bandwidthValue = (long) bandwidth;
71     }
72
73     public Bandwidth(String name) {
74         super(name);
75     }
76
77     @Override
78     public Bandwidth clone() {
79         return new Bandwidth(this.bandwidthValue);
80     }
81
82     public long getValue() {
83         return this.bandwidthValue;
84     }
85
86     @Override
87     public int hashCode() {
88         final int prime = 31;
89         int result = super.hashCode();
90         result = prime * result
91                 + (int) (bandwidthValue ^ (bandwidthValue >>> 32));
92         return result;
93     }
94
95     @Override
96     public boolean equals(Object obj) {
97         if (this == obj)
98             return true;
99         if (!super.equals(obj))
100             return false;
101         if (getClass() != obj.getClass())
102             return false;
103         Bandwidth other = (Bandwidth) obj;
104         if (bandwidthValue != other.bandwidthValue)
105             return false;
106         return true;
107     }
108
109     @Override
110     public String toString() {
111         return "BandWidth[" + getStringValue() + "]";
112     }
113
114     @Override
115     public String getStringValue() {
116         if (this.bandwidthValue == 0) {
117             return("UnKnown");
118         } else if (this.bandwidthValue < BW1Kbps) {
119             return(this.bandwidthValue + "bps");
120         } else if (this.bandwidthValue < BW1Mbps) {
121             return(Long.toString(this.bandwidthValue / BW1Kbps) + "Kbps");
122         } else if (this.bandwidthValue < BW1Gbps) {
123             return(Long.toString(this.bandwidthValue / BW1Mbps) + "Mbps");
124         } else if (this.bandwidthValue < BW1Tbps) {
125             return(Long.toString(this.bandwidthValue / BW1Gbps) + "Gbps");
126         } else if (this.bandwidthValue < BW1Pbps) {
127             return(Long.toString(this.bandwidthValue / BW1Tbps) + "Tbps");
128         } else {
129             return(this.bandwidthValue + "bps");
130         }
131     }
132 }