Bug 1029: Remove dead code: samples/clustersession
[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.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 public class TimeStamp extends Property {
32     private static final long serialVersionUID = 1L;
33     @XmlElement(name = "value")
34     private long timestamp;
35     @XmlElement(name = "name")
36     private String timestampName;
37
38     public static final String TimeStampPropName = "timeStamp";
39
40     /**
41      * Construct a TimeStamp proporty
42      *
43      * @param timestamp the time stampt we want to describe in "epoch"
44      * format following the rules of java.util.Date
45      * @param timestampName A qualifier for the timestamp, for example
46      * "JoinTime" or any even qualifier could come up
47      *
48      * @return Constructed object
49      */
50     public TimeStamp(long timestamp, String timestampName) {
51         super(TimeStampPropName);
52         this.timestamp = timestamp;
53         this.timestampName = timestampName;
54     }
55
56     /*
57      * Private constructor used for JAXB mapping
58      */
59     private TimeStamp() {
60         super(TimeStampPropName);
61         this.timestamp = 0;
62         this.timestampName = null;
63     }
64
65     @Override
66     public TimeStamp clone() {
67         return new TimeStamp(this.timestamp, this.timestampName);
68     }
69
70     public long getValue() {
71         return this.timestamp;
72     }
73
74     public String getTimeStampName() {
75         return this.timestampName;
76     }
77
78     @Override
79     public int hashCode() {
80         final int prime = 31;
81         int result = super.hashCode();
82         result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
83         result = prime * result
84                 + ((timestampName == null) ? 0 : timestampName.hashCode());
85         return result;
86     }
87
88     @Override
89     public boolean equals(Object obj) {
90         if (this == obj)
91             return true;
92         if (!super.equals(obj))
93             return false;
94         if (getClass() != obj.getClass())
95             return false;
96         TimeStamp other = (TimeStamp) obj;
97         if (timestamp != other.timestamp)
98             return false;
99         if (timestampName == null) {
100             if (other.timestampName != null)
101                 return false;
102         } else if (!timestampName.equals(other.timestampName))
103             return false;
104         return true;
105     }
106
107     @Override
108     public String toString() {
109         return "TimeStamp[" + timestampName + ": " + timestamp +"]";
110     }
111
112     @Override
113     public String getStringValue() {
114         return timestampName + ": " + new Date(timestamp);
115     }
116 }