Interface IdFactory

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface IdFactory
A factory for creating a new, unique Id for an object.
Author:
Fabrizio Giudici
Status: stable API
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Class<IdFactory>
     
    static final IdFactory
    A default implementation that uses UUID.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new id.
    default Id
    createId(Class<?> objectClass)
    Creates a new id for an object of the given class.
    default Id
    createId(Class<?> objectClass, Object object)
    Creates a new id for the given object of the given class.
    static IdFactory
    Creates a new mock factory, useful for testing, that returns mock UUIDs based on a sequential counter.
  • Field Details

    • _IdFactory_

      static final Class<IdFactory> _IdFactory_
    • DEFAULT

      static final IdFactory DEFAULT
      A default implementation that uses UUID.
      Since:
      3.2-ALPHA-19
  • Method Details

    • createMock

      @Nonnull static IdFactory createMock()
      Creates a new mock factory, useful for testing, that returns mock UUIDs based on a sequential counter.
      Returns:
      the new factory
      Since:
      3.2-ALPHA-23
    • createId

      @Nonnull Id createId()
      Creates a new id.
      Returns:
      the new id
    • createId

      @Nonnull default Id createId(@Nonnull Class<?> objectClass)
      Creates a new id for an object of the given class.
      Parameters:
      objectClass - the class of the object for which the Id is created
      Returns:
      the new id
    • createId

      @Nonnull default Id createId(@Nonnull Class<?> objectClass, @Nonnull Object object)
      Creates a new id for the given object of the given class. This method allows to explicitly pass a Class for cases in which the object implements multiple interfaces and one wants to specify the referenced one.
      Parameters:
      objectClass - the class of the object for which the Id is created
      object - the object for which the Id
      Returns:
      the new id