Refactored yang-maven-plugin. Updated tests.
[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 import org.apache.commons.lang3.builder.EqualsBuilder;
16 import org.apache.commons.lang3.builder.HashCodeBuilder;
17
18 /**
19  * @file   TimeStamp.java
20  *
21  * @brief  Class representing a TimeStamp
22  *
23  * A property describing a timestamp based following the rules of
24  * java.util.Date, also given the time stamp represent the time when
25  * something happened, then a name is attached to this property so
26  * to qualify what are we talking about
27  */
28 @XmlRootElement
29 public class TimeStamp extends Property {
30     private static final long serialVersionUID = 1L;
31     @XmlElement
32     private long timestamp;
33     @XmlElement
34     private String timestampName;
35
36     public static final String TimeStampPropName = "timeStamp";
37
38     /**
39      * Construct a TimeStamp proporty
40      *
41      * @param timestamp the time stampt we want to describe in "epoch"
42      * format following the rules of java.util.Date
43      * @param timestampName A qualifier for the timestamp, for example
44      * "JoinTime" or any even qualifier could come up
45      *
46      * @return Constructed object
47      */
48     public TimeStamp(long timestamp, String timestampName) {
49         super(TimeStampPropName);
50         this.timestamp = timestamp;
51         this.timestampName = timestampName;
52     }
53
54     /*
55      * Private constructor used for JAXB mapping
56      */
57     private TimeStamp() {
58         super(TimeStampPropName);
59         this.timestamp = 0;
60         this.timestampName = null;
61     }
62
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         return HashCodeBuilder.reflectionHashCode(this);
78     }
79
80     @Override
81     public boolean equals(Object obj) {
82         return EqualsBuilder.reflectionEquals(this, obj);
83     }
84
85     @Override
86     public String toString() {
87         return "TimeStamp[" + timestampName + ": " + timestamp +"]";
88     }
89 }