ISSUE
[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 org.apache.commons.lang3.builder.HashCodeBuilder;
13 import org.apache.commons.lang3.builder.EqualsBuilder;
14 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
15
16 import javax.xml.bind.annotation.XmlRootElement;
17 import javax.xml.bind.annotation.XmlElement;
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 public class TimeStamp extends Property {
31     private static final long serialVersionUID = 1L;
32     @XmlElement
33     private long timestamp;
34     @XmlElement
35     private String timestampName;
36
37     public static final String TimeStampPropName = "timeStamp";
38
39     /**
40      * Construct a TimeStamp proporty
41      *
42      * @param timestamp the time stampt we want to describe in "epoch"
43      * format following the rules of java.util.Date
44      * @param timestampName A qualifier for the timestamp, for example
45      * "JoinTime" or any even qualifier could come up
46      *
47      * @return Constructed object
48      */
49     public TimeStamp(long timestamp, String timestampName) {
50         super(TimeStampPropName);
51         this.timestamp = timestamp;
52         this.timestampName = timestampName;
53     }
54
55     /*
56      * Private constructor used for JAXB mapping
57      */
58     private TimeStamp() {
59         super(TimeStampPropName);
60         this.timestamp = 0;
61         this.timestampName = null;
62     }
63
64     public TimeStamp clone() {
65         return new TimeStamp(this.timestamp, this.timestampName);
66     }
67
68     public long getValue() {
69         return this.timestamp;
70     }
71
72     public String getTimeStampName() {
73         return this.timestampName;
74     }
75
76     @Override
77     public int hashCode() {
78         return HashCodeBuilder.reflectionHashCode(this);
79     }
80
81     @Override
82     public boolean equals(Object obj) {
83         return EqualsBuilder.reflectionEquals(this, obj);
84     }
85
86     @Override
87     public String toString() {
88         return "TimeStamp[" + ReflectionToStringBuilder.toString(this) + "]";
89     }
90 }