Class Accessor<T>

  • Type Parameters:
    T - the actual object type to access.
    All Implemented Interfaces:
    java.util.function.Supplier<T>
    Direct Known Subclasses:
    ControlAccessor, ItemAccessor, MenuAccessor

    public class Accessor<T>
    extends java.lang.Object
    implements java.util.function.Supplier<T>
    Base class for all kinds of accessor classes.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(@Nullable java.lang.Object obj)  
      T get()
      Gets the object instance wrapped by this accessor.
      static <T> T get​(@Nullable T object)
      Convenience function to access an object instance directly.
      java.util.Optional<T> getOptional()
      Gets the optional object instance wrapped by this accessor.
      int hashCode()  
      static <T> Accessor<T> notPresent()
      Gets the empty accessor.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Accessor

        public Accessor​(@Nullable T object)
        Constructs a new Accessor instance.
        Parameters:
        object - the object to access.
      • Accessor

        public Accessor​(java.util.Optional<T> objectHolder)
        Constructs a new Accessor instance.
        Parameters:
        objectHolder - to the optional object to access.
      • Accessor

        public Accessor​(Accessor<T> accessor)
        Constructs a new Accessor instance.
        Parameters:
        accessor - accessor to the object to access.
    • Method Detail

      • get

        public T get()
        Gets the object instance wrapped by this accessor.

        A test failure is signaled if the accessor is empty.

        Specified by:
        get in interface java.util.function.Supplier<T>
        Returns:
        the object instance wrapped by this accessor.
      • getOptional

        public java.util.Optional<T> getOptional()
        Gets the optional object instance wrapped by this accessor.
        Returns:
        the optional object instance wrapped by this accessor.
      • get

        public static <T> T get​(@Nullable T object)
        Convenience function to access an object instance directly.

        A test failure is signaled if the given object is null.

        Type Parameters:
        T - the object type to access.
        Parameters:
        object - the object instance to access (may be null).
        Returns:
        the object instance.
      • notPresent

        public static <T> Accessor<T> notPresent()
        Gets the empty accessor.
        Type Parameters:
        T - the actual object type to access.
        Returns:
        the empty accessor.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(@Nullable java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object