类 TodayStrategies
General purpose strategy loading mechanism for internal use within the framework.
Reads a META-INF/today-strategies.properties file from the root of the library classpath,
and also allows for programmatically setting properties through setProperty(java.lang.String, java.lang.String).
When checking a property, local entries are being checked first, then falling back
to JVM-level system properties through a System.getProperty(java.lang.String) check.
Get keyed strategies
- 从以下版本开始:
- 4.0
- 作者:
- TODAY 2021/9/5 13:57
-
嵌套类概要
嵌套类修饰符和类型类说明static interfaceStrategy for resolving constructor arguments based on their type.static interfaceStrategy for handling a failure that occurs when instantiating a strategy.static interfaceStrategy for instantiate strategy. -
字段概要
字段 -
构造器概要
构造器限定符构造器说明protectedTodayStrategies(ClassLoader classLoader, Map<String, List<String>> strategies) Create a newTodayStrategiesinstance. -
方法概要
修饰符和类型方法说明static <T> List<T>get none repeatable strategies by given classstatic <T> List<T>find(Class<T> strategyType, TodayStrategies.Instantiator instantiator) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.static <T> List<T>find(Class<T> strategyType, ClassLoader classLoader) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.static <T> List<T>find(Class<T> strategyType, ClassLoader classLoader, TodayStrategies.Instantiator instantiator) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.Load the fully qualified class names of strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.findNames(Class<?> strategyType, ClassLoader classLoader) Load the fully qualified class names of strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.Load the fully qualified class names of strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.findNames(String strategyKey, ClassLoader classLoader) Load the fully qualified class names of strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.static TodayStrategiesCreate aTodayStrategiesinstance that will load and instantiate the strategy implementations from "META-INF/today-strategies.properties", using the default class loader.static TodayStrategiesforDefaultResourceLocation(ClassLoader classLoader) Create aTodayStrategiesinstance that will load and instantiate the strategy implementations from "META-INF/today-strategies.properties", using the given class loader.static TodayStrategiesforLocation(String resourceLocation) Create aTodayStrategiesinstance that will load and instantiate the strategy implementations from the given location, using the default class loader.static TodayStrategiesforLocation(String resourceLocation, ClassLoader classLoader) Create aTodayStrategiesinstance that will load and instantiate the strategy implementations from the given location, using the given class loader.static <T> Tget first strategystatic Stringget first strategystatic booleanRetrieve the flag for the given property key.static booleanRetrieve the flag for the given property key.static intDetermines the integer value of the system property with the specified name.static IntegergetInteger(String key) Determines the integer value of the property with the specified name.static IntegergetInteger(String key, Integer val) Returns the integer value of the property with the specified name.static LongDetermines thelongvalue of the system property with the specified name.static LongDetermines thelongvalue of the system property with the specified name.static LongReturns thelongvalue of the system property with the specified name.static StringgetProperty(String key) Retrieve the property value for the given key, checking local properties first and falling back to JVM-level system properties.static StringgetProperty(String key, String def) Retrieve the property value for the given key, checking local properties first and falling back to JVM-level system properties.protected <T> TinstantiateStrategy(String implementationName, Class<T> type, TodayStrategies.Instantiator instantiator, TodayStrategies.FailureHandler failureHandler) <T> List<T>Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader and a default argument resolver that expects a no-arg constructor.<T> List<T>load(Class<T> strategyType, TodayStrategies.ArgumentResolver argumentResolver) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader and the given argument resolver.<T> List<T>load(Class<T> strategyType, TodayStrategies.ArgumentResolver argumentResolver, TodayStrategies.FailureHandler failureHandler) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader, the given argument resolver, and custom failure handling provided by the given failure handler.<T> List<T>load(Class<T> strategyType, TodayStrategies.FailureHandler failureHandler) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader with custom failure handling provided by the given failure handler.<T> List<T>load(Class<T> strategyType, TodayStrategies.Instantiator instantiator) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader and the given argument resolver.<T> List<T>load(Class<T> strategyType, TodayStrategies.Instantiator instantiator, TodayStrategies.FailureHandler failureHandler) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader, the given argument resolver, and custom failure handling provided by the given failure handler.loadResource(ClassLoader classLoader, String resourceLocation) static voidreadStrategies(MultiValueMap<String, String> strategies, String strategyKey, String value) static voidreadStrategies(MultiValueMap<String, String> strategies, Properties properties) static voidProgrammatically set a local flag to "true", overriding an entry in thePROPERTIES_RESOURCE_LOCATIONfile (if any).static voidsetProperty(String key, String value) Programmatically set a local property, overriding an entry in thePROPERTIES_RESOURCE_LOCATIONfile (if any).
-
字段详细资料
-
STRATEGIES_LOCATION
- 另请参阅:
-
-
构造器详细资料
-
TodayStrategies
Create a newTodayStrategiesinstance.- 参数:
classLoader- the classloader used to instantiate the factoriesstrategies- a map of strategy class name to implementation class names
-
-
方法详细资料
-
getFlag
Retrieve the flag for the given property key.- 参数:
key- the property key- 返回:
trueif the property is set to "true", false otherwise
-
getFlag
Retrieve the flag for the given property key.If there isn't a key returns defaultFlag
- 参数:
key- the property key- 返回:
trueif the property is set to "true", false otherwise ,If there isn't a key returns defaultFlag
-
setFlag
Programmatically set a local flag to "true", overriding an entry in thePROPERTIES_RESOURCE_LOCATIONfile (if any).- 参数:
key- the property key
-
setProperty
Programmatically set a local property, overriding an entry in thePROPERTIES_RESOURCE_LOCATIONfile (if any).- 参数:
key- the property keyvalue- the associated property value, ornullto reset it
-
getProperty
Retrieve the property value for the given key, checking local properties first and falling back to JVM-level system properties.- 参数:
key- the property key- 返回:
- the associated property value, or
nullif none found
-
getProperty
Retrieve the property value for the given key, checking local properties first and falling back to JVM-level system properties.- 参数:
key- the name of the system property.def- a default value.- 返回:
- the string value of the system property, or the default value if there is no property with that key.
- 另请参阅:
-
getInteger
Determines the integer value of the property with the specified name.The first argument is treated as the name of a today.properties or system property. properties are accessible through the
getProperty(java.lang.String)method. The string value of this property is then interpreted as an integer value using the grammar supported bydecodeand anIntegerobject representing this value is returned.If there is no property with the specified name, if the specified name is empty or
null, or if the property does not have the correct numeric format, thennullis returned.In other words, this method returns an
Integerobject equal to the value of:getInteger(nm, null)- 参数:
key- property name.- 返回:
- the
Integervalue of the property. - 抛出:
SecurityException- for the same reasons asSystem.getProperty- 另请参阅:
-
getInt
Determines the integer value of the system property with the specified name.The first argument is treated as the name of a today.properties or system property. properties are accessible through the
getProperty(java.lang.String)method. The string value of this property is then interpreted as an integer value using the grammar supported bydecodeand anIntegerobject representing this value is returned.The second argument is the default value. An
Integerobject that represents the value of the second argument is returned if there is no property of the specified name, if the property does not have the correct numeric format, or if the specified name is empty ornull.In other words, this method returns an
Integerobject equal to the value of:
but in practice it may be implemented in a manner such as:getInteger(nm, new Integer(val))
to avoid the unnecessary allocation of anInteger result = getInteger(nm, null); return (result == null) ? new Integer(val) : result;
Integerobject when the default value is not needed.- 参数:
key- property name.val- default value.- 返回:
- the
Integervalue of the property. - 抛出:
SecurityException- for the same reasons asSystem.getProperty- 另请参阅:
-
getInteger
Returns the integer value of the property with the specified name.The first argument is treated as the name of a today.properties or system property. properties are accessible through the
getProperty(java.lang.String)method. The string value of this property is then interpreted as an integer value using the grammar supported bydecodeand anIntegerobject representing this value is returned. in summary:- If the property value begins with the two ASCII characters
0xor the ASCII character#, not followed by a minus sign, then the rest of it is parsed as a hexadecimal integer exactly as by the methodInteger.valueOf(java.lang.String, int)with radix 16. - If the property value begins with the ASCII character
0followed by another character, it is parsed as an octal integer exactly as by the methodInteger.valueOf(java.lang.String, int)with radix 8. - Otherwise, the property value is parsed as a decimal integer
exactly as by the method
Integer.valueOf(java.lang.String, int)with radix 10.
The second argument is the default value. The default value is returned if there is no property of the specified name, if the property does not have the correct numeric format, or if the specified name is empty or
null.- 参数:
key- property name.val- default value.- 返回:
- the
Integervalue of the property.System.getProperty - 另请参阅:
- If the property value begins with the two ASCII characters
-
getLong
Determines thelongvalue of the system property with the specified name.The first argument is treated as the name of a today.properties or system property. properties are accessible through the
getProperty(java.lang.String)method. The string value of this property is then interpreted as an integer value using the grammar supported bydecodeand anIntegerobject representing this value is returned.If there is no property with the specified name, if the specified name is empty or
null, or if the property does not have the correct numeric format, thennullis returned.In other words, this method returns a
Longobject equal to the value of:getLong(nm, null)- 参数:
nm- property name.- 返回:
- the
Longvalue of the property. - 抛出:
SecurityException- for the same reasons asSystem.getProperty- 另请参阅:
-
getLong
Determines thelongvalue of the system property with the specified name.The first argument is treated as the name of a today.properties or system property. properties are accessible through the
getProperty(java.lang.String)method. The string value of this property is then interpreted as an integer value using the grammar supported bydecodeand anIntegerobject representing this value is returned.The second argument is the default value. A
Longobject that represents the value of the second argument is returned if there is no property of the specified name, if the property does not have the correct numeric format, or if the specified name is empty or null.In other words, this method returns a
Longobject equal to the value of:
but in practice it may be implemented in a manner such as:getLong(nm, new Long(val))
to avoid the unnecessary allocation of aLong result = getLong(nm, null); return (result == null) ? new Long(val) : result;
Longobject when the default value is not needed.- 参数:
nm- property name.val- default value.- 返回:
- the
Longvalue of the property. - 抛出:
SecurityException- for the same reasons asSystem.getProperty- 另请参阅:
-
getLong
Returns thelongvalue of the system property with the specified name.The first argument is treated as the name of a today.properties or system property. properties are accessible through the
getProperty(java.lang.String)method. The string value of this property is then interpreted as an integer value using the grammar supported bydecodeand anIntegerobject representing this value is returned. in summary:- If the property value begins with the two ASCII characters
0xor the ASCII character#, not followed by a minus sign, then the rest of it is parsed as a hexadecimal integer exactly as for the methodLong.valueOf(java.lang.String, int)with radix 16. - If the property value begins with the ASCII character
0followed by another character, it is parsed as an octal integer exactly as by the methodLong.valueOf(java.lang.String, int)with radix 8. - Otherwise the property value is parsed as a decimal
integer exactly as by the method
Long.valueOf(java.lang.String, int)with radix 10.
Note that, in every case, neither
L('\u004C') norl('\u006C') is permitted to appear at the end of the property value as a type indicator, as would be permitted in Java programming language source code.The second argument is the default value. The default value is returned if there is no property of the specified name, if the property does not have the correct numeric format, or if the specified name is empty or
null.- 参数:
nm- property name.val- default value.- 返回:
- the
Longvalue of the property. - 抛出:
SecurityException- for the same reasons asSystem.getProperty- 另请参阅:
- If the property value begins with the two ASCII characters
-
readStrategies
public static void readStrategies(MultiValueMap<String, String> strategies, String strategyKey, String value) -
readStrategies
- 参数:
strategies- outputproperties- input
-
load
Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader and a default argument resolver that expects a no-arg constructor.The returned factories are sorted through
AnnotationAwareOrderComparator.If a custom instantiation strategy is required, use
load(...)with a customArgumentResolverand/orFailureHandler.if duplicate implementation class names are discovered for a given strategy type, only one instance of the duplicated implementation type will be instantiated.
- 参数:
strategyType- the interface or abstract class representing the strategy- 抛出:
IllegalArgumentException- if any strategy implementation class cannot be loaded or if an error occurs while instantiating any strategy
-
load
public <T> List<T> load(Class<T> strategyType, @Nullable TodayStrategies.ArgumentResolver argumentResolver) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader and the given argument resolver.The returned factories are sorted through
AnnotationAwareOrderComparator.If duplicate implementation class names are discovered for a given strategy type, only one instance of the duplicated implementation type will be instantiated.
- 参数:
strategyType- the interface or abstract class representing the strategyargumentResolver- strategy used to resolve constructor arguments by their type- 抛出:
IllegalArgumentException- if any strategy implementation class cannot be loaded or if an error occurs while instantiating any strategy
-
load
Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader and the given argument resolver.The returned factories are sorted through
AnnotationAwareOrderComparator.If duplicate implementation class names are discovered for a given strategy type, only one instance of the duplicated implementation type will be instantiated.
- 参数:
strategyType- the interface or abstract class representing the strategyinstantiator- strategy used it to instantiate instance- 抛出:
IllegalArgumentException- if any strategy implementation class cannot be loaded or if an error occurs while instantiating any strategy
-
load
public <T> List<T> load(Class<T> strategyType, @Nullable TodayStrategies.FailureHandler failureHandler) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader with custom failure handling provided by the given failure handler.The returned factories are sorted through
AnnotationAwareOrderComparator.If duplicate implementation class names are discovered for a given strategy type, only one instance of the duplicated implementation type will be instantiated.
For any strategy implementation class that cannot be loaded or error that occurs while instantiating it, the given failure handler is called.
- 参数:
strategyType- the interface or abstract class representing the strategyfailureHandler- strategy used to handle strategy instantiation failures
-
load
public <T> List<T> load(Class<T> strategyType, @Nullable TodayStrategies.ArgumentResolver argumentResolver, @Nullable TodayStrategies.FailureHandler failureHandler) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader, the given argument resolver, and custom failure handling provided by the given failure handler.The returned factories are sorted through
AnnotationAwareOrderComparator.If duplicate implementation class names are discovered for a given strategy type, only one instance of the duplicated implementation type will be instantiated.
For any strategy implementation class that cannot be loaded or error that occurs while instantiating it, the given failure handler is called.
- 参数:
strategyType- the interface or abstract class representing the strategyargumentResolver- strategy used to resolve constructor arguments by their typefailureHandler- strategy used to handle strategy instantiation failures
-
load
public <T> List<T> load(Class<T> strategyType, TodayStrategies.Instantiator instantiator, @Nullable TodayStrategies.FailureHandler failureHandler) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the configured class loader, the given argument resolver, and custom failure handling provided by the given failure handler.The returned factories are sorted through
AnnotationAwareOrderComparator.If duplicate implementation class names are discovered for a given strategy type, only one instance of the duplicated implementation type will be instantiated.
For any strategy implementation class that cannot be loaded or error that occurs while instantiating it, the given failure handler is called.
- 参数:
strategyType- the interface or abstract class representing the strategyinstantiator- strategy used it to instantiate instancefailureHandler- strategy used to handle strategy instantiation failures
-
instantiateStrategy
@Nullable protected <T> T instantiateStrategy(String implementationName, Class<T> type, TodayStrategies.Instantiator instantiator, TodayStrategies.FailureHandler failureHandler) -
getFirst
get first strategy- 另请参阅:
-
getFirst
get first strategy- 另请参阅:
-
find
get none repeatable strategies by given class- 类型参数:
T- target type- 参数:
strategyClass- strategy class- 返回:
- returns none repeatable strategies by given class
-
find
Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.The returned factories are sorted through
AnnotationAwareOrderComparator.if duplicate implementation class names are discovered for a given strategy type, only one instance of the duplicated implementation type will be instantiated.
For more advanced strategy loading with
TodayStrategies.ArgumentResolverorTodayStrategies.FailureHandlersupport useforDefaultResourceLocation(ClassLoader)to obtain aTodayStrategiesinstance.- 参数:
strategyType- the interface or abstract class representing the strategyclassLoader- the ClassLoader to use for loading (can benullto use the default)- 抛出:
IllegalArgumentException- if any strategy implementation class cannot be loaded or if an error occurs while instantiating any strategy
-
find
public static <T> List<T> find(Class<T> strategyType, @Nullable ClassLoader classLoader, TodayStrategies.Instantiator instantiator) Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.The returned factories are sorted through
AnnotationAwareOrderComparator.if duplicate implementation class names are discovered for a given strategy type, only one instance of the duplicated implementation type will be instantiated.
For more advanced strategy loading with
TodayStrategies.ArgumentResolverorTodayStrategies.FailureHandlersupport useforDefaultResourceLocation(ClassLoader)to obtain aTodayStrategiesinstance.- 参数:
strategyType- the interface or abstract class representing the strategyclassLoader- the ClassLoader to use for loading (can benullto use the default)- 抛出:
IllegalArgumentException- if any strategy implementation class cannot be loaded or if an error occurs while instantiating any strategy
-
find
Load and instantiate the strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.The returned factories are sorted through
AnnotationAwareOrderComparator.if duplicate implementation class names are discovered for a given strategy type, only one instance of the duplicated implementation type will be instantiated.
For more advanced strategy loading with
TodayStrategies.ArgumentResolverorTodayStrategies.FailureHandlersupport useforDefaultResourceLocation(ClassLoader)to obtain aTodayStrategiesinstance.- 参数:
strategyType- the interface or abstract class representing the strategy- 抛出:
IllegalArgumentException- if any strategy implementation class cannot be loaded or if an error occurs while instantiating any strategy
-
findNames
Load the fully qualified class names of strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.if a particular implementation class name is discovered more than once for the given strategy type, duplicates will be ignored.
- 参数:
strategyType- the interface or abstract class representing the strategy- 抛出:
IllegalArgumentException- if an error occurs while loading strategy names- 另请参阅:
-
findNames
Load the fully qualified class names of strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.if a particular implementation class name is discovered more than once for the given strategy type, duplicates will be ignored.
- 参数:
strategyType- the interface or abstract class representing the strategyclassLoader- the ClassLoader to use for loading resources; can benullto use the default- 抛出:
IllegalArgumentException- if an error occurs while loading strategy names- 另请参阅:
-
findNames
Load the fully qualified class names of strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.if a particular implementation class name is discovered more than once for the given strategy type, duplicates will be ignored.
- 参数:
strategyKey- the key representing the strategy- 抛出:
IllegalArgumentException- if an error occurs while loading strategy names- 另请参阅:
-
findNames
Load the fully qualified class names of strategy implementations of the given type from "META-INF/today-strategies.properties", using the given class loader.if a particular implementation class name is discovered more than once for the given strategy type, duplicates will be ignored.
- 参数:
strategyKey- the key representing the strategyclassLoader- the ClassLoader to use for loading resources; can benullto use the default- 抛出:
IllegalArgumentException- if an error occurs while loading strategy names- 另请参阅:
-
forDefaultResourceLocation
Create aTodayStrategiesinstance that will load and instantiate the strategy implementations from "META-INF/today-strategies.properties", using the default class loader.- 返回:
- a
TodayStrategiesinstance - 另请参阅:
-
forDefaultResourceLocation
Create aTodayStrategiesinstance that will load and instantiate the strategy implementations from "META-INF/today-strategies.properties", using the given class loader.- 参数:
classLoader- the ClassLoader to use for loading resources; can benullto use the default- 返回:
- a
TodayStrategiesinstance - 另请参阅:
-
forLocation
Create aTodayStrategiesinstance that will load and instantiate the strategy implementations from the given location, using the default class loader.- 参数:
resourceLocation- the resource location to look for factories- 返回:
- a
TodayStrategiesinstance - 另请参阅:
-
forLocation
public static TodayStrategies forLocation(String resourceLocation, @Nullable ClassLoader classLoader) Create aTodayStrategiesinstance that will load and instantiate the strategy implementations from the given location, using the given class loader.- 参数:
resourceLocation- the resource location to look for factoriesclassLoader- the ClassLoader to use for loading resources; can benullto use the default- 返回:
- a
TodayStrategiesinstance - 另请参阅:
-
loadResource
-