Skip to content

Commit 812ee6b

Browse files
committed
Add jSpecify user.datum.event.domain package.
1 parent 9c79159 commit 812ee6b

15 files changed

Lines changed: 220 additions & 158 deletions

File tree

solarnet/user-datum/src/main/java/net/solarnetwork/central/user/datum/event/domain/UserNodeEvent.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
package net.solarnetwork.central.user.datum.event.domain;
2424

25+
import static net.solarnetwork.util.ObjectUtils.requireNonNullArgument;
2526
import java.io.Serial;
2627
import java.time.Instant;
2728
import java.util.UUID;
29+
import org.jspecify.annotations.Nullable;
2830
import net.solarnetwork.central.user.dao.UserNodeRelatedEntity;
2931
import net.solarnetwork.dao.BasicUuidEntity;
3032

@@ -33,27 +35,38 @@
3335
* {@link UserNodeEventTask}.
3436
*
3537
* @author matt
36-
* @version 1.1
38+
* @version 1.2
3739
*/
3840
public class UserNodeEvent extends BasicUuidEntity implements UserNodeRelatedEntity<UUID> {
3941

4042
@Serial
4143
private static final long serialVersionUID = -7055529796513860954L;
4244

43-
private UserNodeEventHookConfiguration config;
44-
private UserNodeEventTask task;
45+
private @Nullable UserNodeEventHookConfiguration config;
46+
private @Nullable UserNodeEventTask task;
4547

48+
/**
49+
* Constructor.
50+
*
51+
* @param id
52+
* the ID
53+
* @param created
54+
* the creation date
55+
* @throws IllegalArgumentException
56+
* if any argument is {@code null}
57+
*/
4658
public UserNodeEvent(UUID id, Instant created) {
47-
super(id, created);
59+
super(requireNonNullArgument(id, "id"), requireNonNullArgument(created, "created"));
4860
}
4961

62+
@SuppressWarnings("NullAway")
5063
@Override
51-
public Long getUserId() {
64+
public @Nullable Long getUserId() {
5265
return (task != null ? task.getUserId() : null);
5366
}
5467

5568
@Override
56-
public Long getNodeId() {
69+
public @Nullable Long getNodeId() {
5770
return (task != null ? task.getNodeId() : null);
5871
}
5972

@@ -71,7 +84,7 @@ public String toString() {
7184
*
7285
* @return the config
7386
*/
74-
public UserNodeEventHookConfiguration getConfig() {
87+
public final @Nullable UserNodeEventHookConfiguration getConfig() {
7588
return config;
7689
}
7790

@@ -81,7 +94,7 @@ public UserNodeEventHookConfiguration getConfig() {
8194
* @param config
8295
* the config to set
8396
*/
84-
public void setConfig(UserNodeEventHookConfiguration config) {
97+
public final void setConfig(@Nullable UserNodeEventHookConfiguration config) {
8598
this.config = config;
8699
}
87100

@@ -90,7 +103,7 @@ public void setConfig(UserNodeEventHookConfiguration config) {
90103
*
91104
* @return the task
92105
*/
93-
public UserNodeEventTask getTask() {
106+
public final @Nullable UserNodeEventTask getTask() {
94107
return task;
95108
}
96109

@@ -100,7 +113,7 @@ public UserNodeEventTask getTask() {
100113
* @param task
101114
* the task to set
102115
*/
103-
public void setTask(UserNodeEventTask task) {
116+
public final void setTask(@Nullable UserNodeEventTask task) {
104117
this.task = task;
105118
}
106119

solarnet/user-datum/src/main/java/net/solarnetwork/central/user/datum/event/domain/UserNodeEventHookConfiguration.java

Lines changed: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
package net.solarnetwork.central.user.datum.event.domain;
2424

25+
import static net.solarnetwork.util.ObjectUtils.requireNonNullArgument;
2526
import java.io.Serial;
2627
import java.time.Instant;
2728
import java.util.Map;
29+
import org.jspecify.annotations.Nullable;
2830
import com.fasterxml.jackson.annotation.JsonGetter;
2931
import com.fasterxml.jackson.annotation.JsonIgnore;
3032
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -47,12 +49,12 @@ public class UserNodeEventHookConfiguration extends BasicEntity<UserLongPK>
4749
@Serial
4850
private static final long serialVersionUID = 3878313156603958081L;
4951

50-
private Long[] nodeIds;
51-
private String[] sourceIds;
52-
private String topic;
5352
private String name;
5453
private String serviceIdentifier;
55-
private Map<String, Object> serviceProps;
54+
private Long @Nullable [] nodeIds;
55+
private String @Nullable [] sourceIds;
56+
private @Nullable String topic;
57+
private @Nullable Map<String, Object> serviceProps;
5658

5759
/**
5860
* Constructor.
@@ -61,9 +63,18 @@ public class UserNodeEventHookConfiguration extends BasicEntity<UserLongPK>
6163
* the ID
6264
* @param created
6365
* the creation date
66+
* @param name
67+
* the configuration name
68+
* @param serviceIdentifier
69+
* the service identifier
70+
* @throws IllegalArgumentException
71+
* if any argument is {@code null}
6472
*/
65-
public UserNodeEventHookConfiguration(UserLongPK id, Instant created) {
66-
super(id, created);
73+
public UserNodeEventHookConfiguration(UserLongPK id, Instant created, String name,
74+
String serviceIdentifier) {
75+
super(requireNonNullArgument(id, "id"), requireNonNullArgument(created, "created"));
76+
this.name = requireNonNullArgument(name, "name");
77+
this.serviceIdentifier = requireNonNullArgument(serviceIdentifier, "serviceIdentifier");
6778
}
6879

6980
/**
@@ -73,9 +84,16 @@ public UserNodeEventHookConfiguration(UserLongPK id, Instant created) {
7384
* the user ID
7485
* @param created
7586
* the creation date
87+
* @param name
88+
* the configuration name
89+
* @param serviceIdentifier
90+
* the service identifier
91+
* @throws IllegalArgumentException
92+
* if any argument is {@code null}
7693
*/
77-
public UserNodeEventHookConfiguration(Long userId, Instant created) {
78-
this(null, userId, created);
94+
public UserNodeEventHookConfiguration(Long userId, Instant created, String name,
95+
String serviceIdentifier) {
96+
this(null, userId, created, name, serviceIdentifier);
7997
}
8098

8199
/**
@@ -87,9 +105,17 @@ public UserNodeEventHookConfiguration(Long userId, Instant created) {
87105
* the user ID
88106
* @param created
89107
* the creation date
108+
* @param name
109+
* the configuration name
110+
* @param serviceIdentifier
111+
* the service identifier
112+
* @throws IllegalArgumentException
113+
* if any argument except {@code id} is {@code null}
90114
*/
91-
public UserNodeEventHookConfiguration(Long id, Long userId, Instant created) {
92-
this(new UserLongPK(userId, id), created);
115+
public UserNodeEventHookConfiguration(@Nullable Long id, Long userId, Instant created, String name,
116+
String serviceIdentifier) {
117+
this(new UserLongPK(requireNonNullArgument(userId, "userId"), id), created, name,
118+
serviceIdentifier);
93119
}
94120

95121
/**
@@ -101,25 +127,22 @@ public UserNodeEventHookConfiguration(Long id, Long userId, Instant created) {
101127
*/
102128
public UserNodeEventHookConfiguration withUserId(Long userId) {
103129
UserNodeEventHookConfiguration copy = new UserNodeEventHookConfiguration(getConfigurationId(),
104-
userId, getCreated());
105-
copy.setName(name);
130+
userId, created(), name, serviceIdentifier);
106131
copy.setNodeIds(nodeIds);
107-
copy.setServiceIdentifier(serviceIdentifier);
108132
copy.setServiceProps(serviceProps);
109133
copy.setTopic(topic);
110134
return copy;
111135
}
112136

113137
@Override
114-
public boolean hasId() {
138+
public final boolean hasId() {
115139
UserLongPK id = getId();
116140
return (id != null && id.getId() != null && id.getUserId() != null);
117141
}
118142

119143
@Override
120-
public Long getUserId() {
121-
final UserLongPK id = getId();
122-
return id != null ? id.getUserId() : null;
144+
public final Long getUserId() {
145+
return id().getUserId();
123146
}
124147

125148
/**
@@ -129,17 +152,16 @@ public Long getUserId() {
129152
* @since 1.1
130153
*/
131154
@JsonGetter("id")
132-
public Long getConfigurationId() {
133-
final UserLongPK id = getId();
134-
return (id != null ? id.getId() : null);
155+
public final @Nullable Long getConfigurationId() {
156+
return id().getId();
135157
}
136158

137159
/**
138160
* Get the node IDs.
139161
*
140162
* @return the node IDs, or {@code null} for any node
141163
*/
142-
public Long[] getNodeIds() {
164+
public final Long @Nullable [] getNodeIds() {
143165
return nodeIds;
144166
}
145167

@@ -149,7 +171,7 @@ public Long[] getNodeIds() {
149171
* @param nodeIds
150172
* the node IDs to set
151173
*/
152-
public void setNodeIds(Long[] nodeIds) {
174+
public final void setNodeIds(Long @Nullable [] nodeIds) {
153175
this.nodeIds = nodeIds;
154176
}
155177

@@ -162,7 +184,7 @@ public void setNodeIds(Long[] nodeIds) {
162184
*
163185
* @return the source IDs
164186
*/
165-
public String[] getSourceIds() {
187+
public final String @Nullable [] getSourceIds() {
166188
return sourceIds;
167189
}
168190

@@ -172,7 +194,7 @@ public String[] getSourceIds() {
172194
* @param sourceIds
173195
* the source IDs or source ID Ant-style patterns to set
174196
*/
175-
public void setSourceIds(String[] sourceIds) {
197+
public final void setSourceIds(String @Nullable [] sourceIds) {
176198
this.sourceIds = sourceIds;
177199
}
178200

@@ -181,7 +203,7 @@ public void setSourceIds(String[] sourceIds) {
181203
*
182204
* @return the topic
183205
*/
184-
public String getTopic() {
206+
public final @Nullable String getTopic() {
185207
return topic;
186208
}
187209

@@ -191,12 +213,12 @@ public String getTopic() {
191213
* @param topic
192214
* the topic to set
193215
*/
194-
public void setTopic(String topic) {
216+
public final void setTopic(@Nullable String topic) {
195217
this.topic = topic;
196218
}
197219

198220
@Override
199-
public String getName() {
221+
public final String getName() {
200222
return name;
201223
}
202224

@@ -205,13 +227,15 @@ public String getName() {
205227
*
206228
* @param name
207229
* the name to use
230+
* @throws IllegalArgumentException
231+
* if any argument is {@code null}
208232
*/
209-
public void setName(String name) {
210-
this.name = name;
233+
public final void setName(String name) {
234+
this.name = requireNonNullArgument(name, "name");
211235
}
212236

213237
@Override
214-
public String getServiceIdentifier() {
238+
public final String getServiceIdentifier() {
215239
return serviceIdentifier;
216240
}
217241

@@ -221,24 +245,26 @@ public String getServiceIdentifier() {
221245
*
222246
* @param serviceIdentifier
223247
* the identifier of the service to use
248+
* @throws IllegalArgumentException
249+
* if any argument is {@code null}
224250
*/
225-
public void setServiceIdentifier(String serviceIdentifier) {
226-
this.serviceIdentifier = serviceIdentifier;
251+
public final void setServiceIdentifier(String serviceIdentifier) {
252+
this.serviceIdentifier = requireNonNullArgument(serviceIdentifier, "serviceIdentifier");
227253
}
228254

229255
@Override
230256
@JsonIgnore
231-
public Map<String, ?> getServiceProperties() {
257+
public final @Nullable Map<String, ?> getServiceProperties() {
232258
return getServiceProps();
233259
}
234260

235261
@JsonGetter("serviceProperties")
236-
public Map<String, Object> getServiceProps() {
262+
public final @Nullable Map<String, Object> getServiceProps() {
237263
return serviceProps;
238264
}
239265

240266
@JsonSetter("serviceProperties")
241-
public void setServiceProps(Map<String, Object> serviceProps) {
267+
public final void setServiceProps(@Nullable Map<String, Object> serviceProps) {
242268
this.serviceProps = serviceProps;
243269
}
244270

0 commit comments

Comments
 (0)