-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
core/src/main/java/com/github/cowwoc/pouch/core/AbstractScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.github.cowwoc.pouch.core; | ||
|
||
/** | ||
* The default implementation of {@link Scope}. | ||
*/ | ||
public abstract class AbstractScope implements Scope | ||
{ | ||
/** | ||
* The child scopes. | ||
*/ | ||
protected final ConcurrentChildScopes children = new ConcurrentChildScopes(); | ||
|
||
/** | ||
* Creates new scope. | ||
*/ | ||
protected AbstractScope() | ||
{ | ||
} | ||
|
||
@Override | ||
public void addChild(Scope child) | ||
{ | ||
ensureOpen(); | ||
children.add(child); | ||
} | ||
|
||
@Override | ||
public void removeChild(Scope child) | ||
{ | ||
ensureOpen(); | ||
children.remove(child); | ||
} | ||
|
||
/** | ||
* Ensures that the scope is open. | ||
* | ||
* @throws IllegalStateException if the scope is closed | ||
*/ | ||
protected void ensureOpen() | ||
{ | ||
if (isClosed()) | ||
throw new IllegalStateException("Scope is closed"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters