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.XmlRootElement;
17 * @brief Class representing Latency
19 * Describe a latency in picoseconds or multiple of its.
22 public class Latency extends Property {
23 private static final long serialVersionUID = 1L;
26 public static final long LATENCYUNK = 0;
27 public static final long LATENCY1ns = (long) Math.pow(10, 3);
28 public static final long LATENCY10ns = (long) Math.pow(10, 4);
29 public static final long LATENCY100ns = (long) Math.pow(10, 5);
30 public static final long LATENCY1us = (long) Math.pow(10, 6);
31 public static final long LATENCY10us = (long) Math.pow(10, 7);
32 public static final long LATENCY100us = (long) Math.pow(10, 8);
33 public static final long LATENCY1ms = (long) Math.pow(10, 9);
34 public static final long LATENCY1s = (long) Math.pow(10, 12);
36 public static final String LatencyPropName = "latency";
39 * Private constructor used for JAXB mapping
42 super(LatencyPropName);
43 this.latency = LATENCYUNK;
46 public Latency(long latency) {
47 super(LatencyPropName);
48 this.latency = latency;
51 public Latency(int latency) {
52 super(LatencyPropName);
53 this.latency = (long) latency;
56 public Latency(short latency) {
57 super(LatencyPropName);
58 this.latency = (long) latency;
61 public Latency clone() {
62 return new Latency(this.latency);
65 public long getValue() {
70 public int hashCode() {
72 int result = super.hashCode();
73 result = prime * result + (int) (latency ^ (latency >>> 32));
78 public boolean equals(Object obj) {
81 if (!super.equals(obj))
83 if (getClass() != obj.getClass())
85 Latency other = (Latency) obj;
86 if (latency != other.latency)
92 public String toString() {
93 StringBuffer sb = new StringBuffer();
95 sb.append("Latency[");
96 if (this.latency == 0) {
98 } else if (this.latency < LATENCY1ns) {
99 sb.append(this.latency + "psec");
100 } else if (this.latency < LATENCY1us) {
101 sb.append(Long.toString(this.latency / LATENCY1ns) + "nsec");
102 } else if (this.latency < LATENCY1ms) {
103 sb.append(Long.toString(this.latency / LATENCY1us) + "usec");
104 } else if (this.latency < LATENCY1s) {
105 sb.append(Long.toString(this.latency / LATENCY1ms) + "msec");
109 return sb.toString();