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 org.apache.commons.lang3.builder.HashCodeBuilder;
13 import org.apache.commons.lang3.builder.EqualsBuilder;
15 import javax.xml.bind.annotation.XmlRootElement;
16 import javax.xml.bind.annotation.XmlAccessType;
17 import javax.xml.bind.annotation.XmlAccessorType;
18 import javax.xml.bind.annotation.XmlElement;
23 * @brief Class representing Latency
25 * Describe a latency in picoseconds or multiple of its.
28 public class Latency extends Property {
29 private static final long serialVersionUID = 1L;
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.latency = LATENCYUNK;
52 public Latency(long latency) {
53 super(LatencyPropName);
54 this.latency = latency;
57 public Latency(int latency) {
58 super(LatencyPropName);
59 this.latency = (long) latency;
62 public Latency(short latency) {
63 super(LatencyPropName);
64 this.latency = (long) latency;
67 public Latency clone() {
68 return new Latency(this.latency);
71 public long getValue() {
76 public int hashCode() {
77 return HashCodeBuilder.reflectionHashCode(this);
81 public boolean equals(Object obj) {
82 return EqualsBuilder.reflectionEquals(this, obj);
86 public String toString() {
87 StringBuffer sb = new StringBuffer();
89 sb.append("Latency[");
90 if (this.latency == 0) {
92 } else if (this.latency < LATENCY1ns) {
93 sb.append(this.latency + "psec");
94 } else if (this.latency < LATENCY1us) {
95 sb.append(Long.toString(this.latency / LATENCY1ns) + "nsec");
96 } else if (this.latency < LATENCY1ms) {
97 sb.append(Long.toString(this.latency / LATENCY1us) + "usec");
98 } else if (this.latency < LATENCY1s) {
99 sb.append(Long.toString(this.latency / LATENCY1ms) + "msec");
103 return sb.toString();