Package 

Class SParser


  • 
    public class SParser
    
                        

    A common string parser

    • Constructor Detail

      • SParser

        SParser()
        Constructor for SParser.
    • Method Detail

      • setClassLoader

         void setClassLoader(ClassLoader classLoader)

        Set the class loader that will be used to load the various objects.

        Parameters:
        classLoader - the new class loader.
      • get

         String get()

        Get the value of property, null ifno 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,null if no 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(String defaultValue)

        Get the value of property as a trimmed String,defaultValue if no such property exists.See @{Configuration#getTrimmed} for more details.

        Parameters:
        defaultValue - the property default value.
      • 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 valid long,then an error is thrown.

        Parameters:
        defaultValue - default value.
      • getLongBytes

         long getLongBytes(long defaultValue)

        Get the value of property as a long orhuman readable format. If no such property exists, the provided defaultvalue is returned, or if the specified value is not a validlong or 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 - long value 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 valid float,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 valid double,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, then defaultValue is returned.

        Parameters:
        defaultValue - default value.
      • setBoolean

         void setBoolean(boolean value)

        Set the value of property to a boolean.

        Parameters:
        value - boolean value 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 duration
        unit - 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, then DefaultValue is 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.
      • getStrings

         Array<String> getStrings()

        Get the comma delimited values of property asan array of Strings.If no such property is specified then null is 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 empty Collection is 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
      • 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.
      • 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

      • 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, then defaultValue isreturned.

        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, then defaultValue isreturned.

        Parameters:
        defaultValue - default value.
      • getClass

         <U> Class<out U> getClass(Class<out U> defaultValue, Class<U> xface)

        Set the value to theClass implementing the given interface xface.

        If no such property is specified, then defaultValue isreturned.

        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 theClass implementing the given interface xface.

        An exception is thrown if theClass does not implement theinterface xface.

        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.