T
- For a dependency X -> Y, Y has type TD
- For a dependency X -> Y, X has type Dpublic abstract class AbstractDependencyTracker<T,D> extends Object
hasNewAllSatisfied()
, getNewAllSatisfied()
and getNewAllSatisfiedList()
Modifier | Constructor and Description |
---|---|
protected |
AbstractDependencyTracker() |
Modifier and Type | Method and Description |
---|---|
void |
addDependency(T y,
D x)
Add a dependency: y depends on x, as in x -> y
|
void |
addOrDependency(T y,
D x1,
D x2)
Add an "Or" dependency: Y requires either x1 OR x2 - i.e., (x1 or x2) -> Y
If either x1 or x2 (or both) are marked satisfied via markSatisfied(Object, boolean) then the
dependency is considered satisfied |
protected void |
checkAndUpdateIfAllSatisfied(T y) |
void |
clear()
Clear all internal state for the dependency tracker
|
DependencyList<T,D> |
getDependencies(T y)
Get all dependencies x, for x -> y, and (x1 or x2) -> y
|
T |
getFirstNewAllSatisfiedMatching(@NonNull Predicate<T> predicate)
As per
getNewAllSatisfied() but instead of returning the first dependee, it returns the first that matches
the provided predicate. |
T |
getNewAllSatisfied()
Returns the next new dependent (Y in X->Y) that has all dependees (Xs) marked as satisfied via
markSatisfied(Object, boolean)
Throws an exception if hasNewAllSatisfied() returns false.Note that once a value has been retrieved from here, no new dependencies of the form (X -> Y) can be added for this value; the value is considered "processed" at this point. |
List<T> |
getNewAllSatisfiedList() |
boolean |
hasDependency(T y)
Check whether any dependencies x -> y exist, for y (i.e., anything previously added by
addDependency(Object, Object)
or addOrDependency(Object, Object, Object) |
boolean |
hasNewAllSatisfied() |
protected boolean |
isAllSatisfied(T y) |
boolean |
isEmpty() |
boolean |
isSatisfied(D x) |
void |
markSatisfied(D x,
boolean satisfied)
Mark the specified value as satisfied.
|
protected abstract Map<T,?> |
newTMap() |
protected abstract Set<T> |
newTSet() |
void |
removeDependency(T y,
D x)
Remove a dependency (x -> y)
|
protected abstract String |
toStringD(D d) |
protected abstract String |
toStringT(T t) |
protected abstract Map<T,?> newTMap()
protected abstract Set<T> newTSet()
protected abstract String toStringT(T t)
protected abstract String toStringD(D d)
public void clear()
public boolean isEmpty()
public boolean isSatisfied(@NonNull D x)
markSatisfied(Object, boolean)
public void markSatisfied(@NonNull D x, boolean satisfied)
x
- Value to marksatisfied
- Whether to mark as satisfied (true) or unsatisfied (false)public boolean hasDependency(@NonNull T y)
addDependency(Object, Object)
or addOrDependency(Object, Object, Object)
y
- Dependent to checkpublic DependencyList<T,D> getDependencies(@NonNull T y)
y
- Dependent to get dependencies forpublic void addDependency(@NonNull T y, @NonNull D x)
y
- The dependentx
- The dependee that is required for Yprotected void checkAndUpdateIfAllSatisfied(@NonNull T y)
protected boolean isAllSatisfied(@NonNull T y)
public void removeDependency(@NonNull T y, @NonNull D x)
y
- The dependent that currently requires Xx
- The dependee that is no longer required for Ypublic void addOrDependency(@NonNull T y, @NonNull D x1, @NonNull D x2)
markSatisfied(Object, boolean)
then the
dependency is considered satisfiedy
- Dependentx1
- Dependee 1x2
- Dependee 2public boolean hasNewAllSatisfied()
public T getNewAllSatisfied()
markSatisfied(Object, boolean)
Throws an exception if hasNewAllSatisfied()
returns false.public List<T> getNewAllSatisfiedList()
getNewAllSatisfied()
but returns all valuespublic T getFirstNewAllSatisfiedMatching(@NonNull @NonNull Predicate<T> predicate)
getNewAllSatisfied()
but instead of returning the first dependee, it returns the first that matches
the provided predicate. If no value matches the predicate, null is returnedpredicate
- Predicate gor checkingCopyright © 2020. All rights reserved.