Make sure invokeOperation is set once
[controller.git] / opendaylight / adsal / 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.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
18
19 /**
20  * @file   TimeStamp.java
21  *
22  * @brief  Class representing a TimeStamp
23  *
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
28  */
29 @XmlRootElement
30 @XmlAccessorType(XmlAccessType.NONE)
31 @Deprecated
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;
38
39     public static final String TimeStampPropName = "timeStamp";
40
41     /**
42      * Construct a TimeStamp proporty
43      *
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
48      *
49      * @return Constructed object
50      */
51     public TimeStamp(long timestamp, String timestampName) {
52         super(TimeStampPropName);
53         this.timestamp = timestamp;
54         this.timestampName = timestampName;
55     }
56
57     /*
58      * Private constructor used for JAXB mapping
59      */
60     private TimeStamp() {
61         super(TimeStampPropName);
62         this.timestamp = 0;
63         this.timestampName = null;
64     }
65
66     @Override
67     public TimeStamp clone() {
68         return new TimeStamp(this.timestamp, this.timestampName);
69     }
70
71     public long getValue() {
72         return this.timestamp;
73     }
74
75     public String getTimeStampName() {
76         return this.timestampName;
77     }
78
79     @Override
80     public int hashCode() {
81         final int prime = 31;
82         int result = super.hashCode();
83         result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
84         result = prime * result
85                 + ((timestampName == null) ? 0 : timestampName.hashCode());
86         return result;
87     }
88
89     @Override
90     public boolean equals(Object obj) {
91         if (this == obj)
92             return true;
93         if (!super.equals(obj))
94             return false;
95         if (getClass() != obj.getClass())
96             return false;
97         TimeStamp other = (TimeStamp) obj;
98         if (timestamp != other.timestamp)
99             return false;
100         if (timestampName == null) {
101             if (other.timestampName != null)
102                 return false;
103         } else if (!timestampName.equals(other.timestampName))
104             return false;
105         return true;
106     }
107
108     @Override
109     public String toString() {
110         return "TimeStamp[" + timestampName + ": " + timestamp +"]";
111     }
112
113     @Override
114     public String getStringValue() {
115         return timestampName + ": " + new Date(timestamp);
116     }
117 }