Added annotations to Latency for northbound usage.
[controller.git] / opendaylight / 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.XmlElement;
13 import javax.xml.bind.annotation.XmlRootElement;
14
15 /**
16  * @file   Latency.java
17  *
18  * @brief  Class representing Latency
19  *
20  * Describe a latency in picoseconds or multiple of its.
21  */
22 @XmlRootElement
23 public class Latency extends Property {
24     private static final long serialVersionUID = 1L;
25
26     @XmlElement
27     private long latencyValue;
28
29     public static final long LATENCYUNK = 0;
30     public static final long LATENCY1ns = (long) Math.pow(10, 3);
31     public static final long LATENCY10ns = (long) Math.pow(10, 4);
32     public static final long LATENCY100ns = (long) Math.pow(10, 5);
33     public static final long LATENCY1us = (long) Math.pow(10, 6);
34     public static final long LATENCY10us = (long) Math.pow(10, 7);
35     public static final long LATENCY100us = (long) Math.pow(10, 8);
36     public static final long LATENCY1ms = (long) Math.pow(10, 9);
37     public static final long LATENCY1s = (long) Math.pow(10, 12);
38
39     public static final String LatencyPropName = "latency";
40
41     /*
42      * Private constructor used for JAXB mapping
43      */
44     private Latency() {
45         super(LatencyPropName);
46         this.latencyValue = LATENCYUNK;
47     }
48
49     public Latency(long latency) {
50         super(LatencyPropName);
51         this.latencyValue = latency;
52     }
53
54     public Latency(int latency) {
55         super(LatencyPropName);
56         this.latencyValue = (long) latency;
57     }
58
59     public Latency(short latency) {
60         super(LatencyPropName);
61         this.latencyValue = (long) latency;
62     }
63
64     public Latency clone() {
65         return new Latency(this.latencyValue);
66     }
67
68     public long getValue() {
69         return this.latencyValue;
70     }
71
72     @Override
73     public int hashCode() {
74         final int prime = 31;
75         int result = super.hashCode();
76         result = prime * result + (int) (latencyValue ^ (latencyValue >>> 32));
77         return result;
78     }
79
80     @Override
81     public boolean equals(Object obj) {
82         if (this == obj)
83             return true;
84         if (!super.equals(obj))
85             return false;
86         if (getClass() != obj.getClass())
87             return false;
88         Latency other = (Latency) obj;
89         if (latencyValue != other.latencyValue)
90             return false;
91         return true;
92     }
93
94     @Override
95     public String toString() {
96         StringBuffer sb = new StringBuffer();
97
98         sb.append("Latency[");
99         if (this.latencyValue == 0) {
100             sb.append("UnKnown");
101         } else if (this.latencyValue < LATENCY1ns) {
102             sb.append(this.latencyValue + "psec");
103         } else if (this.latencyValue < LATENCY1us) {
104             sb.append(Long.toString(this.latencyValue / LATENCY1ns) + "nsec");
105         } else if (this.latencyValue < LATENCY1ms) {
106             sb.append(Long.toString(this.latencyValue / LATENCY1us) + "usec");
107         } else if (this.latencyValue < LATENCY1s) {
108             sb.append(Long.toString(this.latencyValue / LATENCY1ms) + "msec");
109         }
110
111         sb.append("]");
112         return sb.toString();
113     }
114 }