Class SParser
-
- All Implemented Interfaces:
public class SParserA common string parser
vincent
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classSParser.IntegerRangesA class that represents a set of positive integer ranges. It parses strings of the form: "2-3,5,7-" where ranges are separated by comma and the lower/upper bounds are separated by dash. Either the lower or upper bound may be omitted meaning all values up to or over. So the string above 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 LoggerLOGpublic final static DurationINVALID_DURATIONpublic 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, nullif no 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.StringgetRaw()getRaw. Stringget(String defaultValue)get. intgetInt(int defaultValue)Get an integer value, if the configured value is invalid or not set, return the default value. 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 longor human 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.SParser.IntegerRangesgetRange(String defaultValue)Parse the given attribute as a set of integer ranges Collection<String>getStringCollection()Get the comma delimited values of property as a collection of Strings.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 as an array of Strings.voidsetStrings(Array<String> values)Set the array of string values for property as as comma delimited values. Array<String>getStrings(Array<String> defaultValue)Get the comma delimited values of property as an array of Strings.Collection<String>getTrimmedStringCollection()Get the comma delimited values of property as a collection of Strings, trimmed of the leading and trailing whitespace.Array<String>getTrimmedStrings()Get the comma delimited values of property as an array of Strings, trimmed of the leading and trailing whitespace.Array<String>getTrimmedStrings(Array<String> defaultValue)Get the comma delimited values of property as an array of Strings, trimmed of the leading and trailing whitespace.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 format ISO-8601 standard : PnDTnHnMn.nS Hadoop time duration format : Valid units are : ns, us, ms, s, m, h, d. DurationgetDuration()Retrieves the duration. InstantgetInstant()Try to detect a date time from the text and convert it to be a instant If no date time detected, return Instant. InstantgetInstant(Instant defaultValue)Try to detect a date time from the text and convert it to be a instant If no date time detected, return defaultValue Accept 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 exception if it couldn't be loaded. Array<Class<out Object>>getClasses(Array<Class<out Object>> defaultValue)Get the value of property as an array of Class.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 with the 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.
- Returns:
the correct class loader.
-
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.- Returns:
a ai.platon.pulsar.common.SParser 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,
nullif no such property exists.Values are processed for variable expansion before being returned.
- Returns:
the value of or its replacing property, or null if no such property exists.
-
getTrimmed
String getTrimmed()
Get the value of property as a trimmed
String,nullif no such property exists.Values are processed for variable expansion before being returned.
- Returns:
the value of or its replacing property, or null if no such property exists.
-
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.- Returns:
the value of or defaultValue if it is not set.
-
getRaw
String getRaw()
getRaw.
- Returns:
a java.lang.String object.
-
get
String get(String defaultValue)
get.
- Parameters:
defaultValue- a java.lang.String object.- Returns:
a java.lang.String object.
-
getInt
int getInt(int defaultValue)
Get an integer value, if the configured value is invalid or not set, return the default value.
-
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.- Returns:
property value as a
long, ordefaultValue.
-
getLongBytes
long getLongBytes(long defaultValue)
Get the value of property as a
longor human readable format. If no such property exists, the provided default value is returned, or if the specified value is not a validlongor human readable format, then an error is thrown. You can use the following suffix (case insensitive): k(kilo), m(mega), g(giga), t(tera), p(peta), e(exa)- Parameters:
defaultValue- default value.- Returns:
property value as a
long, ordefaultValue.
-
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.- Returns:
property value as a
float, ordefaultValue.
-
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.- Returns:
property value as a
double, ordefaultValue.
-
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.- Returns:
property value as a
boolean, ordefaultValue.
-
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. This is 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- Returns:
a T object.
-
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 in properties 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.- Returns:
The time duration
-
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- Returns:
property value as a compiled Pattern, or defaultValue
-
setPattern
void setPattern(Pattern pattern)
Set the given property to
Pattern. If the pattern is passed as null, sets the empty pattern which results in further 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- Returns:
a new set of ranges from the configured value
-
getStringCollection
Collection<String> getStringCollection()
Get the comma delimited values of property as a collection of
Strings. If no such property is specified then empty collection is returned.- Returns:
property value as a collection of
Strings.
-
getPair
Pair<String, String> getPair(Pair<String, String> defaultValue)
getPair.
- Parameters:
defaultValue- a org.apache.commons.lang3.tuple.Pair object.- Returns:
a org.apache.commons.lang3.tuple.Pair object.
-
getKvs
Map<String, String> getKvs()
getKvs.
- Returns:
a java.util.Map object.
-
getKvs
Map<String, String> getKvs(String kvDelimeter)
getKvs.
- Parameters:
kvDelimeter- a java.lang.String object.- Returns:
a java.util.Map object.
-
getKvs
Map<String, String> getKvs(String pairDelimeterPattern, String kvDelimeter)
getKvs.
- Parameters:
pairDelimeterPattern- a java.lang.String object.kvDelimeter- a java.lang.String object.- Returns:
a java.util.Map object.
-
getStrings
Array<String> getStrings()
Get the comma delimited values of property as an array of
Strings. If no such property is specified thennullis returned.- Returns:
property value as an array of
Strings, ornull.
-
setStrings
void setStrings(Array<String> values)
Set the array of string values for property as as comma delimited values.
- Parameters:
values- The values
-
getStrings
Array<String> getStrings(Array<String> defaultValue)
Get the comma delimited values of property as an array of
Strings. If no such property is specified then default value is returned.- Parameters:
defaultValue- The default value- Returns:
property value as an array of
Strings, or default value.
-
getTrimmedStringCollection
Collection<String> getTrimmedStringCollection()
Get the comma delimited values of property as a collection of
Strings, trimmed of the leading and trailing whitespace. If no such property is specified then emptyCollectionis returned.- Returns:
property value as a collection of
Strings, or emptyCollection
-
getTrimmedStrings
Array<String> getTrimmedStrings()
Get the comma delimited values of property as an array of
Strings, trimmed of the leading and trailing whitespace. If no such property is specified then an empty array is returned.- Returns:
property value as an array of trimmed
Strings, or empty array.
-
getTrimmedStrings
Array<String> getTrimmedStrings(Array<String> defaultValue)
Get the comma delimited values of property as an 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- Returns:
property value as an array of trimmed
Strings, or 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- Returns:
a positive integer
-
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- Returns:
a positive long integer
-
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 format ISO-8601 standard : PnDTnHnMn.nS Hadoop time duration format : Valid units are : ns, us, ms, s, m, h, d.
- Parameters:
defaultValue- a java.time.Duration object.- Returns:
a java.time.Duration object.
-
getDuration
Duration getDuration()
Retrieves the duration.
This method obtains the duration by invoking another overloaded getDuration method. It uses a constant named INVALID_DURATION as a default value, indicating that if a valid duration cannot be obtained, an invalid Duration object will be returned.
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.
Note: for hadoop time duration format, the unit is always lowercase, and only single unit is allowed.
- Returns:
A Duration object representing the duration of a process. If a valid duration cannot be obtained, it returns an object representing an invalid duration.
-
getInstant
Instant getInstant()
Try to detect a date time from the text and convert it to be a instant If 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 instant If no date time detected, return defaultValue Accept 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- Returns:
the class object.
-
getClassByNameOrNull
Class<out Object> getClassByNameOrNull(String name)
Load a class by name, returning null rather than throwing an exception if it couldn't be loaded. This is to avoid the overhead of creating an exception.
- Parameters:
name- the class name- Returns:
the class object, or null if it could not be found.
-
getClasses
Array<Class<out Object>> getClasses(Array<Class<out Object>> defaultValue)
Get the value of property as an array of
Class. The value of the property specifies a list of comma separated class names. If no such property is specified, thendefaultValueis returned.- Parameters:
defaultValue- default value.- Returns:
property value as a
Class[], ordefaultValue.
-
getClass
Class<out Object> getClass(Class<out Object> defaultValue)
Get the value as a
Class. If no such property is specified, thendefaultValueis returned.- Parameters:
defaultValue- default value.- Returns:
property value as a
Class, ordefaultValue.
-
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
defaultValueis returned.An exception is thrown if the returned class does not implement the named interface.
- Parameters:
defaultValue- default value.xface- the interface implemented by the named class.- Returns:
property value as a
Class, ordefaultValue.
-
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 the interfacexface.- 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 with the given path. If dirsProp contains multiple directories, then one is chosen based on path's hash code. If the selected directory does not exist, an attempt is made to create it.
- Parameters:
dirsProp- directory in which to locate the file.path- file-path.- Returns:
local file under the directory with the given path.
-
getResource
URL getResource()
Get the java.net.URL for the named resource.
- Returns:
the url for the named resource.
-
getResourceAsInputStream
InputStream getResourceAsInputStream()
Get an input stream
- Returns:
an input stream attached to the resource.
-
getResourceAsReader
Reader getResourceAsReader()
Get a java.io.Reader
- Returns:
a reader attached to the resource.
-
-
-
-