a15b3fa9cd10166b3179e163c80b5de7f50170ba
[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
29     private long timestamp;
30     @XmlElement
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     public TimeStamp clone() {
61         return new TimeStamp(this.timestamp, this.timestampName);
62     }
63
64     public long getValue() {
65         return this.timestamp;
66     }
67
68     public String getTimeStampName() {
69         return this.timestampName;
70     }
71
72     @Override
73     public int hashCode() {
74         final int prime = 31;
75         int result = super.hashCode();
76         result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
77         result = prime * result
78                 + ((timestampName == null) ? 0 : timestampName.hashCode());
79         return result;
80     }
81
82     @Override
83     public boolean equals(Object obj) {
84         if (this == obj)
85             return true;
86         if (!super.equals(obj))
87             return false;
88         if (getClass() != obj.getClass())
89             return false;
90         TimeStamp other = (TimeStamp) obj;
91         if (timestamp != other.timestamp)
92             return false;
93         if (timestampName == null) {
94             if (other.timestampName != null)
95                 return false;
96         } else if (!timestampName.equals(other.timestampName))
97             return false;
98         return true;
99     }
100
101     @Override
102     public String toString() {
103         return "TimeStamp[" + timestampName + ": " + timestamp +"]";
104     }
105 }