public class Util
extends java.lang.Object
| Constructor and Description |
|---|
Util() |
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.List<T> |
arrayToList(T[] array)
Given an array, returns a list.
|
static java.util.List |
asList(java.lang.Object o)
Return a List with the given object.
|
static boolean |
atob(java.lang.String a) |
static int |
atoi(java.lang.String a)
Convert a String value into an unboxed int.
|
static int |
atoi(java.lang.String a,
int def)
Convert a String value into a primitive integer value.
|
static long |
atol(java.lang.String a)
Convert a String value into a primitive long value.
|
static java.lang.String |
capitalize(java.lang.String str)
Capitalizes the first letter in the given String Example: hElLo becomes
HElLo
|
static java.lang.String |
computeDifference(java.util.Date start,
java.util.Date end)
This returns the difference between two dates in parts such as '11 h 58
min 27 s 8 ms'
|
static long |
computeDifferenceMilli(java.util.Date start,
java.util.Date end)
This returns the difference between two dates in milliseconds
|
static java.lang.String |
convertEscapeXMLCharToXmlCharacter(java.lang.String inputString)
This method used to convert XML entity to XML special character
|
static java.util.List<java.lang.String> |
convertStringToList(java.lang.String value,
java.lang.String delimiter)
Function to change string to list taking into any delimiter in
consideration.
|
static java.util.Set<java.lang.String> |
convertStringToSet(java.lang.String value,
java.lang.String delimiter)
Utility function to create set out of delimited string.
|
static java.util.List<java.lang.String> |
csvToList(java.lang.String src)
Convert a comma delimited string into a List of strings.
|
static java.util.List<java.lang.String> |
csvToList(java.lang.String src,
java.lang.String delimiter)
Convert a given delimited string into a List of strings.
|
static java.lang.String |
dateToString(java.util.Date src)
Format a Date value as a String, using the usual "American" format with
the current time zone.
|
static java.lang.String |
dateToString(java.util.Date src,
java.lang.String format) |
static java.lang.String |
dateToString(java.util.Date src,
java.lang.String format,
java.util.TimeZone tz) |
static java.lang.String |
dtoa(double d)
Convert a double to String.
|
static java.lang.String |
escapeMetaCharacters(java.lang.String inputString)
add escape characters to special string
|
static java.lang.String |
escapeXmlSpecialChar(java.lang.String inputString)
This method will convert XML special char to HTML entities, this is useful if
your SOAP/any request is XML based and you want provision below XML special
char in request
& = &
< = <
> = >
" = "
' = '
here we first convert all & to & then again replace & to &
|
static java.lang.String |
expandVariables(java.lang.String src,
java.util.Map<java.lang.String,java.lang.Object> variables)
Process a string which may contain references to variables
and substitute the values of those variables.
|
static <T> java.util.List<T> |
filterNulls(java.util.List<T> src)
Remove all nulls from a list.
|
static java.lang.String |
ftoa(float f)
Convert a float to String.
|
static java.lang.Object |
get(java.util.Map map,
java.lang.String name)
This method get the value of attribute in object.
|
static boolean |
getBoolean(java.util.Map map,
java.lang.String name)
This method to check the value of attribute is boolean or not.
|
static java.util.Date |
getDate(java.lang.Object o)
Try to derive a Date from a random object.
|
static java.lang.String |
getHostName() |
static int |
getInt(java.util.Map map,
java.lang.String name)
This method converts the attribute value into an integer.
|
static java.util.Map<java.lang.String,java.lang.String> |
getJarDetails(java.lang.String jarClass,
java.util.List<java.lang.String> attributes)
Method to get jar details, here we are passing jar class to read the jar path
and list of attributes which need to read from jar's MANIFEST file
|
static java.lang.String |
getLibraryPath(java.lang.Object className)
This method will return base location of JAR from where class it is
loaded
|
static java.lang.String |
getString(java.util.Map map,
java.lang.String name)
Return a map value as a string.
|
static java.lang.String |
getString(java.lang.String s)
Return the given String or null (if the given String is null or
zero-length).
|
static long |
getTimeDiff(java.time.Instant start)
This method get the difference between start and end time
|
static java.lang.Object |
getValueFromMap(java.util.Map map,
java.lang.String name)
This method returns the value for input key from the map.
|
static boolean |
isAnyNullOrEmpty(java.lang.String... vals)
This method check values is null or empty if then return true....
|
static boolean |
isBooleanOrNumberOrList(java.lang.Object attributeValue)
Returns true if Object type either boolean or Number or list
|
static boolean |
isEmpty(java.util.Collection collection)
This method will return true true is the collection is null or empty
|
static boolean |
isEmpty(int[] args)
Returns true if the specified primitive integer array is empty.
|
static boolean |
isEmpty(java.util.Iterator i)
Return true if the specified Iterator is empty.
|
static boolean |
isEmpty(java.util.Map map)
Return true if the specified map is empty.
|
static boolean |
isEmpty(java.lang.Object[] args)
Return true if the specified array is empty.
|
static boolean |
isEmpty(java.lang.String src)
Return true if the specified String is empty.
|
static boolean |
isIdentityNow()
This method tells us if the application is running on identityNow
isIdentityNow is system property we set in CCG main method
and we dont set this in case of identityIQ
|
static boolean |
isInt(java.lang.String str)
Return true if the specified String is an Integer value.
|
static boolean |
isNothing(java.lang.String str)
Return true if the specified String is null or empty.
|
static boolean |
isNotNullOrEmpty(java.lang.String str)
Negative of isNullOrEmpty
|
static boolean |
isNullOrEmpty(java.lang.String str)
This method will return true if the String that is passed is null or
empty
|
static <T> java.lang.Iterable<T> |
iterate(java.lang.Iterable<T> iterable)
Constructs a null-safe iterable for use with for-each loops to avoid null
checking.
|
static java.lang.String |
itoa(int i)
Convert an unboxed int to a String.
|
static java.lang.String |
listToCsv(java.util.List list)
Convert a list of strings into a comma delimited list.
|
static java.lang.String |
listToCsv(java.util.List list,
boolean filterEmpty) |
static java.util.Map |
listToMap(java.util.List<java.lang.String> listOfValues)
This method is to create a map from list of string.
|
static java.lang.String |
listToQuotedCsv(java.util.List list,
java.lang.Character quoteChar,
boolean filterEmpty)
Convert a list of strings into a comma delimited list of Strings wrapped
in the specified type of quote.
|
static java.lang.String |
listToQuotedCsv(java.util.List list,
java.lang.Character quoteChar,
boolean filterEmpty,
boolean conditionallyQuote)
This is similar to listToQuoteCsv but allows the specification of the
conditionally quoted individual values in a csv that have embedded
commas.
|
static java.lang.String |
listToQuotedCsv(java.util.List list,
java.lang.Character quoteChar,
boolean filterEmpty,
boolean conditionallyQuote,
boolean conditionallyAddSpace)
This is similar to listToQuoteCsv but allows the specification of the
conditionally add space char between the csv values.
|
static java.lang.String |
ltoa(long l)
Convert a long to String.
|
static boolean |
nullSafeCaseInsensitiveEq(java.lang.String o1,
java.lang.String o2)
This method performs a null-safe equality comparison between the two
strings.
|
static <T extends java.lang.Comparable> |
nullSafeCompareTo(T o1,
T o2)
Return the compareTo() value for two objects that may be null.
|
static boolean |
nullSafeContains(java.util.List list,
java.lang.Object o)
Check a list for the given object, checking for null on the list.
|
static boolean |
nullSafeEq(java.lang.Object o1,
java.lang.Object o2)
This method performs a null-safe equality comparison between the two
given objects.
|
static boolean |
nullSafeEq(java.lang.Object o1,
java.lang.Object o2,
boolean nullsEq)
This method performs a null-safe equality comparison between the two
given objects.
|
static boolean |
nullSafeEq(java.lang.Object o1,
java.lang.Object o2,
boolean nullsEq,
boolean emptyStringToNull)
This method performs a null-safe equality comparison between the two
given objects.
|
static boolean |
nullSafeEq(java.lang.String s1,
java.lang.String s2)
This method performs a null-safe equality comparison between the two
strings If both objects are null, this returns false.
|
static boolean |
nullSafeEq(java.lang.String s1,
java.lang.String s2,
boolean nullsEq)
This method performs a null-safe equality comparison between the two
strings.
|
static boolean |
otob(java.lang.Object o)
Convert a random object into an unboxed boolean.
|
static int |
otoi(java.lang.Object o)
Convert a random object into an unboxed int.
|
static java.util.List<java.lang.String> |
otol(java.lang.Object o)
Convert an object to a List of Strings.
|
static java.util.List<java.lang.String> |
otolForNonCSVList(java.lang.Object o)
Convert an object to a List of Strings.
|
static java.util.Map<java.lang.String,java.lang.Object> |
otom(java.lang.Object o)
Convert an object to a Map of
|
static java.lang.String |
otos(java.lang.Object o)
Convert an object to its string representation.
|
static <T> java.util.List<java.util.List<T>> |
partition(java.util.Collection<T> members,
int maxSize)
This method partitions the list into number of sublists similar to the partition
method from Google Guava
https://google.github.io/guava/releases/19.0/api/docs/com/google/common/collect/Lists.html#partition(java.util.List,%20int)
|
static java.lang.String |
quoteNameSQLObject(java.lang.String sqlParam)
This function acts like QUOTENAME function in MSsql server.
|
static java.lang.String |
quoteSQLPassword(java.lang.String passwordToQuote)
This method escapes single quote "'" characters in the password string,
if the password contains some.
|
static java.util.List<java.lang.String[]> |
readFile(java.lang.String fileNameWithPath,
java.lang.String delimiter,
boolean skipHeaderOnFirstLine)
Function to read a a file and create a list of all data present in it.
|
static <T> void |
removeDuplicates(java.util.List<T> list)
Remove duplicate items from provided list.
|
static java.lang.String |
replaceCharacter(java.lang.String toReplace,
java.lang.String replaceWith,
java.lang.String str)
Function to replace a charecter with other charecter in any string.
|
static <T> java.lang.Iterable<T> |
safeIterable(java.lang.Iterable<T> iterable)
Constructs a null-safe iterable for use with for-each loops to avoid null
checking.
|
static java.lang.String |
setToCsv(java.util.Set<?> set) |
static int |
size(java.util.Collection c)
Return the size of the given collection.
|
static java.lang.String |
stackToString(java.lang.Throwable th)
Converts the stack trace of an exception to a String
|
static java.util.Date |
stringToDate(java.lang.String src)
Convert the string representation for a date into a Date object.
|
static java.util.List |
stringToList(java.lang.String value)
This function create list from string value
|
static java.lang.String |
trimWhitespace(java.lang.String src)
Trims trailing whitespace from a string.
|
static java.lang.String |
uuid()
Generate a unique identifier.
|
public static java.lang.String uuid()
public static <T> java.util.List<java.util.List<T>> partition(java.util.Collection<T> members,
int maxSize)
members - The full listmaxSize - The max size of the listpublic static java.lang.String capitalize(java.lang.String str)
str - string in need of some capitalizationpublic static int atoi(java.lang.String a)
public static int atoi(java.lang.String a,
int def)
public static int otoi(java.lang.Object o)
public static long atol(java.lang.String a)
public static java.lang.String itoa(int i)
public static java.lang.String ltoa(long l)
public static java.lang.String ftoa(float f)
public static java.lang.String dtoa(double d)
public static boolean otob(java.lang.Object o)
public static java.lang.String otos(java.lang.Object o)
o - The object to convert to a string.public static java.util.List<java.lang.String> otol(java.lang.Object o)
o - Either a List of String or a CSV listpublic static java.util.Map<java.lang.String,java.lang.Object> otom(java.lang.Object o)
o - Mappublic static java.util.List<java.lang.String> otolForNonCSVList(java.lang.Object o)
o - Either a List of String or a plain stringpublic static java.lang.Object getValueFromMap(java.util.Map map,
java.lang.String name)
public static java.util.List<java.lang.String> csvToList(java.lang.String src)
public static java.util.List<java.lang.String> csvToList(java.lang.String src,
java.lang.String delimiter)
src - comma separate stringdelimiter - delimiter used to separate List objectspublic static java.lang.String escapeMetaCharacters(java.lang.String inputString)
inputString - public static java.lang.String listToCsv(java.util.List list)
public static java.lang.String listToCsv(java.util.List list,
boolean filterEmpty)
public static java.lang.String setToCsv(java.util.Set<?> set)
public static java.lang.String listToQuotedCsv(java.util.List list,
java.lang.Character quoteChar,
boolean filterEmpty)
list - List of objects to be converted into a list of stringsquoteChar - Quote character in which to wrap the strings. Can be ', ", or
null. If null is specified no quotes will be appliedfilterEmpty - True to filter blank strings out of the list. False to include
thempublic static java.lang.String listToQuotedCsv(java.util.List list,
java.lang.Character quoteChar,
boolean filterEmpty,
boolean conditionallyQuote)
conditionallyQuote - True prevents ALL strings from being quoted, and instead will
only quote ( escape ) the values that actually contain
embedded commas.Util.listToQuotedCsv(List, Character, boolean)public static java.lang.String listToQuotedCsv(java.util.List list,
java.lang.Character quoteChar,
boolean filterEmpty,
boolean conditionallyQuote,
boolean conditionallyAddSpace)
list - List of objects to be converted into a list of stringsquoteChar - Quote character in which to wrap the strings. Can be ', ", or
null. If null is specified no quotes will be appliedfilterEmpty - True to filter blank strings out of the list. False to include
themconditionallyQuote - If true it prevents ALL strings from being quoted, and instead
will only quote ( escape ) the values that actually contain
embedded commas.conditionallyAddSpace - If true it appends a space before adding the next value.public static int size(java.util.Collection c)
c - The possibly-null collection to get the size of.public static boolean isNullOrEmpty(java.lang.String str)
str - that needs to be checked for null or emptypublic static boolean isNotNullOrEmpty(java.lang.String str)
str - public static boolean isEmpty(java.util.Collection collection)
collection - public static boolean isEmpty(java.util.Iterator i)
i - Iterator being checkedpublic static boolean isEmpty(java.lang.Object[] args)
args - array being checkedpublic static boolean isEmpty(java.util.Map map)
map - Map being checkedpublic static boolean isEmpty(java.lang.String src)
src - String being checkedpublic static boolean isNothing(java.lang.String str)
str - String being checkedpublic static boolean isInt(java.lang.String str)
str - String being checkedpublic static java.util.List asList(java.lang.Object o)
o - The object to return as a list.public static java.lang.String getString(java.lang.String s)
s - The String to filter.public static java.lang.String getString(java.util.Map map,
java.lang.String name)
public static java.util.List<java.lang.String> convertStringToList(java.lang.String value,
java.lang.String delimiter)
value - delimiter - public static java.util.List stringToList(java.lang.String value)
value - value is stringpublic static java.util.Set<java.lang.String> convertStringToSet(java.lang.String value,
java.lang.String delimiter)
value - delimiter - public static java.lang.String replaceCharacter(java.lang.String toReplace,
java.lang.String replaceWith,
java.lang.String str)
toReplace - - Variable to hold the value for the charecter to be replaced.replaceWith - - variable to hold the value for the charecter to which will
replace.str - - A string whose value need to be changed.public static java.util.List<java.lang.String[]> readFile(java.lang.String fileNameWithPath,
java.lang.String delimiter,
boolean skipHeaderOnFirstLine)
throws java.lang.Exception
fileNameWithPath - delimiter - skipHeaderOnFirstLine - java.lang.Exceptionpublic static boolean isBooleanOrNumberOrList(java.lang.Object attributeValue)
attributeValue - object being checkedpublic static java.lang.String quoteSQLPassword(java.lang.String passwordToQuote)
passwordToQuote - public static java.lang.String quoteNameSQLObject(java.lang.String sqlParam)
sqlParam - public static <T> java.lang.Iterable<T> iterate(java.lang.Iterable<T> iterable)
iterable - The iterable to use.public static <T> java.lang.Iterable<T> safeIterable(java.lang.Iterable<T> iterable)
iterable - The iterable to use.public static java.lang.String stackToString(java.lang.Throwable th)
public static boolean atob(java.lang.String a)
public static java.util.Map listToMap(java.util.List<java.lang.String> listOfValues)
listOfValues - list of string values.public static boolean isAnyNullOrEmpty(java.lang.String... vals)
vals - string of value.public static java.lang.Object get(java.util.Map map,
java.lang.String name)
map - Map of values.name - name of attribute to get the value.public static int getInt(java.util.Map map,
java.lang.String name)
map - it is map of arguments of SQL statement.name - Name of attribute.public static boolean getBoolean(java.util.Map map,
java.lang.String name)
map - It is map of arguments of SQL statement.name - Name of attribute.public static java.lang.String trimWhitespace(java.lang.String src)
public static boolean nullSafeCaseInsensitiveEq(java.lang.String o1,
java.lang.String o2)
o1 - first string to compareo2 - second string to comparepublic static <T extends java.lang.Comparable> int nullSafeCompareTo(T o1,
T o2)
public static java.lang.String getHostName()
public static boolean nullSafeEq(java.lang.String s1,
java.lang.String s2,
boolean nullsEq)
s1 - first string to compares2 - second string to comparenullsEq - Whether two null strings should be considered equal.public static boolean nullSafeEq(java.lang.String s1,
java.lang.String s2)
s1 - first string to compares2 - second string to comparepublic static boolean nullSafeContains(java.util.List list,
java.lang.Object o)
list - List to check for objecto - Object to check for in the listpublic static boolean nullSafeEq(java.lang.Object o1,
java.lang.Object o2)
o1 - The first object to compare.o2 - The second object to compare.public static boolean nullSafeEq(java.lang.Object o1,
java.lang.Object o2,
boolean nullsEq)
o1 - The first object to compare.o2 - The second object to compare.nullsEq - Whether two null objects should be considered equal.public static boolean nullSafeEq(java.lang.Object o1,
java.lang.Object o2,
boolean nullsEq,
boolean emptyStringToNull)
public static java.lang.String getLibraryPath(java.lang.Object className)
className - class name of which we need to find path of JARpublic static java.util.Date getDate(java.lang.Object o)
public static java.lang.String dateToString(java.util.Date src)
public static java.lang.String dateToString(java.util.Date src,
java.lang.String format)
public static java.lang.String dateToString(java.util.Date src,
java.lang.String format,
java.util.TimeZone tz)
public static java.util.Date stringToDate(java.lang.String src)
throws java.text.ParseException
M/d/y H:m:s z M/d/y H:m:s M/d/y
java.text.ParseExceptionpublic static long computeDifferenceMilli(java.util.Date start,
java.util.Date end)
throws java.lang.Exception
java.lang.Exceptionpublic static java.lang.String computeDifference(java.util.Date start,
java.util.Date end)
throws java.lang.Exception
java.lang.Exceptionpublic static boolean isIdentityNow()
public static java.lang.String expandVariables(java.lang.String src,
java.util.Map<java.lang.String,java.lang.Object> variables)
If a variable is not defined, it silently expands to nothing.
A variable is referenced with the syntax "$(x)" where "x" is the name of the variable. Values for variables are supplied through a Map.
NOTE: This method has been copied from "sailpoint.tools.Util" and is primarily used
by LDAPConnector, JDBCConnector, PeopleSoftHRMSConnector, HostAccessConnector. It is kept here just to avoid code
duplication.
TODO: In future, move this method out of here to maybe a new utility class since this class is meant for methods that are generic to all connectors.
public static <T> void removeDuplicates(java.util.List<T> list)
public static <T> java.util.List<T> filterNulls(java.util.List<T> src)
public static java.util.Map<java.lang.String,java.lang.String> getJarDetails(java.lang.String jarClass,
java.util.List<java.lang.String> attributes)
throws java.lang.Exception
jarClass - - any class from jar
- Example : com.sap.db.jdbc.Driverattributes - - list of attributes need to read from MANIFEST file
- Example : Implementation-Versionjava.lang.Exception - - we are throwing exception here but safer side at connector level just logged itpublic static <T> java.util.List<T> arrayToList(T[] array)
array - Array to copy to a listpublic static boolean isEmpty(int[] args)
args - integer array being checkedpublic static java.lang.String escapeXmlSpecialChar(java.lang.String inputString)
inputString - - input string to convert charpublic static long getTimeDiff(java.time.Instant start)
start - start timepublic static java.lang.String convertEscapeXMLCharToXmlCharacter(java.lang.String inputString)
inputString - - input string