Record Class PropertyProvider<T>
- Record Components:
type- thePropertyfor which thisPropertyProvidercreates values.priority- the priority of this providerreferenceClass- The Class to which thisPropertyProvider'belongs'. It's only used for logging purposes. For example, all fallback/default values haveJDACBuilderas their reference class.supplier- theFunctionreturning the properties value, provides access toPropertyProvider.Context
- All Implemented Interfaces:
Comparable<PropertyProvider<T>>
PropertyProviders
An PropertyProvider provides values for the Property associated with it.
Dependencies
Because many properties especially services depend on other properties, you can get the values
of these properties through the PropertyProvider.Context.get(Property) that is available in the supplier().
If somehow recursive calls to the same Property are created (called cycling dependencies),
then a ConfigurationException is thrown providing information on how this recursion occurs.
Priorities
To decide which value is taken at the end for a property, each PropertyProvider defines a priority between
0 and Integer.MAX_VALUE.
The provider with the highest priority will be taken, thus its value is set for the property.
It's important to note that the priorities 0 to 100 and Integer.MAX_VALUE are reserved by JDA-Commands:
- priority = 0 are all fallback/default value provided by JDA-Commands
- priority =
Integer.MAX_VALUEare all values set by the user manually inJDACBuilder
Usage of reserved priorities will result in an exception causing JDA-Commands to stop itself.
Example
An example usage of this class would be:
class Foo {
public bar(...) {
var provider = new PropertyProvider(
Type.INTERACTION_CONTROLLER_INSTANTIATOR,
2000, // just some random priority
Foo.class, // used as a waypoint for debugging
ctx -> new MyInteractionControllerInstantiator(ctx.get(Property.I18N)) // needs the I18n instance
)
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis context provides useful functionality to aPropertyProviderduring value creation. -
Constructor Summary
ConstructorsConstructorDescriptionPropertyProvider(Property<T> type, int priority, Class<?> referenceClass, Function<PropertyProvider.Context, @Nullable T> supplier) Creates an instance of aPropertyProviderrecord class. -
Method Summary
Modifier and TypeMethodDescriptionintCompares twoPropertyProviderby theirpriority()in reverse order.static <T> PropertyProvider<T> create(Property<T> type, int priority, Function<PropertyProvider.Context, @Nullable T> supplier) Creates a newPropertyProviderwhere itsreferenceClass()is the caller of this method.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intpriority()Returns the value of thepriorityrecord component.Class<?> Returns the value of thereferenceClassrecord component.Function<PropertyProvider.Context, @Nullable T> supplier()Returns the value of thesupplierrecord component.final StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.
-
Constructor Details
-
PropertyProvider
public PropertyProvider(Property<T> type, int priority, Class<?> referenceClass, Function<PropertyProvider.Context, @Nullable T> supplier) Creates an instance of aPropertyProviderrecord class.- Parameters:
type- the value for thetyperecord componentpriority- the value for thepriorityrecord componentreferenceClass- the value for thereferenceClassrecord componentsupplier- the value for thesupplierrecord component
-
-
Method Details
-
create
public static <T> PropertyProvider<T> create(Property<T> type, int priority, Function<PropertyProvider.Context, @Nullable T> supplier) Creates a newPropertyProviderwhere itsreferenceClass()is the caller of this method.- Parameters:
type- thePropertyfor which thisPropertyProvidercreates valuespriority- the priority of this providersupplier- theFunctionreturning the properties value, provides access toPropertyProvider.Context- Returns:
- the
PropertyProviderinstance - See Also:
-
compareTo
Compares twoPropertyProviderby theirpriority()in reverse order. ThePropertyProviderwith the higher priority comes first.- Specified by:
compareToin interfaceComparable<T>- Returns:
-
toString
-
hashCode
-
equals
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
type
-
priority
-
referenceClass
Returns the value of thereferenceClassrecord component.- Returns:
- the value of the
referenceClassrecord component
-
supplier
-