b38ec8582b17db2d765a35c9df4d3b888ed96228
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / core / TimeStamp.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.sal.core;
11
12 import javax.xml.bind.annotation.XmlElement;
13 import javax.xml.bind.annotation.XmlRootElement;
14
15 /**
16  * @file   TimeStamp.java
17  *
18  * @brief  Class representing a TimeStamp
19  *
20  * A property describing a timestamp based following the rules of
21  * java.util.Date, also given the time stamp represent the time when
22  * something happened, then a name is attached to this property so
23  * to qualify what are we talking about
24  */
25 @XmlRootElement
26 public class TimeStamp extends Property {
27     private static final long serialVersionUID = 1L;
28     @XmlElement(name = "value")
29     private long timestamp;
30     @XmlElement(name = "name")
31     private String timestampName;
32
33     public static final String TimeStampPropName = "timeStamp";
34
35     /**
36      * Construct a TimeStamp proporty
37      *
38      * @param timestamp the time stampt we want to describe in "epoch"
39      * format following the rules of java.util.Date
40      * @param timestampName A qualifier for the timestamp, for example
41      * "JoinTime" or any even qualifier could come up
42      *
43      * @return Constructed object
44      */
45     public TimeStamp(long timestamp, String timestampName) {
46         super(TimeStampPropName);
47         this.timestamp = timestamp;
48         this.timestampName = timestampName;
49     }
50
51     /*
52      * Private constructor used for JAXB mapping
53      */
54     private TimeStamp() {
55         super(TimeStampPropName);
56         this.timestamp = 0;
57         this.timestampName = null;
58     }
59
60     @Override
61     public TimeStamp clone() {
62         return new TimeStamp(this.timestamp, this.timestampName);
63     }
64
65     public long getValue() {
66         return this.timestamp;
67     }
68
69     public String getTimeStampName() {
70         return this.timestampName;
71     }
72
73     @Override
74     public int hashCode() {
75         final int prime = 31;
76         int result = super.hashCode();
77         result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
78         result = prime * result
79                 + ((timestampName == null) ? 0 : timestampName.hashCode());
80         return result;
81     }
82
83     @Override
84     public boolean equals(Object obj) {
85         if (this == obj)
86             return true;
87         if (!super.equals(obj))
88             return false;
89         if (getClass() != obj.getClass())
90             return false;
91         TimeStamp other = (TimeStamp) obj;
92         if (timestamp != other.timestamp)
93             return false;
94         if (timestampName == null) {
95             if (other.timestampName != null)
96                 return false;
97         } else if (!timestampName.equals(other.timestampName))
98             return false;
99         return true;
100     }
101
102     @Override
103     public String toString() {
104         return "TimeStamp[" + timestampName + ": " + timestamp +"]";
105     }
106 }