Package com.nuix.superutilities.misc
Class FormatUtility
- java.lang.Object
-
- com.nuix.superutilities.misc.FormatUtility
-
public class FormatUtility extends java.lang.Object
Class which offers methods for formatting values.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
FormatUtility()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
bytesToDynamicSize(long bytes, int decimalPlaces)
Converts size in bytes to a String representing the file size, as you might see it represented by the OS, such as "1.24 KB" or "3.42 GB"static double
bytesToGigaBytes(long bytes, int decimalPlaces)
Converts size specified in bytes to size specified in giga bytes, rounding to specified number of decimal places.static java.lang.String
bytesToHex(byte[] bytes)
Convenience method for converting a byte array to a hex string.static double
bytesToKiloBytes(long bytes, int decimalPlaces)
Converts size specified in bytes to size specified in kilo bytes, rounding to specified number of decimal places.static double
bytesToMegaBytes(long bytes, int decimalPlaces)
Converts size specified in bytes to size specified in mega bytes, rounding to specified number of decimal places.java.lang.String
convertToString(java.lang.Object value)
Attempts to convert data types, which may be values of metadata properties or custom metadata, to a String.static java.lang.String
debugString(java.lang.Exception exc)
static java.lang.String
debugString(java.util.Map<java.lang.String,?> map)
static java.lang.String
escapeTagForSearch(java.lang.String tagName)
static java.lang.String
formatAsTextualTable(java.util.List<java.util.List<java.lang.String>> rows)
java.lang.String
formatNumber(double number)
Convenience method for formatting numeric value using US locale.java.lang.String
formatNumber(int number)
Convenience method for formatting numeric value using US locale.java.lang.String
formatNumber(long number)
Convenience method for formatting numeric value using US locale.java.lang.String
getFilenameTimestamp()
Generates a time stamp string which is safe to use in a file or directory name.static java.lang.String
getHtmlText(java.lang.String htmlSource)
Convenience method for getting the "rendered text" (text as seen in browser) of HTML source code using Jsoup.static FormatUtility
getInstance()
static double
getUnitBase()
Gets the unit base which will be used in size calculations.static boolean
getUseSIUnits()
Gets value indicating whether SI Unit (1000 Bytes = 1 Kilo Byte) will be used.static byte[]
hexToBytes(java.lang.String hex)
Convenience method for converting hex string to byte array.static java.io.File
makeGuidPath(nuix.Item item, java.io.File rootDirectory, java.lang.String extension)
java.lang.String
resolvePlaceholders(java.lang.String template, java.util.Map<java.lang.String,java.lang.Object> placeholderValues)
Simple method to replace place holders with values in a template string.static double
round(double value, int numberOfDigitsAfterDecimalPoint)
Helper method for rounding a decimal value to a particular number of decimal places.java.lang.String
secondsToElapsedString(long offsetSeconds)
Converts a value representing some number of seconds to an "elapsed" string.java.lang.String
secondsToElapsedString(java.lang.Double offsetSeconds)
Converts a value representing some number of seconds to an "elapsed" string.static void
setUseSIUnits(boolean useSIUnits)
Gets value indicating whether SI Unit (1000 Bytes = 1 Kilo Byte) will be used.static java.util.List<java.lang.String>
tokenizeText(java.lang.String inputText)
Convenience method for using Lucene's StandardTokenizer to tokenize arbitrary text.
-
-
-
Method Detail
-
getInstance
public static FormatUtility getInstance()
-
hexToBytes
public static byte[] hexToBytes(java.lang.String hex)
Convenience method for converting hex string to byte array.- Parameters:
hex
- String of hexadecimal.- Returns:
- Byte array equivalent.
-
bytesToHex
public static java.lang.String bytesToHex(byte[] bytes)
Convenience method for converting a byte array to a hex string.- Parameters:
bytes
- The bytes to convert.- Returns:
- A string representation of the byte array as hexadecimal.
-
convertToString
public java.lang.String convertToString(java.lang.Object value)
Attempts to convert data types, which may be values of metadata properties or custom metadata, to a String. Data types supported: - String - Integer - Long Integer - Boolean - Float - Double - Byte Array Data of other types will just have their toString method called.- Parameters:
value
- Value to attempt to convert to a String- Returns:
- A String value of the provided data.
-
secondsToElapsedString
public java.lang.String secondsToElapsedString(java.lang.Double offsetSeconds)
Converts a value representing some number of seconds to an "elapsed" string. For example a value of 75 seconds would be converted to the string "00:01:15". If the time span represents more than 24 hours you may get a value such as "3 Days 11:01:37".- Parameters:
offsetSeconds
- The number of seconds elapsed- Returns:
- A String representing the elapsed time.
-
secondsToElapsedString
public java.lang.String secondsToElapsedString(long offsetSeconds)
Converts a value representing some number of seconds to an "elapsed" string. For example a value of 75 seconds would be converted to the string "00:01:15". If the time span represents more than 24 hours you may get a value such as "3 Days 11:01:37".- Parameters:
offsetSeconds
- The number of seconds elapsed- Returns:
- A String representing the elapsed time.
-
formatNumber
public java.lang.String formatNumber(int number)
Convenience method for formatting numeric value using US locale.- Parameters:
number
- The number to format- Returns:
- Formatting String version of the number
-
formatNumber
public java.lang.String formatNumber(long number)
Convenience method for formatting numeric value using US locale.- Parameters:
number
- The number to format- Returns:
- Formatting String version of the number
-
formatNumber
public java.lang.String formatNumber(double number)
Convenience method for formatting numeric value using US locale.- Parameters:
number
- The number to format- Returns:
- Formatting String version of the number
-
resolvePlaceholders
public java.lang.String resolvePlaceholders(java.lang.String template, java.util.Map<java.lang.String,java.lang.Object> placeholderValues)
Simple method to replace place holders with values in a template string. Placeholders are values starting with a '{', followed by a name, followed by '}'. For example "{name}".- Parameters:
template
- The template text to resolve place holders inplaceholderValues
- Map of place holder names and associated values to replace them with. Name should not include '{' or '}'- Returns:
- Template string with place holders replaced
-
getFilenameTimestamp
public java.lang.String getFilenameTimestamp()
Generates a time stamp string which is safe to use in a file or directory name.- Returns:
- File/directory name safe time stamp string.
-
getUseSIUnits
public static boolean getUseSIUnits()
Gets value indicating whether SI Unit (1000 Bytes = 1 Kilo Byte) will be used.- Returns:
- True if size methods use 1000 bytes, false if they will use 1024 bytes
-
setUseSIUnits
public static void setUseSIUnits(boolean useSIUnits)
Gets value indicating whether SI Unit (1000 Bytes = 1 Kilo Byte) will be used.- Parameters:
useSIUnits
- True if size methods use 1000 bytes, false if they will use 1024 bytes
-
getUnitBase
public static double getUnitBase()
Gets the unit base which will be used in size calculations. Will return 1000 ifgetUseSIUnits()
returns true and 1024 ifgetUseSIUnits()
returns false.- Returns:
- Size base unit used in size calculations.
-
bytesToKiloBytes
public static double bytesToKiloBytes(long bytes, int decimalPlaces)
Converts size specified in bytes to size specified in kilo bytes, rounding to specified number of decimal places.- Parameters:
bytes
- Size in bytesdecimalPlaces
- Number of decimal places to round to- Returns:
- Size in bytes converted to size in kilo bytes
-
bytesToMegaBytes
public static double bytesToMegaBytes(long bytes, int decimalPlaces)
Converts size specified in bytes to size specified in mega bytes, rounding to specified number of decimal places.- Parameters:
bytes
- Size in bytesdecimalPlaces
- Number of decimal places to round to- Returns:
- Size in bytes converted to size in mega bytes
-
bytesToGigaBytes
public static double bytesToGigaBytes(long bytes, int decimalPlaces)
Converts size specified in bytes to size specified in giga bytes, rounding to specified number of decimal places.- Parameters:
bytes
- Size in bytesdecimalPlaces
- Number of decimal places to round to- Returns:
- Size in bytes converted to size in giga bytes
-
bytesToDynamicSize
public static java.lang.String bytesToDynamicSize(long bytes, int decimalPlaces)
Converts size in bytes to a String representing the file size, as you might see it represented by the OS, such as "1.24 KB" or "3.42 GB"- Parameters:
bytes
- The size in bytesdecimalPlaces
- The number of decimal places to include in the result- Returns:
- A String representing the size in appropriate format
-
round
public static double round(double value, int numberOfDigitsAfterDecimalPoint)
Helper method for rounding a decimal value to a particular number of decimal places.- Parameters:
value
- The value to roundnumberOfDigitsAfterDecimalPoint
- Number of digits to round to- Returns:
- The given value rounded off to specified decimal places
-
tokenizeText
public static java.util.List<java.lang.String> tokenizeText(java.lang.String inputText) throws java.lang.Exception
Convenience method for using Lucene's StandardTokenizer to tokenize arbitrary text.- Parameters:
inputText
- The text to tokenize- Returns:
- A list of tokens parsed from inputText by Lucene.
- Throws:
java.lang.Exception
- Most likely thrown if Lucene tokenizer encounters a problem.
-
getHtmlText
public static java.lang.String getHtmlText(java.lang.String htmlSource)
Convenience method for getting the "rendered text" (text as seen in browser) of HTML source code using Jsoup.- Parameters:
htmlSource
- The HTML source code to parse the text from.- Returns:
- The "rendered text" of the provided HTML source code.
-
formatAsTextualTable
public static java.lang.String formatAsTextualTable(java.util.List<java.util.List<java.lang.String>> rows)
-
debugString
public static java.lang.String debugString(java.util.Map<java.lang.String,?> map)
-
debugString
public static java.lang.String debugString(java.lang.Exception exc)
-
makeGuidPath
public static java.io.File makeGuidPath(nuix.Item item, java.io.File rootDirectory, java.lang.String extension)
-
escapeTagForSearch
public static java.lang.String escapeTagForSearch(java.lang.String tagName)
-
-