Revert "Checkstyle enforcer"
[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
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     public Bandwidth clone() {
75         return new Bandwidth(this.bandwidthValue);
76     }
77
78     public long getValue() {
79         return this.bandwidthValue;
80     }
81
82     @Override
83     public int hashCode() {
84         final int prime = 31;
85         int result = super.hashCode();
86         result = prime * result
87                 + (int) (bandwidthValue ^ (bandwidthValue >>> 32));
88         return result;
89     }
90
91     @Override
92     public boolean equals(Object obj) {
93         if (this == obj)
94             return true;
95         if (!super.equals(obj))
96             return false;
97         if (getClass() != obj.getClass())
98             return false;
99         Bandwidth other = (Bandwidth) obj;
100         if (bandwidthValue != other.bandwidthValue)
101             return false;
102         return true;
103     }
104
105     @Override
106     public String toString() {
107         StringBuffer sb = new StringBuffer();
108
109         sb.append("BandWidth[");
110         if (this.bandwidthValue == 0) {
111             sb.append("UnKnown");
112         } else if (this.bandwidthValue < BW1Kbps) {
113             sb.append(this.bandwidthValue + "bps");
114         } else if (this.bandwidthValue < BW1Mbps) {
115             sb.append(Long.toString(this.bandwidthValue / BW1Kbps) + "Kbps");
116         } else if (this.bandwidthValue < BW1Gbps) {
117             sb.append(Long.toString(this.bandwidthValue / BW1Mbps) + "Mbps");
118         } else if (this.bandwidthValue < BW1Tbps) {
119             sb.append(Long.toString(this.bandwidthValue / BW1Gbps) + "Gbps");
120         } else if (this.bandwidthValue < BW1Pbps) {
121             sb.append(Long.toString(this.bandwidthValue / BW1Tbps) + "Tbps");
122         }
123
124         sb.append("]");
125         return sb.toString();
126     }
127 }