T
- the value typepublic abstract class Shared<T> extends Object
initialValue()
to prepare shared value.
Example:
// operator class
public abstract class SomeOperator {
// shared value container
static final Shared<Hoge> SHARED = new Shared<Hoge>() {
@Override protected Hoge initialValue() throws IOException {
// initializes shared value
Hoge result = ...;
return result;
}
}
// operator
@Update
public void some(Foo foo) {
// obtains shared value
Hoge hoge = SHARED.get();
...
}
}
Modifier and Type | Class and Description |
---|---|
static class |
Shared.InitializationException
Represents an exception occurred while
initializing shared values. |
Constructor and Description |
---|
Shared() |
Modifier and Type | Method and Description |
---|---|
T |
get()
Returns the shared value.
|
protected abstract T |
initialValue()
Returns the initial shared value.
|
boolean |
isInitialzed()
Returns whether this container is initialized or not.
|
void |
remove()
Discards the current shared value.
|
void |
set(T value)
Manually sets a shared value.
|
public final T get()
initialized
yet,
this will prepare an initial value and returns it.Shared.InitializationException
- if failed to initialize the shared valuepublic final void remove()
isInitialzed()
will return false
until
this container is re-initialized.
If this does not hold a shared value, this does nothing.public final void set(T value)
get()
method will return the value until remove()
is invoked.
This forcibly replaces the shared value even if this container is already initialized.value
- the shared valueisInitialzed()
public final boolean isInitialzed()
true
if this is initialized, or false
otherwiseprotected abstract T initialValue() throws IOException
IOException
- if initialization was failedCopyright © 2011–2019 Asakusa Framework Team. All rights reserved.