Class AttributeFactory

java.lang.Object
org.apache.lucene.util.AttributeFactory
Direct Known Subclasses:
AttributeFactory.DefaultAttributeFactory, AttributeFactory.StaticImplementationAttributeFactory

public abstract class AttributeFactory extends Object
An AttributeFactory creates instances of AttributeImpls.
  • Field Details

    • lookup

      private static final MethodHandles.Lookup lookup
    • NO_ARG_CTOR

      private static final MethodType NO_ARG_CTOR
    • NO_ARG_RETURNING_ATTRIBUTEIMPL

      private static final MethodType NO_ARG_RETURNING_ATTRIBUTEIMPL
    • DEFAULT_ATTRIBUTE_FACTORY

      public static final AttributeFactory DEFAULT_ATTRIBUTE_FACTORY
      This is the default factory that creates AttributeImpls using the class name of the supplied Attribute interface class by appending Impl to it.
  • Constructor Details

    • AttributeFactory

      public AttributeFactory()
  • Method Details

    • createAttributeInstance

      public abstract AttributeImpl createAttributeInstance(Class<? extends Attribute> attClass) throws UndeclaredThrowableException
      Returns an AttributeImpl for the supplied Attribute interface class.
      Throws:
      UndeclaredThrowableException - A wrapper runtime exception thrown if the constructor of the attribute class throws a checked exception. Note that attributes should not throw or declare checked exceptions; this may be verified and fail early in the future.
    • findAttributeImplCtor

      static final MethodHandle findAttributeImplCtor(Class<? extends AttributeImpl> clazz)
      Returns a correctly typed MethodHandle for the no-arg ctor of the given class.
    • getStaticImplementation

      public static <A extends AttributeImpl> AttributeFactory getStaticImplementation(AttributeFactory delegate, Class<A> clazz)
      Returns an AttributeFactory returning an instance of the given clazz for the attributes it implements. The given clazz must have a public no-arg constructor. For all other attributes it calls the given delegate factory as fallback. This method can be used to prefer a specific AttributeImpl which combines multiple attributes over separate classes.

      Please save instances created by this method in a static final field, because on each call, this does reflection for creating a MethodHandle.