-
Notifications
You must be signed in to change notification settings - Fork 402
/
AbstractDownlinkRequest.java
76 lines (68 loc) · 2.43 KB
/
AbstractDownlinkRequest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*******************************************************************************
* Copyright (c) 2013-2015 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
*******************************************************************************/
package org.eclipse.leshan.core.request;
import org.eclipse.leshan.core.node.LwM2mPath;
import org.eclipse.leshan.core.response.LwM2mResponse;
import org.eclipse.leshan.util.Validate;
/**
* A base class for concrete LWM2M Downlink request types.
*
* Provides generic support for specifying the target client and the resource path.
*/
public abstract class AbstractDownlinkRequest<T extends LwM2mResponse> implements DownlinkRequest<T> {
private final LwM2mPath path;
protected AbstractDownlinkRequest(LwM2mPath path) {
Validate.notNull(path);
if (path.isRoot()) {
throw new IllegalArgumentException("downlink request cannot target root path: " + path.toString());
}
if (path.isResourceInstance()) {
throw new IllegalArgumentException(
"downlink request cannot target resource instance path: " + path.toString());
}
this.path = path;
}
/**
* {@inheritDoc}
*/
@Override
public LwM2mPath getPath() {
return this.path;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((path == null) ? 0 : path.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AbstractDownlinkRequest<?> other = (AbstractDownlinkRequest<?>) obj;
if (path == null) {
if (other.path != null)
return false;
} else if (!path.equals(other.path))
return false;
return true;
}
}