Class ExistingGenerator

java.lang.Object
com.comphenix.protocol.reflect.instances.ExistingGenerator
All Implemented Interfaces:
InstanceProvider

public class ExistingGenerator extends Object implements InstanceProvider
Provides instance constructors using a list of existing values.

Only one instance per individual class.

  • Method Details

    • fromObjectFields

      public static ExistingGenerator fromObjectFields(Object object)
      Automatically create an instance provider from a objects public and private fields.

      If two or more fields share the same type, the last declared non-null field will take precedent.

      Parameters:
      object - - object to create an instance generator from.
      Returns:
      The instance generator.
    • fromObjectFields

      public static ExistingGenerator fromObjectFields(Object object, Class<?> type)
      Automatically create an instance provider from a objects public and private fields.

      If two or more fields share the same type, the last declared non-null field will take precedent.

      Parameters:
      object - - object to create an instance generator from.
      type - - the type to cast the object.
      Returns:
      The instance generator.
    • fromObjectArray

      public static ExistingGenerator fromObjectArray(Object[] values)
      Create an instance generator from a pre-defined array of values.
      Parameters:
      values - - values to provide.
      Returns:
      An instance provider that uses these values.
    • create

      public Object create(@Nullable Class<?> type)
      Description copied from interface: InstanceProvider
      Create an instance given a type, if possible.
      Specified by:
      create in interface InstanceProvider
      Parameters:
      type - - type to create.
      Returns:
      The instance, or NULL if the type cannot be created.