The usage pattern for code accessing the trackable data is as follows:
StateTrackable trackedobject;
MyInfo cacheddata;
StateTracker cachetracker;
public synchronized MyInfo getInfoAbout(StateTrackable obj) {
if (trackedobject != obj || !cachetracker.isCurrent()) {
// Note: Always call getStateTracker() before
// caching any data about the objct...
cachetracker = obj.getStateTracker();
cacheddata = calculateInfoFrom(obj);
trackedobject = obj;
}
return cacheddata;
}
Note that the sample code above works correctly regardless of the
State of the complex data of the object,
but it may be inefficient to store precalculated information about
an object whose current State is
UNTRACKABLE
and it is unnecessary to perform the isCurrent test for
data whose current State is
IMMUTABLE.
Optimizations to the sample code for either or both of those terminal
States may be of benefit for some use cases, but is left out of the
example to reduce its complexity.
StateTrackable.State
| Modifier and Type | Field and Description |
|---|---|
| public static final StateTracker | ALWAYS_CURRENT
An implementation of the StateTracker interface which always returns true. |
| public static final StateTracker | NEVER_CURRENT
An implementation of the StateTracker interface which always returns false. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | isCurrent()
Returns true iff the contents of the complex data of the associated StateTrackable object have not changed since the time that this StateTracker was returned from its getStateTracker() method. |
| ALWAYS_CURRENT | back to summary |
|---|---|
| public static final StateTracker ALWAYS_CURRENT An implementation of the StateTracker interface which
always returns true.
This implementation is useful for objects whose current
| |
| NEVER_CURRENT | back to summary |
|---|---|
| public static final StateTracker NEVER_CURRENT An implementation of the StateTracker interface which
always returns false.
This implementation is useful for objects whose current
| |
| isCurrent | back to summary |
|---|---|
| public boolean isCurrent() Returns true iff the contents of the complex data of the associated StateTrackable object have not changed since the time that this StateTracker was returned from its getStateTracker() method.
| |