Interface PointersSupplier<T>

  • Type Parameters:
    T - the type

    public interface PointersSupplier<T>
    A supplier of Pointers that allows for the implementation of pointers in a static context without having to manually create a new pointers instance for each instance of a given type.

    An example of how this could be implemented is as follows:

     public class MyPointeredObject extends SomePointeredParent implements Pointered {
       private static final PointersSupplier<MyPointeredObject> POINTERS = PointersSupplier.builder()
         .parent(SomePointeredParent.POINTERS) // Fallback to the parent to get pointers from.
         .resolving(Identity.UUID, MyPointeredObject::getUniqueId)
         .resolving(Identity.DISPLAY_NAME, MyPointeredObject::getDisplayName)
         .build();
    
       @Override
       public Pointers pointers() {
         return POINTERS.view(this);
       }
     }
     
    Since:
    4.17.0
    • Method Detail

      • builder

        @NotNull
        static <T> @NotNull PointersSupplier.Builder<T> builder()
        Gets a new pointers supplier builder.
        Type Parameters:
        T - the type
        Returns:
        the builder
        Since:
        4.17.0
      • view

        @NotNull
        @NotNull Pointers view​(@NotNull
                               T instance)
        Creates a pointers view for the given instance.
        Parameters:
        instance - the instance
        Returns:
        the view
        Since:
        4.17.0
      • supports

        <P> boolean supports​(@NotNull
                             @NotNull Pointer<P> pointer)
        Checks if this supplier supports a given pointer.
        Type Parameters:
        P - the type of the pointer
        Parameters:
        pointer - the pointer
        Returns:
        if this supplier supports a given pointer
        Since:
        4.17.0
      • resolver

        @Nullable
        <P> @Nullable java.util.function.Function<? super T,​P> resolver​(@NotNull
                                                                              @NotNull Pointer<P> pointer)
        Returns the resolver for a given pointer (if any).
        Type Parameters:
        P - the type of the pointer
        Parameters:
        pointer - the pointer
        Returns:
        the resolver, if any
        Since:
        4.17.0