Class Lazy<T>

  • Type Parameters:
    T -
    All Implemented Interfaces:
    LazyReferencing<T>, Referencing<T>

    public final class Lazy<T>
    extends Object
    implements LazyReferencing<T>
    A reference providing generic lazy-loading functionality.

    Note that the shortened name has been chosen intentionally to optimize readability in class design.

    Also note that a type like this is strongly required to implement lazy loading behavior in an architectural clean and proper way. I.e. the design has to define that a certain reference is meant be capable of lazy-loading. If such a definition is not done, a loading logic is strictly required to always load the encountered reference, as it is defined by the normal reference. Any "tricks" of whatever framework to "sneak in" lazy loading behavior where it hasn't actually been defined are nothing more than dirty hacks and mess up if not destroy the program's consistency of state (e.g. antipatterns like secretly replacing a well-defined collection instance with a framework-proprietary proxy instance of a "similar" collection implementation). In proper architectured sofware, if a reference does not define lazy loading capacity, it is not wanted to have that capacity on the business logical level by design in the first place. Any attempts of saying "but I want it anyway in a sneaky 'transparent' way" indicate ambivalent conflicting design errors and thus in the end poor design.

    • Constructor Detail

      • Lazy

        public Lazy()
    • Method Detail

      • genericType

        public static final Class<Lazy<?>> genericType()
      • get

        public static final <T> T get​(Lazy<T> reference)
      • peek

        public static final <T> T peek​(Lazy<T> reference)
      • clear

        public static final void clear​(Lazy<?> reference)
      • isStored

        public static final boolean isStored​(Lazy<?> reference)
      • Reference

        public static final <T> Lazy<T> Reference​(T subject)
      • New

        public static final <T> Lazy<T> New​(long objectId)
      • Checker

        public static final Lazy.Checker Checker​(long millisecondTimeout)
      • objectId

        public final long objectId()
      • lastTouched

        public final long lastTouched()
      • isStored

        public final boolean isStored()
      • peek

        public final T peek()
        Returns the wrapped reference in its current state without loading it on demand.
        Specified by:
        peek in interface LazyReferencing<T>
        Returns:
        the current reference withouth on-demand loading.
      • clear

        public final T clear()
        Clears the reference, leaving the option to re-load it again intact, and returns the subject that was referenced prior to clearing.
        Returns:
        the subject referenced prior to clearing the reference.
      • get

        public final T get()
        Returns the original subject referenced by this reference instance. If the subject has (lazily) not been loaded, an attempt to do so now is made. Any exception occuring during the loading attempt will be passed along without currupting this reference instance's internal state.
        Specified by:
        get in interface LazyReferencing<T>
        Specified by:
        get in interface Referencing<T>
        Returns:
        the originally referenced subject, either already-known or lazy-loaded.