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;
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;
64 public Latency clone() {
65 return new Latency(this.latencyValue);
68 public long getValue() {
69 return this.latencyValue;
73 public int hashCode() {
75 int result = super.hashCode();
76 result = prime * result + (int) (latencyValue ^ (latencyValue >>> 32));
81 public boolean equals(Object obj) {
84 if (!super.equals(obj))
86 if (getClass() != obj.getClass())
88 Latency other = (Latency) obj;
89 if (latencyValue != other.latencyValue)
95 public String toString() {
96 StringBuffer sb = new StringBuffer();
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");
112 return sb.toString();