Enhancement to switchmanager CLI commands to display all the properties of node and...
[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 java.util.Date;
13
14 import javax.xml.bind.annotation.XmlElement;
15 import javax.xml.bind.annotation.XmlRootElement;
16
17 /**
18  * @file   TimeStamp.java
19  *
20  * @brief  Class representing a TimeStamp
21  *
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
26  */
27 @XmlRootElement
28 public class TimeStamp extends Property {
29     private static final long serialVersionUID = 1L;
30     @XmlElement(name = "value")
31     private long timestamp;
32     @XmlElement(name = "name")
33     private String timestampName;
34
35     public static final String TimeStampPropName = "timeStamp";
36
37     /**
38      * Construct a TimeStamp proporty
39      *
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
44      *
45      * @return Constructed object
46      */
47     public TimeStamp(long timestamp, String timestampName) {
48         super(TimeStampPropName);
49         this.timestamp = timestamp;
50         this.timestampName = timestampName;
51     }
52
53     /*
54      * Private constructor used for JAXB mapping
55      */
56     private TimeStamp() {
57         super(TimeStampPropName);
58         this.timestamp = 0;
59         this.timestampName = null;
60     }
61
62     @Override
63     public TimeStamp clone() {
64         return new TimeStamp(this.timestamp, this.timestampName);
65     }
66
67     public long getValue() {
68         return this.timestamp;
69     }
70
71     public String getTimeStampName() {
72         return this.timestampName;
73     }
74
75     @Override
76     public int hashCode() {
77         final int prime = 31;
78         int result = super.hashCode();
79         result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
80         result = prime * result
81                 + ((timestampName == null) ? 0 : timestampName.hashCode());
82         return result;
83     }
84
85     @Override
86     public boolean equals(Object obj) {
87         if (this == obj)
88             return true;
89         if (!super.equals(obj))
90             return false;
91         if (getClass() != obj.getClass())
92             return false;
93         TimeStamp other = (TimeStamp) obj;
94         if (timestamp != other.timestamp)
95             return false;
96         if (timestampName == null) {
97             if (other.timestampName != null)
98                 return false;
99         } else if (!timestampName.equals(other.timestampName))
100             return false;
101         return true;
102     }
103
104     @Override
105     public String toString() {
106         return "TimeStamp[" + timestampName + ": " + timestamp +"]";
107     }
108
109     @Override
110     public String getStringValue() {
111         return timestampName + ": " + new Date(timestamp);
112     }
113 }