Mark AD-SAL interfaces as deprecated
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / core / Latency.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   Latency.java
19  *
20  * @brief  Class representing Latency
21  *
22  * Describe a latency in picoseconds or multiple of its.
23  */
24 @XmlRootElement
25 @XmlAccessorType(XmlAccessType.NONE)
26 @Deprecated
27 public class Latency extends Property {
28     private static final long serialVersionUID = 1L;
29
30     @XmlElement(name="value")
31     private long latencyValue;
32
33     public static final long LATENCYUNK = 0;
34     public static final long LATENCY1ns = (long) Math.pow(10, 3);
35     public static final long LATENCY10ns = (long) Math.pow(10, 4);
36     public static final long LATENCY100ns = (long) Math.pow(10, 5);
37     public static final long LATENCY1us = (long) Math.pow(10, 6);
38     public static final long LATENCY10us = (long) Math.pow(10, 7);
39     public static final long LATENCY100us = (long) Math.pow(10, 8);
40     public static final long LATENCY1ms = (long) Math.pow(10, 9);
41     public static final long LATENCY1s = (long) Math.pow(10, 12);
42
43     public static final String LatencyPropName = "latency";
44
45     /*
46      * Private constructor used for JAXB mapping
47      */
48     private Latency() {
49         super(LatencyPropName);
50         this.latencyValue = LATENCYUNK;
51     }
52
53     public Latency(long latency) {
54         super(LatencyPropName);
55         this.latencyValue = latency;
56     }
57
58     public Latency(int latency) {
59         super(LatencyPropName);
60         this.latencyValue = (long) latency;
61     }
62
63     public Latency(short latency) {
64         super(LatencyPropName);
65         this.latencyValue = (long) latency;
66     }
67
68     @Override
69     public Latency clone() {
70         return new Latency(this.latencyValue);
71     }
72
73     public long getValue() {
74         return this.latencyValue;
75     }
76
77     @Override
78     public int hashCode() {
79         final int prime = 31;
80         int result = super.hashCode();
81         result = prime * result + (int) (latencyValue ^ (latencyValue >>> 32));
82         return result;
83     }
84
85     @Override
86     public boolean equals(Object obj) {
87         if (this == obj)
88             return true;
89         if (!super.equals(obj))
90             return false;
91         if (getClass() != obj.getClass())
92             return false;
93         Latency other = (Latency) obj;
94         if (latencyValue != other.latencyValue)
95             return false;
96         return true;
97     }
98
99     @Override
100     public String toString() {
101         StringBuffer sb = new StringBuffer();
102
103         sb.append("Latency[");
104         if (this.latencyValue == 0) {
105             sb.append("UnKnown");
106         } else if (this.latencyValue < LATENCY1ns) {
107             sb.append(this.latencyValue).append("psec");
108         } else if (this.latencyValue < LATENCY1us) {
109             sb.append(Long.toString(this.latencyValue / LATENCY1ns)).append("nsec");
110         } else if (this.latencyValue < LATENCY1ms) {
111             sb.append(Long.toString(this.latencyValue / LATENCY1us)).append("usec");
112         } else if (this.latencyValue < LATENCY1s) {
113             sb.append(Long.toString(this.latencyValue / LATENCY1ms)).append("msec");
114         }
115
116         sb.append("]");
117         return sb.toString();
118     }
119
120     @Override
121     public String getStringValue() {
122         if (this.latencyValue == 0) {
123             return("UnKnown");
124         } else if (this.latencyValue < LATENCY1ns) {
125             return(this.latencyValue + "psec");
126         } else if (this.latencyValue < LATENCY1us) {
127             return(Long.toString(this.latencyValue / LATENCY1ns) + "nsec");
128         } else if (this.latencyValue < LATENCY1ms) {
129             return(Long.toString(this.latencyValue / LATENCY1us) + "usec");
130         } else if (this.latencyValue < LATENCY1s) {
131             return(Long.toString(this.latencyValue / LATENCY1ms) + "msec");
132         } else {
133             return Long.toString(this.latencyValue) + "sec";
134         }
135     }
136 }