-
public class SParserA common string parser
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classSParser.IntegerRangesA class that represents a set of positive integer ranges. It parsesstrings of the form: "2-3,5,7-" where ranges are separated by comma andthe lower/upper bounds are separated by dash. Either the lower or upperbound may be omitted meaning all values up to or over. So the stringabove means 2, 3, 5, and 7, 8, 9, ...
public enumSParser.TraditionalBinaryPrefixThe traditional binary prefixes, kilo, mega, ..., exa,which can be represented by a 64-bit integer.TraditionalBinaryPrefix symbol are case insensitive.
-
Field Summary
Fields Modifier and Type Field Description public final static LogLOGpublic final static DurationINVALID_DURATIONprivate ClassLoaderclassLoader
-
Method Summary
Modifier and Type Method Description ClassLoadergetClassLoader()Get the java.lang.ClassLoader for this job. voidsetClassLoader(ClassLoader classLoader)Set the class loader that will be used to load the various objects. static SParserwrap(String value)wrap. voidset(String value)set. synchronized voidsetIfUnset(String value)setIfUnset. Stringget()Get the value of property, nullifno such property exists.StringgetTrimmed()Get the value of property as a trimmed String,nullif no such property exists.StringgetTrimmed(String defaultValue)Get the value of property as a trimmed String,defaultValueif no such property exists.See @{Configuration#getTrimmed} for more details.StringgetRaw()getRaw. Stringget(String defaultValue)get. intgetInt(int defaultValue)getInt. Array<int>getInts()getInts. voidsetInt(int value)setInt. longgetLong(long defaultValue)Get the value of property as a long.longgetLongBytes(long defaultValue)Get the value of property as a longorhuman readable format.voidsetLong(long value)Set the value of property to a long.floatgetFloat(float defaultValue)Get the value of property as a float.voidsetFloat(float value)Set the value of property to a float.doublegetDouble(double defaultValue)Get the value of property as a double.voidsetDouble(double value)Set the value of property to a double.booleangetBoolean(boolean defaultValue)Get the value of property as a boolean.voidsetBoolean(boolean value)Set the value of property to a boolean.voidsetBooleanIfUnset(boolean value)Set the given property, if it is currently unset. <T extends Enum<T>> voidsetEnum(T value)Set the value of property to the given type. <T extends Enum<T>> TgetEnum(T defaultValue)Return value matching this enumerated type. voidsetTimeDuration(long value, TimeUnit unit)Set the value to the given time duration longgetTimeDuration(long defaultValue, TimeUnit unit)Return time duration in the given time unit. PatterngetPattern(Pattern defaultValue)Get the value of property as a Pattern.voidsetPattern(Pattern pattern)Set the given property to Pattern.If the pattern is passed as null, sets the empty pattern which results infurther calls to getPattern(...) returning the default value.SParser.IntegerRangesgetRange(String defaultValue)Parse the given attribute as a set of integer ranges Collection<String>getStringCollection()Get the comma delimited values of property asa collection of Strings.If no such property is specified then empty collection is returned.Pair<String, String>getPair(Pair<String, String> defaultValue)getPair. Map<String, String>getKvs()getKvs. Map<String, String>getKvs(String kvDelimeter)getKvs. Map<String, String>getKvs(String pairDelimeterPattern, String kvDelimeter)getKvs. Array<String>getStrings()Get the comma delimited values of property asan array of Strings.voidsetStrings(Array<String> values)Set the array of string values for property asas comma delimited values. Array<String>getStrings(Array<String> defaultValue)Get the comma delimited values of property asan array of Strings.If no such property is specified then default value is returned.Collection<String>getTrimmedStringCollection()Get the comma delimited values of property asa collection of Strings, trimmed of the leading and trailing whitespace.Array<String>getTrimmedStrings()Get the comma delimited values of property asan array of Strings, trimmed of the leading and trailing whitespace.If no such property is specified then an empty array is returned.Array<String>getTrimmedStrings(Array<String> defaultValue)Get the comma delimited values of property asan array of Strings, trimmed of the leading and trailing whitespace.If no such property is specified then default value is returned.IntegergetUint(int defaultValue)Get a unsigned integer, if the configured value is negative or not set, return the default value LonggetUlong(long defaultValue)Get a unsigned long integer, if the configured value is negative, return the default value voidsetIfNotNull(String value)setIfNotNull. voidsetIfNotEmpty(String value)setIfNotEmpty. DurationgetDuration(Duration defaultValue)Support both ISO-8601 standard and hadoop time duration formatISO-8601 standard : PnDTnHnMn.nSHadoop time duration format : Valid units are : ns, us, ms, s, m, h, d. DurationgetDuration()getDuration. InstantgetInstant()Try to detect a date time from the text and convert it to be a instantIf no date time detected, return Instant. InstantgetInstant(Instant defaultValue)Try to detect a date time from the text and convert it to be a instantIf no date time detected, return defaultValueAccept the following format:1. PathgetPath(Path defaultValue, boolean createDirectories)PathgetPath(Path defaultValue)PathgetPathOrNull()Class<out Object>getClassByName(String name)Load a class by name. Class<out Object>getClassByNameOrNull(String name)Load a class by name, returning null rather than throwing an exceptionif it couldn't be loaded. Array<Class<out Object>>getClasses(Array<Class<out Object>> defaultValue)Get the value of propertyas an array of Class.The value of the property specifies a list of comma separated class names.Class<out Object>getClass(Class<out Object> defaultValue)Get the value as a Class.<U> Class<out U>getClass(Class<out U> defaultValue, Class<U> xface)Set the value to theClassimplementing the given interfacexface.voidsetClass(Class<out Object> theClass, Class<out Object> xface)Set the value to theClassimplementing the given interfacexface.FilegetFile(String dirsProp, String path)Get a local file name under a directory named in dirsProp withthe given path. URLgetResource()Get the java.net.URL for the named resource. InputStreamgetResourceAsInputStream()Get an input stream ReadergetResourceAsReader()Get a java.io.Reader -
-
Constructor Detail
-
SParser
SParser()
Constructor for SParser.
-
SParser
SParser(String value)
Constructor for SParser.- Parameters:
value- a java.lang.String object.
-
-
Method Detail
-
getClassLoader
ClassLoader getClassLoader()
Get the java.lang.ClassLoader for this job.
-
setClassLoader
void setClassLoader(ClassLoader classLoader)
Set the class loader that will be used to load the various objects.
- Parameters:
classLoader- the new class loader.
-
wrap
static SParser wrap(String value)
wrap.
- Parameters:
value- a java.lang.String object.
-
set
void set(String value)
set.
- Parameters:
value- a java.lang.String object.
-
setIfUnset
synchronized void setIfUnset(String value)
setIfUnset.
- Parameters:
value- a java.lang.String object.
-
get
String get()
Get the value of property,
nullifno such property exists. If the key is deprecated, it returns the value ofthe first key which replaces the deprecated key and is not null.Values are processed for variable expansionbefore being returned.
-
getTrimmed
String getTrimmed()
Get the value of property as a trimmed
String,nullif no such property exists.If the key is deprecated, it returns the value ofthe first key which replaces the deprecated key and is not nullValues are processed for variable expansionbefore being returned.
-
getTrimmed
String getTrimmed(String defaultValue)
Get the value of property as a trimmed
String,defaultValueif no such property exists.See @{Configuration#getTrimmed} for more details.- Parameters:
defaultValue- the property default value.
-
get
String get(String defaultValue)
get.
- Parameters:
defaultValue- a java.lang.String object.
-
getInt
int getInt(int defaultValue)
getInt.
- Parameters:
defaultValue- a int.
-
setInt
void setInt(int value)
setInt.
- Parameters:
value- a int.
-
getLong
long getLong(long defaultValue)
Get the value of property as a
long.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:
defaultValue- default value.
-
getLongBytes
long getLongBytes(long defaultValue)
Get the value of property as a
longorhuman readable format. If no such property exists, the provided defaultvalue is returned, or if the specified value is not a validlongor human readable format, then an error is thrown. Youcan use the following suffix (case insensitive): k(kilo), m(mega), g(giga),t(tera), p(peta), e(exa)- Parameters:
defaultValue- default value.
-
setLong
void setLong(long value)
Set the value of property to a
long.- Parameters:
value-longvalue of the property.
-
getFloat
float getFloat(float defaultValue)
Get the value of property as a
float.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:
defaultValue- default value.
-
setFloat
void setFloat(float value)
Set the value of property to a
float.- Parameters:
value- property value.
-
getDouble
double getDouble(double defaultValue)
Get the value of property as a
double.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:
defaultValue- default value.
-
setDouble
void setDouble(double value)
Set the value of property to a
double.- Parameters:
value- property value.
-
getBoolean
boolean getBoolean(boolean defaultValue)
Get the value of property as a
boolean.If no such property is specified, or if the specified value is not a validboolean, thendefaultValueis returned.- Parameters:
defaultValue- default value.
-
setBoolean
void setBoolean(boolean value)
Set the value of property to a
boolean.- Parameters:
value-booleanvalue of the property.
-
setBooleanIfUnset
void setBooleanIfUnset(boolean value)
Set the given property, if it is currently unset.
- Parameters:
value- new value
-
setEnum
<T extends Enum<T>> void setEnum(T value)
Set the value of property to the given type. Thisis equivalent to
set(<name>, value.toString()).- Parameters:
value- new value
-
getEnum
<T extends Enum<T>> T getEnum(T defaultValue)
Return value matching this enumerated type.
- Parameters:
defaultValue- Value returned if no mapping exists
-
setTimeDuration
void setTimeDuration(long value, TimeUnit unit)
Set the value to the given time duration
- Parameters:
value- Time durationunit- Unit of time
-
getTimeDuration
long getTimeDuration(long defaultValue, TimeUnit unit)
Return time duration in the given time unit. Valid units are encoded inproperties as suffixes: nanoseconds (ns), microseconds (us), milliseconds(ms), seconds (s), minutes (m), hours (h), and days (d).
- Parameters:
defaultValue- Value returned if no mapping exists.unit- Unit to convert the stored property, if it exists.
-
getPattern
Pattern getPattern(Pattern defaultValue)
Get the value of property as a
Pattern.If no such property is specified, or if the specified value is not a validPattern, thenDefaultValueis returned.- Parameters:
defaultValue- default value
-
setPattern
void setPattern(Pattern pattern)
Set the given property to
Pattern.If the pattern is passed as null, sets the empty pattern which results infurther calls to getPattern(...) returning the default value.- Parameters:
pattern- new value
-
getRange
SParser.IntegerRanges getRange(String defaultValue)
Parse the given attribute as a set of integer ranges
- Parameters:
defaultValue- the default value if it is not set
-
getStringCollection
Collection<String> getStringCollection()
Get the comma delimited values of property asa collection of
Strings.If no such property is specified then empty collection is returned.
-
getPair
Pair<String, String> getPair(Pair<String, String> defaultValue)
getPair.
- Parameters:
defaultValue- a org.apache.commons.lang3.tuple.Pair object.
-
getKvs
Map<String, String> getKvs(String kvDelimeter)
getKvs.
- Parameters:
kvDelimeter- a java.lang.String object.
-
getKvs
Map<String, String> getKvs(String pairDelimeterPattern, String kvDelimeter)
getKvs.
- Parameters:
pairDelimeterPattern- a java.lang.String object.kvDelimeter- a java.lang.String object.
-
getStrings
Array<String> getStrings()
Get the comma delimited values of property asan array of
Strings.If no such property is specified thennullis returned.
-
setStrings
void setStrings(Array<String> values)
Set the array of string values for property asas comma delimited values.
- Parameters:
values- The values
-
getStrings
Array<String> getStrings(Array<String> defaultValue)
Get the comma delimited values of property asan array of
Strings.If no such property is specified then default value is returned.- Parameters:
defaultValue- The default value
-
getTrimmedStringCollection
Collection<String> getTrimmedStringCollection()
Get the comma delimited values of property asa collection of
Strings, trimmed of the leading and trailing whitespace.If no such property is specified then emptyCollectionis returned.
-
getTrimmedStrings
Array<String> getTrimmedStrings()
Get the comma delimited values of property asan array of
Strings, trimmed of the leading and trailing whitespace.If no such property is specified then an empty array is returned.
-
getTrimmedStrings
Array<String> getTrimmedStrings(Array<String> defaultValue)
Get the comma delimited values of property asan array of
Strings, trimmed of the leading and trailing whitespace.If no such property is specified then default value is returned.- Parameters:
defaultValue- The default value
-
getUint
Integer getUint(int defaultValue)
Get a unsigned integer, if the configured value is negative or not set, return the default value
- Parameters:
defaultValue- The default value return if the configured value is negative
-
getUlong
Long getUlong(long defaultValue)
Get a unsigned long integer, if the configured value is negative, return the default value
- Parameters:
defaultValue- The default value return if the configured value is negative
-
setIfNotNull
void setIfNotNull(String value)
setIfNotNull.
- Parameters:
value- a java.lang.String object.
-
setIfNotEmpty
void setIfNotEmpty(String value)
setIfNotEmpty.
- Parameters:
value- a java.lang.String object.
-
getDuration
Duration getDuration(Duration defaultValue)
Support both ISO-8601 standard and hadoop time duration formatISO-8601 standard : PnDTnHnMn.nSHadoop time duration format : Valid units are : ns, us, ms, s, m, h, d.
- Parameters:
defaultValue- a java.time.Duration object.
-
getDuration
Duration getDuration()
getDuration.
-
getInstant
Instant getInstant()
Try to detect a date time from the text and convert it to be a instantIf no date time detected, return Instant.EPOCH
-
getInstant
Instant getInstant(Instant defaultValue)
Try to detect a date time from the text and convert it to be a instantIf no date time detected, return defaultValueAccept the following format:1. yyyy-MM-dd[ HH[:mm[:ss]]]2. ISO_INSTANT, or yyyy-MM-ddTHH:mm:ssZ
-
getPathOrNull
@Nullable() Path getPathOrNull()
-
getClassByName
Class<out Object> getClassByName(String name)
Load a class by name.
- Parameters:
name- The class name
-
getClassByNameOrNull
Class<out Object> getClassByNameOrNull(String name)
Load a class by name, returning null rather than throwing an exceptionif it couldn't be loaded. This is to avoid the overhead of creatingan exception.
- Parameters:
name- the class name
-
getClasses
Array<Class<out Object>> getClasses(Array<Class<out Object>> defaultValue)
Get the value of propertyas an array of
Class.The value of the property specifies a list of comma separated class names.If no such property is specified, thendefaultValueisreturned.- Parameters:
defaultValue- default value.
-
getClass
Class<out Object> getClass(Class<out Object> defaultValue)
Get the value as a
Class.If no such property is specified, thendefaultValueisreturned.- Parameters:
defaultValue- default value.
-
getClass
<U> Class<out U> getClass(Class<out U> defaultValue, Class<U> xface)
Set the value to
theClassimplementing the given interfacexface.If no such property is specified, then
defaultValueisreturned.An exception is thrown if the returned class does not implement the namedinterface.
- Parameters:
defaultValue- default value.xface- the interface implemented by the named class.
-
setClass
void setClass(Class<out Object> theClass, Class<out Object> xface)
Set the value to
theClassimplementing the given interfacexface.An exception is thrown if
theClassdoes not implement theinterfacexface.- Parameters:
theClass- property value.xface- the interface implemented by the named class.
-
getFile
File getFile(String dirsProp, String path)
Get a local file name under a directory named in dirsProp withthe given path. If dirsProp contains multiple directories,then one is chosen based on path's hash code. If the selecteddirectory does not exist, an attempt is made to create it.
- Parameters:
dirsProp- directory in which to locate the file.path- file-path.
-
getResource
URL getResource()
Get the java.net.URL for the named resource.
-
getResourceAsInputStream
InputStream getResourceAsInputStream()
Get an input stream
-
getResourceAsReader
Reader getResourceAsReader()
Get a java.io.Reader
-
-
-
-