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;
14 import org.apache.commons.lang3.builder.EqualsBuilder;
15 import org.apache.commons.lang3.builder.HashCodeBuilder;
20 * @brief Class representing Latency
22 * Describe a latency in picoseconds or multiple of its.
25 public class Latency extends Property {
26 private static final long serialVersionUID = 1L;
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.latency = LATENCYUNK;
49 public Latency(long latency) {
50 super(LatencyPropName);
51 this.latency = latency;
54 public Latency(int latency) {
55 super(LatencyPropName);
56 this.latency = (long) latency;
59 public Latency(short latency) {
60 super(LatencyPropName);
61 this.latency = (long) latency;
64 public Latency clone() {
65 return new Latency(this.latency);
68 public long getValue() {
73 public int hashCode() {
74 return HashCodeBuilder.reflectionHashCode(this);
78 public boolean equals(Object obj) {
79 return EqualsBuilder.reflectionEquals(this, obj);
83 public String toString() {
84 StringBuffer sb = new StringBuffer();
86 sb.append("Latency[");
87 if (this.latency == 0) {
89 } else if (this.latency < LATENCY1ns) {
90 sb.append(this.latency + "psec");
91 } else if (this.latency < LATENCY1us) {
92 sb.append(Long.toString(this.latency / LATENCY1ns) + "nsec");
93 } else if (this.latency < LATENCY1ms) {
94 sb.append(Long.toString(this.latency / LATENCY1us) + "usec");
95 } else if (this.latency < LATENCY1s) {
96 sb.append(Long.toString(this.latency / LATENCY1ms) + "msec");
100 return sb.toString();