Record Class EntityRegistryEntry

java.lang.Object
java.lang.Record
fr.olympus.prometheus.register.EntityRegistryEntry
Record Components:
id - The unique identifier for the entity.
supplier - A supplier that provides instances of the entity when requested.
groups - An array of group identifiers that this entity belongs to, used for categorization and retrieval purposes.

public record EntityRegistryEntry(String id, Supplier<? extends IEntity> supplier, String[] groups) extends Record
Represents an entry in the entity registry, containing the entity's unique identifier and a supplier for creating instances of the entity.
  • Constructor Details

    • EntityRegistryEntry

      public EntityRegistryEntry(String id, Supplier<? extends IEntity> supplier, String[] groups)
      Constructs a new EntityRegistryEntry with the specified unique identifier and supplier.
      Parameters:
      id - The unique identifier for the entity.
      supplier - A supplier that provides instances of the entity when requested.
      Throws:
      IllegalArgumentException - if id is null or if supplier is null.
  • Method Details

    • createInstance

      public IEntity createInstance()
      Creates a new instance of the entity using the supplier.
      Returns:
      A new instance of the entity provided by the supplier.
      Throws:
      RuntimeException - if the supplier fails to create an instance.
      IllegalStateException - if the created instance is null or not an instance of IEntity
    • hasGroup

      public boolean hasGroup(String group)
      Checks if the entity belongs to a specific group.
      Parameters:
      group - The group identifier to check against the entity's groups.
      Returns:
      true if the entity belongs to the specified group, false otherwise.
    • hasGroups

      public boolean hasGroups(String... groups)
      Checks if the entity belongs to all specified groups.
      Parameters:
      groups - An array of group identifiers to check against the entity's groups.
      Returns:
      true if the entity belongs to all specified groups, false otherwise.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • supplier

      public Supplier<? extends IEntity> supplier()
      Returns the value of the supplier record component.
      Returns:
      the value of the supplier record component
    • groups

      public String[] groups()
      Returns the value of the groups record component.
      Returns:
      the value of the groups record component