Skip to content

Commit e5ccfbf

Browse files
Encapsulate checking context
1 parent cda2650 commit e5ccfbf

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

server/src/main/java/io/spine/server/entity/Repository.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public final TypeUrl entityStateType() {
203203
public void registerWith(BoundedContext context) {
204204
checkNotNull(context);
205205
boolean sameValue = context.equals(this.context);
206-
if (this.context != null && !sameValue) {
206+
if (hasContext() && !sameValue) {
207207
throw newIllegalStateException(
208208
"The repository `%s` has the Bounded Context (`%s`) assigned." +
209209
" This operation can be performed only once." +
@@ -222,14 +222,11 @@ public void registerWith(BoundedContext context) {
222222
}
223223

224224
/**
225-
* {@inheritDoc}
226-
*
227-
* <p>Unlike, {@link #isOpen()}, once the repository is
228-
* {@linkplain #registerWith(BoundedContext) initialized}, this method always returns {@code true}.
225+
* Tells if the repository is registered in a {@code BoundedContext}.
229226
*/
230227
@Override
231228
public boolean isRegistered() {
232-
return context != null;
229+
return hasContext();
233230
}
234231

235232
/**
@@ -262,7 +259,7 @@ protected final boolean hasContext() {
262259
* if the repository has no context assigned
263260
*/
264261
protected final BoundedContext context() {
265-
checkState(context != null,
262+
checkState(hasContext(),
266263
"The repository (class: `%s`) is not registered with a `BoundedContext`.",
267264
getClass().getName());
268265
return context;
@@ -364,7 +361,7 @@ public void close() {
364361
*/
365362
@Override
366363
public final boolean isOpen() {
367-
return context != null;
364+
return hasContext();
368365
}
369366

370367
@Internal

0 commit comments

Comments
 (0)