3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.opendaylight.controller.sal.core;
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;
20 * @brief Class representing Latency
22 * Describe a latency in picoseconds or multiple of its.
25 @XmlAccessorType(XmlAccessType.NONE)
27 public class Latency extends Property {
28 private static final long serialVersionUID = 1L;
30 @XmlElement(name="value")
31 private long latencyValue;
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);
43 public static final String LatencyPropName = "latency";
46 * Private constructor used for JAXB mapping
49 super(LatencyPropName);
50 this.latencyValue = LATENCYUNK;
53 public Latency(long latency) {
54 super(LatencyPropName);
55 this.latencyValue = latency;
58 public Latency(int latency) {
59 super(LatencyPropName);
60 this.latencyValue = (long) latency;
63 public Latency(short latency) {
64 super(LatencyPropName);
65 this.latencyValue = (long) latency;
69 public Latency clone() {
70 return new Latency(this.latencyValue);
73 public long getValue() {
74 return this.latencyValue;
78 public int hashCode() {
80 int result = super.hashCode();
81 result = prime * result + (int) (latencyValue ^ (latencyValue >>> 32));
86 public boolean equals(Object obj) {
89 if (!super.equals(obj))
91 if (getClass() != obj.getClass())
93 Latency other = (Latency) obj;
94 if (latencyValue != other.latencyValue)
100 public String toString() {
101 StringBuffer sb = new StringBuffer();
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");
117 return sb.toString();
121 public String getStringValue() {
122 if (this.latencyValue == 0) {
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");
133 return Long.toString(this.latencyValue) + "sec";