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)
26 public class Latency extends Property {
27 private static final long serialVersionUID = 1L;
29 @XmlElement(name="value")
30 private long latencyValue;
32 public static final long LATENCYUNK = 0;
33 public static final long LATENCY1ns = (long) Math.pow(10, 3);
34 public static final long LATENCY10ns = (long) Math.pow(10, 4);
35 public static final long LATENCY100ns = (long) Math.pow(10, 5);
36 public static final long LATENCY1us = (long) Math.pow(10, 6);
37 public static final long LATENCY10us = (long) Math.pow(10, 7);
38 public static final long LATENCY100us = (long) Math.pow(10, 8);
39 public static final long LATENCY1ms = (long) Math.pow(10, 9);
40 public static final long LATENCY1s = (long) Math.pow(10, 12);
42 public static final String LatencyPropName = "latency";
45 * Private constructor used for JAXB mapping
48 super(LatencyPropName);
49 this.latencyValue = LATENCYUNK;
52 public Latency(long latency) {
53 super(LatencyPropName);
54 this.latencyValue = latency;
57 public Latency(int latency) {
58 super(LatencyPropName);
59 this.latencyValue = (long) latency;
62 public Latency(short latency) {
63 super(LatencyPropName);
64 this.latencyValue = (long) latency;
68 public Latency clone() {
69 return new Latency(this.latencyValue);
72 public long getValue() {
73 return this.latencyValue;
77 public int hashCode() {
79 int result = super.hashCode();
80 result = prime * result + (int) (latencyValue ^ (latencyValue >>> 32));
85 public boolean equals(Object obj) {
88 if (!super.equals(obj))
90 if (getClass() != obj.getClass())
92 Latency other = (Latency) obj;
93 if (latencyValue != other.latencyValue)
99 public String toString() {
100 StringBuffer sb = new StringBuffer();
102 sb.append("Latency[");
103 if (this.latencyValue == 0) {
104 sb.append("UnKnown");
105 } else if (this.latencyValue < LATENCY1ns) {
106 sb.append(this.latencyValue).append("psec");
107 } else if (this.latencyValue < LATENCY1us) {
108 sb.append(Long.toString(this.latencyValue / LATENCY1ns)).append("nsec");
109 } else if (this.latencyValue < LATENCY1ms) {
110 sb.append(Long.toString(this.latencyValue / LATENCY1us)).append("usec");
111 } else if (this.latencyValue < LATENCY1s) {
112 sb.append(Long.toString(this.latencyValue / LATENCY1ms)).append("msec");
116 return sb.toString();
120 public String getStringValue() {
121 if (this.latencyValue == 0) {
123 } else if (this.latencyValue < LATENCY1ns) {
124 return(this.latencyValue + "psec");
125 } else if (this.latencyValue < LATENCY1us) {
126 return(Long.toString(this.latencyValue / LATENCY1ns) + "nsec");
127 } else if (this.latencyValue < LATENCY1ms) {
128 return(Long.toString(this.latencyValue / LATENCY1us) + "usec");
129 } else if (this.latencyValue < LATENCY1s) {
130 return(Long.toString(this.latencyValue / LATENCY1ms) + "msec");
132 return Long.toString(this.latencyValue) + "sec";