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.XmlElement;
13 import javax.xml.bind.annotation.XmlRootElement;
18 * @brief Class representing Latency
20 * Describe a latency in picoseconds or multiple of its.
23 public class Latency extends Property {
24 private static final long serialVersionUID = 1L;
26 @XmlElement(name="value")
27 private long latencyValue;
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);
39 public static final String LatencyPropName = "latency";
42 * Private constructor used for JAXB mapping
45 super(LatencyPropName);
46 this.latencyValue = LATENCYUNK;
49 public Latency(long latency) {
50 super(LatencyPropName);
51 this.latencyValue = latency;
54 public Latency(int latency) {
55 super(LatencyPropName);
56 this.latencyValue = (long) latency;
59 public Latency(short latency) {
60 super(LatencyPropName);
61 this.latencyValue = (long) latency;
65 public Latency clone() {
66 return new Latency(this.latencyValue);
69 public long getValue() {
70 return this.latencyValue;
74 public int hashCode() {
76 int result = super.hashCode();
77 result = prime * result + (int) (latencyValue ^ (latencyValue >>> 32));
82 public boolean equals(Object obj) {
85 if (!super.equals(obj))
87 if (getClass() != obj.getClass())
89 Latency other = (Latency) obj;
90 if (latencyValue != other.latencyValue)
96 public String toString() {
97 StringBuffer sb = new StringBuffer();
99 sb.append("Latency[");
100 if (this.latencyValue == 0) {
101 sb.append("UnKnown");
102 } else if (this.latencyValue < LATENCY1ns) {
103 sb.append(this.latencyValue + "psec");
104 } else if (this.latencyValue < LATENCY1us) {
105 sb.append(Long.toString(this.latencyValue / LATENCY1ns) + "nsec");
106 } else if (this.latencyValue < LATENCY1ms) {
107 sb.append(Long.toString(this.latencyValue / LATENCY1us) + "usec");
108 } else if (this.latencyValue < LATENCY1s) {
109 sb.append(Long.toString(this.latencyValue / LATENCY1ms) + "msec");
113 return sb.toString();