Class AbstractDependencyTracker<T,​D>

    • Constructor Detail

      • AbstractDependencyTracker

        protected AbstractDependencyTracker()
    • Method Detail

      • newTMap

        protected abstract IDependencyMap<T,​?> newTMap()
        Returns:
        A new map where the dependents (i.e., Y in "X -> Y") are the key
      • newTSet

        protected abstract Set<T> newTSet()
        Returns:
        A new set where the dependents (i.e., Y in "X -> Y") are the key
      • toStringT

        protected abstract String toStringT​(T t)
        Returns:
        A String representation of the dependent object
      • toStringD

        protected abstract String toStringD​(D d)
        Returns:
        A String representation of the dependee object
      • clear

        public void clear()
        Clear all internal state for the dependency tracker
      • isEmpty

        public boolean isEmpty()
        Returns:
        True if no dependencies have been defined
      • isSatisfied

        public boolean isSatisfied​(@NonNull
                                   D x)
        Returns:
        True if the dependency has been marked as satisfied using markSatisfied(Object, boolean)
      • markSatisfied

        public void markSatisfied​(@NonNull
                                  D x,
                                  boolean satisfied)
        Mark the specified value as satisfied. For example, if two dependencies have been previously added (X -> Y) and (X -> A) then after the markSatisfied(X, true) call, both of these dependencies are considered satisfied.
        Parameters:
        x - Value to mark
        satisfied - Whether to mark as satisfied (true) or unsatisfied (false)
      • getDependencies

        public DependencyList<T,​D> getDependencies​(@NonNull
                                                         T y)
        Get all dependencies x, for x -> y, and (x1 or x2) -> y
        Parameters:
        y - Dependent to get dependencies for
        Returns:
        List of dependencies
      • addDependency

        public void addDependency​(@NonNull
                                  T y,
                                  @NonNull
                                  D x)
        Add a dependency: y depends on x, as in x -> y
        Parameters:
        y - The dependent
        x - The dependee that is required for Y
      • checkAndUpdateIfAllSatisfied

        protected void checkAndUpdateIfAllSatisfied​(@NonNull
                                                    T y)
      • isAllSatisfied

        protected boolean isAllSatisfied​(@NonNull
                                         T y)
      • removeDependency

        public void removeDependency​(@NonNull
                                     T y,
                                     @NonNull
                                     D x)
        Remove a dependency (x -> y)
        Parameters:
        y - The dependent that currently requires X
        x - The dependee that is no longer required for Y
      • addOrDependency

        public void addOrDependency​(@NonNull
                                    T y,
                                    @NonNull
                                    D x1,
                                    @NonNull
                                    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
        Parameters:
        y - Dependent
        x1 - Dependee 1
        x2 - Dependee 2
      • hasNewAllSatisfied

        public boolean hasNewAllSatisfied()
        Returns:
        True if there are any new/unprocessed "all satisfied dependents" (Ys in X->Y)
      • getNewAllSatisfied

        public 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.
        Returns:
        The next new "all satisfied dependent"
      • getNewAllSatisfiedList

        public List<T> getNewAllSatisfiedList()
        Returns:
        As per getNewAllSatisfied() but returns all values
      • getFirstNewAllSatisfiedMatching

        public T getFirstNewAllSatisfiedMatching​(@NonNull
                                                 @NonNull Predicate<T> predicate)
        As per 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 returned
        Parameters:
        predicate - Predicate gor checking
        Returns:
        The first value matching the predicate, or null if no values match the predicate