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)
32 public class TimeStamp extends Property {
33 private static final long serialVersionUID = 1L;
34 @XmlElement(name = "value")
35 private long timestamp;
36 @XmlElement(name = "name")
37 private String timestampName;
39 public static final String TimeStampPropName = "timeStamp";
42 * Construct a TimeStamp proporty
44 * @param timestamp the time stampt we want to describe in "epoch"
45 * format following the rules of java.util.Date
46 * @param timestampName A qualifier for the timestamp, for example
47 * "JoinTime" or any even qualifier could come up
49 * @return Constructed object
51 public TimeStamp(long timestamp, String timestampName) {
52 super(TimeStampPropName);
53 this.timestamp = timestamp;
54 this.timestampName = timestampName;
58 * Private constructor used for JAXB mapping
61 super(TimeStampPropName);
63 this.timestampName = null;
67 public TimeStamp clone() {
68 return new TimeStamp(this.timestamp, this.timestampName);
71 public long getValue() {
72 return this.timestamp;
75 public String getTimeStampName() {
76 return this.timestampName;
80 public int hashCode() {
82 int result = super.hashCode();
83 result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
84 result = prime * result
85 + ((timestampName == null) ? 0 : timestampName.hashCode());
90 public boolean equals(Object obj) {
93 if (!super.equals(obj))
95 if (getClass() != obj.getClass())
97 TimeStamp other = (TimeStamp) obj;
98 if (timestamp != other.timestamp)
100 if (timestampName == null) {
101 if (other.timestampName != null)
103 } else if (!timestampName.equals(other.timestampName))
109 public String toString() {
110 return "TimeStamp[" + timestampName + ": " + timestamp +"]";
114 public String getStringValue() {
115 return timestampName + ": " + new Date(timestamp);