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.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
20 * @file TimeStamp.java
22 * @brief Class representing a TimeStamp
24 * A property describing a timestamp based following the rules of
25 * java.util.Date, also given the time stamp represent the time when
26 * something happened, then a name is attached to this property so
27 * to qualify what are we talking about
30 @XmlAccessorType(XmlAccessType.NONE)
31 public class TimeStamp extends Property {
32 private static final long serialVersionUID = 1L;
33 @XmlElement(name = "value")
34 private long timestamp;
35 @XmlElement(name = "name")
36 private String timestampName;
38 public static final String TimeStampPropName = "timeStamp";
41 * Construct a TimeStamp proporty
43 * @param timestamp the time stampt we want to describe in "epoch"
44 * format following the rules of java.util.Date
45 * @param timestampName A qualifier for the timestamp, for example
46 * "JoinTime" or any even qualifier could come up
48 * @return Constructed object
50 public TimeStamp(long timestamp, String timestampName) {
51 super(TimeStampPropName);
52 this.timestamp = timestamp;
53 this.timestampName = timestampName;
57 * Private constructor used for JAXB mapping
60 super(TimeStampPropName);
62 this.timestampName = null;
66 public TimeStamp clone() {
67 return new TimeStamp(this.timestamp, this.timestampName);
70 public long getValue() {
71 return this.timestamp;
74 public String getTimeStampName() {
75 return this.timestampName;
79 public int hashCode() {
81 int result = super.hashCode();
82 result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
83 result = prime * result
84 + ((timestampName == null) ? 0 : timestampName.hashCode());
89 public boolean equals(Object obj) {
92 if (!super.equals(obj))
94 if (getClass() != obj.getClass())
96 TimeStamp other = (TimeStamp) obj;
97 if (timestamp != other.timestamp)
99 if (timestampName == null) {
100 if (other.timestampName != null)
102 } else if (!timestampName.equals(other.timestampName))
108 public String toString() {
109 return "TimeStamp[" + timestampName + ": " + timestamp +"]";
113 public String getStringValue() {
114 return timestampName + ": " + new Date(timestamp);