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 java.util.Date;
14 import javax.xml.bind.annotation.XmlElement;
15 import javax.xml.bind.annotation.XmlRootElement;
18 * @file TimeStamp.java
20 * @brief Class representing a TimeStamp
22 * A property describing a timestamp based following the rules of
23 * java.util.Date, also given the time stamp represent the time when
24 * something happened, then a name is attached to this property so
25 * to qualify what are we talking about
28 public class TimeStamp extends Property {
29 private static final long serialVersionUID = 1L;
30 @XmlElement(name = "value")
31 private long timestamp;
32 @XmlElement(name = "timestampName")
33 private String timestampName;
35 public static final String TimeStampPropName = "timeStamp";
38 * Construct a TimeStamp proporty
40 * @param timestamp the time stampt we want to describe in "epoch"
41 * format following the rules of java.util.Date
42 * @param timestampName A qualifier for the timestamp, for example
43 * "JoinTime" or any even qualifier could come up
45 * @return Constructed object
47 public TimeStamp(long timestamp, String timestampName) {
48 super(TimeStampPropName);
49 this.timestamp = timestamp;
50 this.timestampName = timestampName;
54 * Private constructor used for JAXB mapping
57 super(TimeStampPropName);
59 this.timestampName = null;
63 public TimeStamp clone() {
64 return new TimeStamp(this.timestamp, this.timestampName);
67 public long getValue() {
68 return this.timestamp;
71 public String getTimeStampName() {
72 return this.timestampName;
76 public int hashCode() {
78 int result = super.hashCode();
79 result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
80 result = prime * result
81 + ((timestampName == null) ? 0 : timestampName.hashCode());
86 public boolean equals(Object obj) {
89 if (!super.equals(obj))
91 if (getClass() != obj.getClass())
93 TimeStamp other = (TimeStamp) obj;
94 if (timestamp != other.timestamp)
96 if (timestampName == null) {
97 if (other.timestampName != null)
99 } else if (!timestampName.equals(other.timestampName))
105 public String toString() {
106 return "TimeStamp[" + timestampName + ": " + timestamp +"]";
110 public String getStringValue() {
111 return timestampName + ": " + new Date(timestamp);