Class LongSizeStringParser
java.lang.Object
com.martiansoftware.jsap.StringParser
com.martiansoftware.jsap.stringparsers.LongSizeStringParser
A
StringParser that lets the user specify sizes with an optional unit.
This parser will parse its argument using parseSize(CharSequence).
- Author:
- Sebastiano Vigna
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic LongSizeStringParserReturns the only instance of aLongSizeStringParser.Parses the specified argument into an Object of the appropriate type.static longParses a size specified using units (e.g., K, Ki, M, Mi,…).Methods inherited from class StringParser
setUp, tearDown
-
Method Details
-
getParser
Returns the only instance of aLongSizeStringParser.Convenient access to the only instance returned by this method is available through
JSAP.LONGSIZE_PARSER.- Returns:
- the only instance of a
LongSizeStringParser.
-
parse
Description copied from class:StringParserParses the specified argument into an Object of the appropriate type. If the specified argument cannot be converted into the desired Object, a ParseException should be thrown.
Note: this method MAY BE CALLED with a null argument. Take this into consideration when subclassing!- Specified by:
parsein classStringParser- Parameters:
arg- the argument to convert to an Object of class appropriate to the StringParser subclass.- Returns:
- the Object resulting from the parsed argument.
- Throws:
ParseException- if the specified argument cannot be parsed.
-
parseSize
Parses a size specified using units (e.g., K, Ki, M, Mi,…).The argument must be in the form number [unit] (with no space inbetween). number is anything accepted by
Long.decode(java.lang.String), which allows, besides decimal numbers, hexadecimal numbers prefixed by0x,0Xor#, and octal numbers prefixed by0. unit may be one of K (103), Ki (210), M (106), Mi (220), G (109), Gi (230), T (1012), Ti (240), P (1015), Pi (250). Thus, for instance, 1Ki is 1024, whereas 9M is nine millions and0x10Piis 18014398509481984. Note that in the number part case does not matter, but in the unit part it does.- Parameters:
s- a size specified as above.- Returns:
- the corresponding unitless size.
- Throws:
ParseException- ifsis malformed, number is negative or the resulting size is larger thanLong.MAX_VALUE.
-