Package com.evolveum.midpoint.util
Class MiscUtil
- java.lang.Object
-
- com.evolveum.midpoint.util.MiscUtil
-
public class MiscUtil extends Object
- Author:
- semancik
-
-
Constructor Summary
Constructors Constructor Description MiscUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> void
addAllIfNotPresent(List<T> receivingList, List<T> supplyingList)
static <T> void
addIfNotPresent(List<T> receivingList, T supplyingElement)
static Boolean
and(Boolean... operands)
n-ary and that ignores null values.static Date
asDate(int year, int month, int date, int hrs, int min, int sec)
static Date
asDate(XMLGregorianCalendar xgc)
Converts an XMLGregorianCalendar to an instance of java.util.Datestatic Long
asLong(XMLGregorianCalendar xgc)
static XMLGregorianCalendar
asXMLGregorianCalendar(Long timeInMilis)
static XMLGregorianCalendar
asXMLGregorianCalendar(Date date)
Converts a java.util.Date into an instance of XMLGregorianCalendarstatic String
binaryToHex(byte[] bytes)
static <T> void
carthesian(Collection<Collection<T>> dimensions, Processor<Collection<T>> processor)
static <K,V>
Map<K,V>cloneMap(Map<K,V> orig)
Shallow clonestatic Integer
compareNullLast(Object o1, Object o2)
static String
concat(Collection<String> stringCollection)
static <T> boolean
contains(T element, T[] array)
static void
copyDirectory(File src, File dst)
Copy a directory and its contents.static void
copyFile(File sourceFile, File destFile)
static <T> Collection<T>
createCollection(T... items)
static String
emptyIfNull(String s)
static <T> Collection<T>
emptyIfNull(Collection<T> collection)
static <T> List<T>
emptyIfNull(List<T> list)
static boolean
equals(Object a, Object b)
static String
expandProperties(String value)
static <T> T
extractSingleton(Collection<T> collection)
static <T> Collection<T>
filter(Collection<T> input, Predicate<? super T> predicate)
static <T> Set<T>
filter(Set<T> input, Predicate<? super T> predicate)
static String
formatExceptionMessageWithCause(Throwable t)
static String
formatExceptionMessageWithCause(Throwable t, int indent)
static String
getClass(Object object)
static <T> T
getFirstNonNull(T... values)
static String
getFirstNonNullString(Object... values)
static String
getObjectName(Object o)
static <T> T
getSingleValue(Collection<T> values, T defaultValue, String contextDescription)
static <T> Collection<T>
getValuesFromDisplayableValues(Collection<? extends DisplayableValue<T>> disps)
static String
getValueWithClass(Object object)
static <T> boolean
hasDuplicates(Collection<T> collection)
Returns true if the collection contains at least one pair of equals elements.static boolean
hasNoValue(Collection<?> collection)
static byte[]
hexToBinary(String hex)
static String
hexToUtf8String(String hex)
static <E> Function<Object,Stream<E>>
instancesOf(Class<E> cls)
static boolean
isAllNull(Collection<?> collection)
static boolean
isBetween(XMLGregorianCalendar date, XMLGregorianCalendar start, XMLGregorianCalendar end)
static boolean
isCollectionOf(Object object, Class<?> memberClass)
static boolean
isNoValue(Collection<?> collection)
static <T> List<T>
join(Collection<T> a, Collection<T> b)
static <T> T
last(List<T> list)
static <T> boolean
listEquals(List<T> a, List<T> b)
static <V> Collection<V>
nonNullValues(Collection<V> values)
static boolean
nullableCollectionsEqual(Collection<?> c1, Collection<?> c2)
static String
nullIfEmpty(String s)
static <K,V>
Map<K,V>paramsToMap(Object[] params)
static String
readFile(File file)
static String
readZipFile(File file, Charset charset)
static <T> T
runChecked(CheckedFunction<Producer<T>,T> function, CheckedProducer<T> checkedProducer)
static List<String>
splitLines(String string)
static <T> Stream<T>
streamOf(Collection<T> collection)
static String
stripHtmlMarkup(String htmlString)
static String
takeThreadDump(Thread thread)
Thanks for this code go to https://crunchify.com/how-to-generate-java-thread-dump-programmatically/static void
throwExceptionAsUnchecked(Throwable t)
static String
toString(Object o)
static URL
toUrlUnchecked(URI uri)
static <T> Collection<T>
union(Collection<T>... sets)
static <T> Collection<? extends T>
unionExtends(Collection<? extends T>... sets)
static <T> boolean
unorderedArrayEquals(T[] a, T[] b)
static <T> boolean
unorderedArrayEquals(T[] a, T[] b, Comparator<T> comparator)
Only zero vs non-zero value of comparator is important.static <T> boolean
unorderedCollectionCompare(Collection<T> a, Collection<T> b, Comparator<T> comparator)
Only zero vs non-zero value of comparator is important.static <A,B>
booleanunorderedCollectionEquals(Collection<A> a, Collection<B> b, HeteroComparator<A,B> comparator)
Only zero vs non-zero value of comparator is important.static <T> boolean
unorderedCollectionEquals(Collection<T> a, Collection<T> b)
static <T> int
unorderedCollectionHashcode(Collection<T> collection, Predicate<T> filter)
static <T> T
unwrapTunnelledException(TunnelException te)
static void
writeZipFile(File file, String entryName, String content, Charset charset)
-
-
-
Method Detail
-
union
@NotNull public static <T> Collection<T> union(Collection<T>... sets)
-
unionExtends
public static <T> Collection<? extends T> unionExtends(Collection<? extends T>... sets)
-
unorderedCollectionEquals
public static <T> boolean unorderedCollectionEquals(Collection<T> a, Collection<T> b)
-
unorderedCollectionCompare
public static <T> boolean unorderedCollectionCompare(Collection<T> a, Collection<T> b, Comparator<T> comparator)
Only zero vs non-zero value of comparator is important.
-
unorderedCollectionEquals
public static <A,B> boolean unorderedCollectionEquals(Collection<A> a, Collection<B> b, HeteroComparator<A,B> comparator)
Only zero vs non-zero value of comparator is important.
-
unorderedArrayEquals
public static <T> boolean unorderedArrayEquals(T[] a, T[] b)
-
unorderedArrayEquals
public static <T> boolean unorderedArrayEquals(T[] a, T[] b, Comparator<T> comparator)
Only zero vs non-zero value of comparator is important.
-
unorderedCollectionHashcode
public static <T> int unorderedCollectionHashcode(Collection<T> collection, Predicate<T> filter)
-
readFile
public static String readFile(File file) throws IOException
- Throws:
IOException
-
copyFile
public static void copyFile(File sourceFile, File destFile) throws IOException
- Throws:
IOException
-
copyDirectory
public static void copyDirectory(File src, File dst) throws IOException
Copy a directory and its contents.- Parameters:
src
- The name of the directory to copy.dst
- The name of the destination directory.- Throws:
IOException
- If the directory could not be copied.
-
createCollection
@SafeVarargs public static <T> Collection<T> createCollection(T... items)
-
asXMLGregorianCalendar
public static XMLGregorianCalendar asXMLGregorianCalendar(Date date)
Converts a java.util.Date into an instance of XMLGregorianCalendar- Parameters:
date
- Instance of java.util.Date or a null reference- Returns:
- XMLGregorianCalendar instance whose value is based upon the value in the date parameter. If the date parameter is null then this method will simply return null.
-
asXMLGregorianCalendar
public static XMLGregorianCalendar asXMLGregorianCalendar(Long timeInMilis)
-
asDate
public static Date asDate(XMLGregorianCalendar xgc)
Converts an XMLGregorianCalendar to an instance of java.util.Date- Parameters:
xgc
- Instance of XMLGregorianCalendar or a null reference- Returns:
- java.util.Date instance whose value is based upon the value in the xgc parameter. If the xgc parameter is null then this method will simply return null.
-
asLong
public static Long asLong(XMLGregorianCalendar xgc)
-
asDate
public static Date asDate(int year, int month, int date, int hrs, int min, int sec)
-
carthesian
public static <T> void carthesian(Collection<Collection<T>> dimensions, Processor<Collection<T>> processor)
-
concat
public static String concat(Collection<String> stringCollection)
-
isAllNull
public static boolean isAllNull(Collection<?> collection)
-
isNoValue
public static boolean isNoValue(Collection<?> collection)
-
hasNoValue
public static boolean hasNoValue(Collection<?> collection)
-
isBetween
public static boolean isBetween(XMLGregorianCalendar date, XMLGregorianCalendar start, XMLGregorianCalendar end)
-
contains
public static <T> boolean contains(T element, T[] array)
-
getValuesFromDisplayableValues
public static <T> Collection<T> getValuesFromDisplayableValues(Collection<? extends DisplayableValue<T>> disps)
-
binaryToHex
public static String binaryToHex(byte[] bytes)
-
hexToBinary
public static byte[] hexToBinary(String hex)
-
addAllIfNotPresent
public static <T> void addAllIfNotPresent(List<T> receivingList, List<T> supplyingList)
-
addIfNotPresent
public static <T> void addIfNotPresent(List<T> receivingList, T supplyingElement)
-
nullableCollectionsEqual
public static boolean nullableCollectionsEqual(Collection<?> c1, Collection<?> c2)
-
getFirstNonNull
@SafeVarargs public static <T> T getFirstNonNull(T... values)
-
extractSingleton
public static <T> T extractSingleton(Collection<T> collection)
-
getSingleValue
public static <T> T getSingleValue(Collection<T> values, T defaultValue, String contextDescription)
-
last
public static <T> T last(List<T> list)
-
emptyIfNull
@NotNull public static <T> Collection<T> emptyIfNull(Collection<T> collection)
-
streamOf
@NotNull public static <T> Stream<T> streamOf(Collection<T> collection)
-
hasDuplicates
public static <T> boolean hasDuplicates(Collection<T> collection)
Returns true if the collection contains at least one pair of equals elements.
-
formatExceptionMessageWithCause
public static String formatExceptionMessageWithCause(Throwable t, int indent)
-
throwExceptionAsUnchecked
public static void throwExceptionAsUnchecked(Throwable t)
-
runChecked
public static <T> T runChecked(CheckedFunction<Producer<T>,T> function, CheckedProducer<T> checkedProducer) throws CommonException
- Throws:
CommonException
-
unwrapTunnelledException
public static <T> T unwrapTunnelledException(TunnelException te) throws CommonException
- Throws:
CommonException
-
filter
public static <T> Collection<T> filter(Collection<T> input, Predicate<? super T> predicate)
-
nonNullValues
@NotNull public static <V> Collection<V> nonNullValues(@NotNull Collection<V> values)
-
join
public static <T> List<T> join(Collection<T> a, Collection<T> b)
-
takeThreadDump
public static String takeThreadDump(@Nullable Thread thread)
Thanks for this code go to https://crunchify.com/how-to-generate-java-thread-dump-programmatically/
-
writeZipFile
public static void writeZipFile(File file, String entryName, String content, Charset charset) throws IOException
- Throws:
IOException
-
readZipFile
public static String readZipFile(File file, Charset charset) throws IOException
- Throws:
IOException
-
-