Add data-provider
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / base / toggleAlarmFilter / NotificationWithServerTimeStamp.java
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  * http://www.apache.org/licenses/LICENSE-2.0
11  * 
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter;
19
20 public class NotificationWithServerTimeStamp<T2> {
21     private final T2 alarmNotification;
22     private T2 contraAlarmNotification;
23     private final long timestampStart;
24     private long timestamp;
25
26     public NotificationWithServerTimeStamp(T2 n) {
27         this(n, System.currentTimeMillis());
28     }
29
30     public NotificationWithServerTimeStamp(T2 n, long ts) {
31         this.alarmNotification = n;
32         this.contraAlarmNotification = null;
33         this.timestamp = ts;
34         this.timestampStart=ts;
35     }
36
37     @SuppressWarnings("unused")
38     public long getStartTime() {
39         return this.timestampStart;
40     }
41     public void refresh() {
42         this.refresh(System.currentTimeMillis());
43     }
44
45     public void refresh(long ts) {
46         this.timestamp = ts;
47     }
48
49     public void setContraEvent(T2 notification) {
50         this.contraAlarmNotification = notification;
51         this.refresh();
52     }
53
54     public void clrContraEvent() {
55         this.contraAlarmNotification = null;
56         this.refresh();
57     }
58
59     public boolean isStable(long now) {
60         return this.timestamp + NotificationDelayFilter.getDelay() < now;
61     }
62
63     @SuppressWarnings("unused")
64     public T2 getAlarmNotification() {
65         return this.alarmNotification;
66     }
67
68     public T2 getContraAlarmNotification() {
69         return this.contraAlarmNotification;
70     }
71
72     @Override
73     public String toString() {
74         return "NotificationWithServerTimeStamp [alarmNotification=" + alarmNotification
75                 + ", contraAlarmNotification=" + contraAlarmNotification + ", timestampStart=" + timestampStart
76                 + ", timestamp=" + timestamp + "]";
77     }
78 }