Fix to remove camel case for Northbound API
[controller.git] / opendaylight / 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.XmlElement;
13 import javax.xml.bind.annotation.XmlRootElement;
14
15 /**
16  * @file   BandWidth.java
17  *
18  * @brief  Class representing bandwidth
19  *
20  * Describe Bandwidth which could be of a link or whatever could have
21  * bandwidth as description. It's intended in multiple of bits per
22  * seconds.
23  */
24 @XmlRootElement
25 public class Bandwidth extends Property {
26     private static final long serialVersionUID = 1L;
27
28     @XmlElement(name="value")
29     protected long bandwidthValue;
30
31     public static final long BWUNK = 0;
32     public static final long BW1Kbps = (long) Math.pow(10, 3);
33     public static final long BW1Mbps = (long) Math.pow(10, 6);
34     public static final long BW10Mbps = (long) Math.pow(10, 7);
35     public static final long BW100Mbps = (long) Math.pow(10, 8);
36     public static final long BW1Gbps = (long) Math.pow(10, 9);
37     public static final long BW10Gbps = (long) Math.pow(10, 10);
38     public static final long BW40Gbps = 4 * (long) Math.pow(10, 10);
39     public static final long BW100Gbps = (long) Math.pow(10, 11);
40     public static final long BW400Gbps = 4 * (long) Math.pow(10, 11);
41     public static final long BW1Tbps = (long) Math.pow(10, 12);
42     public static final long BW1Pbps = (long) Math.pow(10, 15);
43
44     public static final String BandwidthPropName = "bandwidth";
45
46     /*
47      * Private constructor used for JAXB mapping
48      */
49     private Bandwidth() {
50         super(BandwidthPropName);
51         this.bandwidthValue = BWUNK;
52         ;
53     }
54
55     public Bandwidth(long bandwidth) {
56         super(BandwidthPropName);
57         this.bandwidthValue = bandwidth;
58     }
59
60     public Bandwidth(int bandwidth) {
61         super(BandwidthPropName);
62         this.bandwidthValue = (long) bandwidth;
63     }
64
65     public Bandwidth(short bandwidth) {
66         super(BandwidthPropName);
67         this.bandwidthValue = (long) bandwidth;
68     }
69
70     public Bandwidth(String name) {
71         super(name);
72     }
73
74     @Override
75     public Bandwidth clone() {
76         return new Bandwidth(this.bandwidthValue);
77     }
78
79     public long getValue() {
80         return this.bandwidthValue;
81     }
82
83     @Override
84     public int hashCode() {
85         final int prime = 31;
86         int result = super.hashCode();
87         result = prime * result
88                 + (int) (bandwidthValue ^ (bandwidthValue >>> 32));
89         return result;
90     }
91
92     @Override
93     public boolean equals(Object obj) {
94         if (this == obj)
95             return true;
96         if (!super.equals(obj))
97             return false;
98         if (getClass() != obj.getClass())
99             return false;
100         Bandwidth other = (Bandwidth) obj;
101         if (bandwidthValue != other.bandwidthValue)
102             return false;
103         return true;
104     }
105
106     @Override
107     public String toString() {
108         StringBuffer sb = new StringBuffer();
109
110         sb.append("BandWidth[");
111         if (this.bandwidthValue == 0) {
112             sb.append("UnKnown");
113         } else if (this.bandwidthValue < BW1Kbps) {
114             sb.append(this.bandwidthValue + "bps");
115         } else if (this.bandwidthValue < BW1Mbps) {
116             sb.append(Long.toString(this.bandwidthValue / BW1Kbps) + "Kbps");
117         } else if (this.bandwidthValue < BW1Gbps) {
118             sb.append(Long.toString(this.bandwidthValue / BW1Mbps) + "Mbps");
119         } else if (this.bandwidthValue < BW1Tbps) {
120             sb.append(Long.toString(this.bandwidthValue / BW1Gbps) + "Gbps");
121         } else if (this.bandwidthValue < BW1Pbps) {
122             sb.append(Long.toString(this.bandwidthValue / BW1Tbps) + "Tbps");
123         }
124
125         sb.append("]");
126         return sb.toString();
127     }
128 }