Class AbstractConfiguration
-
- All Implemented Interfaces:
public abstract class AbstractConfigurationCreated by vincent on 17-1-17. Copyright @ 2013-2023 Platon AI. All rights reserved.
vincent
-
-
Constructor Summary
Constructors Constructor Description AbstractConfiguration(String profile, Boolean loadDefaults, Iterable<String> resources)AbstractConfiguration(KConfiguration conf)
-
Method Summary
Modifier and Type Method Description final StringgetName()final UnitsetName(String name)final StringgetProfile()final StringgetMode()final EnvironmentgetEnvironment()Spring core is the first class dependency now. final UnitsetEnvironment(Environment environment)Spring core is the first class dependency now. final KConfigurationunbox()Return the boxed KConfiguration. final Integersize()The configured item size. Stringget(String name)Get the value of the nameproperty,nullif no such property exists.Stringget(String name, String defaultValue)Get the value of the name.final IntegergetInt(String name, Integer defaultValue)Get the value of the nameproperty as anint.final IntArraygetInts(String name)Get the value of the nameproperty as a set of comma-delimitedintvalues.final LonggetLong(String name, Long defaultValue)Get the value of the nameproperty as along.final FloatgetFloat(String name, Float defaultValue)Get the value of the nameproperty as afloat.final DoublegetDouble(String name, Double defaultValue)Get the value of the nameproperty as adouble.final BooleangetBoolean(String name, Boolean defaultValue)Get the value of the nameproperty as aboolean.final <T extends Enum<T>> TgetEnum(String name, T defaultValue)Return value matching this enumerated type. final Collection<String>getStringCollection(String name)Get the comma delimited values of the nameproperty as a collection ofStrings.final Array<String>getStrings(String name)Get the comma delimited values of the nameproperty as an array ofStrings.final Array<String>getStrings(String name, String defaultValue)Get the comma delimited values of the nameproperty as an array ofStrings.final Collection<String>getTrimmedStringCollection(String name)Get the comma delimited values of the nameproperty as a collection ofStrings, trimmed of the leading and trailing whitespace.final Array<String>getTrimmedStrings(String name)Get the comma delimited values of the nameproperty as an array ofStrings, trimmed of the leading and trailing whitespace.final Array<String>getTrimmedStrings(String name, String defaultValue)Get the comma delimited values of the nameproperty as an array ofStrings, trimmed of the leading and trailing whitespace.final IntegergetUint(String name, Integer defaultValue)Get an unsigned integer, if the configured value is negative or not set, return the default value final LonggetUlong(String name, Long defaultValue)Get a unsigned long integer, if the configured value is negative, return the default value final DurationgetDuration(String name)Support both ISO-8601 standard and hadoop time duration format ISO-8601 standard : PnDTnHnMn.nS Hadoop time duration format : Valid units are : ns, us, ms, s, m, h, d. final DurationgetDuration(String name, Duration defaultValue)getDuration. final InstantgetInstant(String name, Instant defaultValue)getInstant. final PathgetPath(String name, Path elsePath)getPath. final PathgetPathOrNull(String name)getPathOrNull. final Map<String, String>getKvs(String name)getKvs. final InputStreamgetConfResourceAsInputStream(String resource)getConfResourceAsInputStream. final ReadergetConfResourceAsReader(String resource)getConfResourceAsReader. final URLgetResource(String resource)getResource. final Class<?>getClass(String name, Class<?> defaultValue)Get the value of the nameproperty as aClass.final <U extends Any> Class<out U>getClass(String name, Class<out U> defaultValue, Class<U> xface)Get the value of the nameproperty as aClassimplementing the interface specified byxface.StringtoString()-
-
Constructor Detail
-
AbstractConfiguration
AbstractConfiguration(String profile, Boolean loadDefaults, Iterable<String> resources)
-
AbstractConfiguration
AbstractConfiguration(KConfiguration conf)
-
-
Method Detail
-
getProfile
final String getProfile()
-
getEnvironment
final Environment getEnvironment()
Spring core is the first class dependency now.
-
setEnvironment
final Unit setEnvironment(Environment environment)
Spring core is the first class dependency now.
-
unbox
final KConfiguration unbox()
Return the boxed KConfiguration.
-
get
String get(String name)
Get the value of the
nameproperty,nullif no such property exists.- Parameters:
name- the property name, will be trimmed before get value.- Returns:
the value of the
name, or null if no such property exists.
-
get
String get(String name, String defaultValue)
Get the value of the
name. If the key is deprecated, it returns the value of the first key which replaces the deprecated key and is not null. If no such property exists, thendefaultValueis returned.- Parameters:
name- property name, will be trimmed before get value.defaultValue- default value.- Returns:
property value, or
defaultValueif the property doesn't exist.
-
getInt
final Integer getInt(String name, Integer defaultValue)
Get the value of the
nameproperty as anint.If no such property exists, the provided default value is returned, or if the specified value is not a valid
int, then an error is thrown.- Parameters:
name- property name.defaultValue- default value.- Returns:
property value as an
int, ordefaultValue.
-
getInts
final IntArray getInts(String name)
Get the value of the
nameproperty as a set of comma-delimitedintvalues.If no such property exists, an empty array is returned.
- Parameters:
name- property name- Returns:
property value interpreted as an array of comma-delimited
intvalues
-
getLong
final Long getLong(String name, Long defaultValue)
Get the value of the
nameproperty as along. If no such property exists, the provided default value is returned, or if the specified value is not a validlong, then an error is thrown.- Parameters:
name- property name.defaultValue- default value.- Returns:
property value as a
long, ordefaultValue.
-
getFloat
final Float getFloat(String name, Float defaultValue)
Get the value of the
nameproperty as afloat. If no such property exists, the provided default value is returned, or if the specified value is not a validfloat, then an error is thrown.- Parameters:
name- property name.defaultValue- default value.- Returns:
property value as a
float, ordefaultValue.
-
getDouble
final Double getDouble(String name, Double defaultValue)
Get the value of the
nameproperty as adouble. If no such property exists, the provided default value is returned, or if the specified value is not a validdouble, then an error is thrown.- Parameters:
name- property name.defaultValue- default value.- Returns:
property value as a
double, ordefaultValue.
-
getBoolean
final Boolean getBoolean(String name, Boolean defaultValue)
Get the value of the
nameproperty as aboolean. If no such property is specified, or if the specified value is not a validboolean, thendefaultValueis returned.- Parameters:
name- property name.defaultValue- default value.- Returns:
property value as a
boolean, ordefaultValue.
-
getEnum
final <T extends Enum<T>> T getEnum(String name, T defaultValue)
Return value matching this enumerated type.
- Parameters:
name- Property namedefaultValue- Value returned if no mapping exists- Returns:
a T object. </T>
-
getStringCollection
final Collection<String> getStringCollection(String name)
Get the comma delimited values of the
nameproperty as a collection ofStrings. If no such property is specified then empty collection is returned.This is an optimized version of .getStrings
- Parameters:
name- property name.- Returns:
property value as a collection of
Strings.
-
getStrings
final Array<String> getStrings(String name)
Get the comma delimited values of the
nameproperty as an array ofStrings. If no such property is specified thennullis returned.- Parameters:
name- property name.- Returns:
property value as an array of
Strings, ornull.
-
getStrings
final Array<String> getStrings(String name, String defaultValue)
Get the comma delimited values of the
nameproperty as an array ofStrings. If no such property is specified then default value is returned.- Parameters:
name- property name.defaultValue- The default value- Returns:
property value as an array of
Strings, or default value.
-
getTrimmedStringCollection
final Collection<String> getTrimmedStringCollection(String name)
Get the comma delimited values of the
nameproperty as a collection ofStrings, trimmed of the leading and trailing whitespace. If no such property is specified then emptyCollectionis returned.- Parameters:
name- property name.- Returns:
property value as a collection of
Strings, or emptyCollection
-
getTrimmedStrings
final Array<String> getTrimmedStrings(String name)
Get the comma delimited values of the
nameproperty as an array ofStrings, trimmed of the leading and trailing whitespace. If no such property is specified then an empty array is returned.- Parameters:
name- property name.- Returns:
property value as an array of trimmed
Strings, or empty array.
-
getTrimmedStrings
final Array<String> getTrimmedStrings(String name, String defaultValue)
Get the comma delimited values of the
nameproperty as an array ofStrings, trimmed of the leading and trailing whitespace. If no such property is specified then default value is returned.- Parameters:
name- property name.defaultValue- The default value- Returns:
property value as an array of trimmed
Strings, or default value.
-
getUint
final Integer getUint(String name, Integer defaultValue)
Get an unsigned integer, if the configured value is negative or not set, return the default value
- Parameters:
name- The property namedefaultValue- The default value return if the configured value is negative- Returns:
a positive integer
-
getUlong
final Long getUlong(String name, Long defaultValue)
Get a unsigned long integer, if the configured value is negative, return the default value
- Parameters:
name- The property namedefaultValue- The default value return if the configured value is negative- Returns:
a positive long integer
-
getDuration
final Duration getDuration(String name)
Support both ISO-8601 standard and hadoop time duration format ISO-8601 standard : PnDTnHnMn.nS Hadoop time duration format : Valid units are : ns, us, ms, s, m, h, d.
- Parameters:
name- a java.lang.String object.- Returns:
a java.time.Duration object.
-
getDuration
final Duration getDuration(String name, Duration defaultValue)
getDuration.
- Parameters:
name- a java.lang.String object.defaultValue- a java.time.Duration object.- Returns:
a java.time.Duration object.
-
getInstant
final Instant getInstant(String name, Instant defaultValue)
getInstant.
- Parameters:
name- a java.lang.String object.defaultValue- a java.time.Instant object.- Returns:
a java.time.Instant object.
-
getPath
final Path getPath(String name, Path elsePath)
getPath.
- Parameters:
name- a java.lang.String object.elsePath- a java.nio.file.Path object.- Returns:
a java.nio.file.Path object.
-
getPathOrNull
final Path getPathOrNull(String name)
getPathOrNull.
- Parameters:
name- a java.lang.String object.- Returns:
a java.nio.file.Path object.
-
getKvs
final Map<String, String> getKvs(String name)
getKvs.
- Parameters:
name- a java.lang.String object.- Returns:
a java.util.Map object.
-
getConfResourceAsInputStream
final InputStream getConfResourceAsInputStream(String resource)
getConfResourceAsInputStream.
- Parameters:
resource- a java.lang.String object.- Returns:
a java.io.InputStream object.
-
getConfResourceAsReader
final Reader getConfResourceAsReader(String resource)
getConfResourceAsReader.
- Parameters:
resource- a java.lang.String object.- Returns:
a java.io.Reader object.
-
getResource
final URL getResource(String resource)
getResource.
- Parameters:
resource- a java.lang.String object.- Returns:
a java.net.URL object.
-
getClass
final Class<?> getClass(String name, Class<?> defaultValue)
Get the value of the
nameproperty as aClass. If no such property is specified, thendefaultValueis returned.- Parameters:
name- the property name of class.defaultValue- default value.- Returns:
property value as a
Class, ordefaultValue.
-
getClass
final <U extends Any> Class<out U> getClass(String name, Class<out U> defaultValue, Class<U> xface)
Get the value of the
nameproperty as aClassimplementing the interface specified byxface.If no such property is specified, then
defaultValueis returned.An exception is thrown if the returned class does not implement the named interface.
- Parameters:
name- the property name of class.defaultValue- default value.xface- the interface implemented by the named class.- Returns:
property value as a
Class, ordefaultValue.
-
-
-
-