Record Class ServiceType<O extends Service.Options,S extends Service<O>>

java.lang.Object
java.lang.Record
net.fabricmc.loom.util.service.ServiceType<O,S>
Record Components:
optionsClass - The options class for the service.
serviceClass - The service class.

public record ServiceType<O extends Service.Options,S extends Service<O>>(Class<O extends Service.Options> optionsClass, Class<S extends Service<O>> serviceClass) extends Record
A record to hold the options and service class for a service.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ServiceType(Class<O> optionsClass, Class<S> serviceClass)
    Creates an instance of a ServiceType record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.gradle.api.provider.Provider<O>
    create(org.gradle.api.Project project, org.gradle.api.Action<O> action)
    Create an instance of the options class for the given service class.
    static <O extends Service.Options>
    O
    createOptions(org.gradle.api.model.ObjectFactory objects, ServiceType<O,?> type, org.gradle.api.Action<O> action)
    创建一个只依赖 ObjectFactory 的选项实例.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    org.gradle.api.provider.Provider<O>
    maybeCreate(org.gradle.api.Project project, Function<O,Boolean> function)
    Maybe create an instance of the options class for the given service class.
    Returns the value of the optionsClass record component.
    Returns the value of the serviceClass record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

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

    • ServiceType

      public ServiceType(Class<O> optionsClass, Class<S> serviceClass)
      Creates an instance of a ServiceType record class.
      Parameters:
      optionsClass - the value for the optionsClass record component
      serviceClass - the value for the serviceClass record component
  • Method Details

    • create

      public org.gradle.api.provider.Provider<O> create(org.gradle.api.Project project, org.gradle.api.Action<O> action)
      Create an instance of the options class for the given service class.
      Parameters:
      project - The Project to create the options for.
      action - An action to configure the options.
      Returns:
      The created options provider.
    • maybeCreate

      public org.gradle.api.provider.Provider<O> maybeCreate(org.gradle.api.Project project, Function<O,Boolean> function)
      Maybe create an instance of the options class for the given service class.
      Parameters:
      project - The Project to create the options for.
      function - A function to configure the options, returning true if the options should be created.
      Returns:
      The created options provider.
    • createOptions

      public static <O extends Service.Options> O createOptions(org.gradle.api.model.ObjectFactory objects, ServiceType<O,?> type, org.gradle.api.Action<O> action)
      创建一个只依赖 ObjectFactory 的选项实例.

      与 create(Project, Action) 的唯一区别是不需要 Project,因此可以在执行期使用: 由任务注入的 ObjectFactory 实例化选项对象。选项里那些只能配置期取得的值(例如解析好的 依赖文件)由调用方先行解析成纯值,再在 action 里填进去。

      Type Parameters:
      O - 选项类型
      Parameters:
      objects - 执行期可用的对象工厂
      type - 选项与服务的类型
      action - 配置选项的动作
      Returns:
      创建好的选项实例
    • 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.
    • optionsClass

      public Class<O> optionsClass()
      Returns the value of the optionsClass record component.
      Returns:
      the value of the optionsClass record component
    • serviceClass

      public Class<S> serviceClass()
      Returns the value of the serviceClass record component.
      Returns:
      the value of the serviceClass record component