Package org.apache.ofbiz.base.util
Class UtilMisc
- java.lang.Object
-
- org.apache.ofbiz.base.util.UtilMisc
-
public final class UtilMisc extends java.lang.Object
UtilMisc - Misc Utility Functions
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
module
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <K> java.math.BigDecimal
addToBigDecimalInMap(java.util.Map<K,java.lang.Object> theMap, K mapKey, java.math.BigDecimal addNumber)
Assuming theMap not null; if null will throw a NullPointerExceptionstatic <K> void
addToDoubleInMap(java.util.Map<K,java.lang.Object> theMap, K key, java.lang.Double value)
Adds value to the key entry in theMap, or creates a new one if not already therestatic <K,V>
voidaddToListInMap(V element, java.util.Map<K,java.lang.Object> theMap, K listKey)
static <K,V>
voidaddToSetInMap(V element, java.util.Map<K,java.util.Set<V>> theMap, K setKey)
static <K,V>
voidaddToSortedSetInMap(V element, java.util.Map<K,java.util.Set<V>> theMap, K setKey)
static java.util.List<java.util.Locale>
availableLocales()
Returns a List of available locales sorted by display namestatic <T> java.util.Set<T>
collectionToSet(java.util.Collection<T> c)
static java.lang.String
collectionToString(java.util.Collection<? extends java.lang.Object> values, java.lang.String delimiter)
Generates a String from given values delimited by delimiter.static <T> int
compare(java.lang.Comparable<T> obj1, T obj2)
static <E> int
compare(java.util.List<E> obj1, java.util.List<E> obj2)
static void
copyFile(java.io.File sourceLocation, java.io.File targetLocation)
static java.util.Locale
ensureLocale(java.lang.Object localeObject)
The input can be a String, Locale, or even null and a valid Locale will always be returned; if nothing else works, returns the default locale.static java.util.List<java.lang.String>
getHostHeadersAllowed()
List of domains or IP addresses to be checked to prevent Host Header Injection, no spaces after commas,no wildcard, can be extended of course...static <K,V>
java.util.List<V>getListFromMap(java.util.Map<K,java.lang.Object> outerMap, K key)
Assuming outerMap not null; if null will throw a NullPointerExceptionstatic <K,IK,V>
java.util.Map<IK,V>getMapFromMap(java.util.Map<K,java.lang.Object> outerMap, K key)
Assuming outerMap not null; if null will throw a NullPointerExceptionstatic int
getViewLastIndex(int listSize, int viewSize)
static <T extends java.lang.Throwable>
TinitCause(T throwable, java.lang.Throwable cause)
static <V> void
makeArrayListSerializable(java.util.ArrayList<java.lang.Object> arrayList)
This change an ArrayList to be Serializable by removing all entries that are not Serializable.static <T> java.util.List<T>
makeListWritable(java.util.Collection<? extends T> col)
static <V> void
makeMapSerializable(java.util.Map<java.lang.String,V> map)
This change a Map to be Serializable by removing all entries with values that are not Serializable.static <K,V>
java.util.Map<K,V>makeMapWritable(java.util.Map<K,? extends V> map)
static <T> java.util.Set<T>
makeSetWritable(java.util.Collection<? extends T> col)
static java.util.Locale
parseLocale(java.lang.String localeString)
Parse a locale string Locale objectstatic <K,V>
java.lang.StringprintMap(java.util.Map<? extends K,? extends V> theMap)
static <T> T
removeFirst(java.util.List<T> lst)
static java.util.List<java.util.Map<java.lang.Object,java.lang.Object>>
sortMaps(java.util.List<java.util.Map<java.lang.Object,java.lang.Object>> listOfMaps, java.util.List<? extends java.lang.String> sortKeys)
Sort a List of Maps by specified consistent keys.static java.util.Map<java.lang.String,java.lang.String>
splitPhoneNumber(java.lang.String phoneNumber, Delegator delegator)
static void
staticWait(long timeout)
Deprecated.use Thread.sleep()static double
toDouble(java.lang.Object obj)
Converts anObject
to adouble
.static java.lang.Double
toDoubleObject(java.lang.Object obj)
Converts anObject
to aDouble
.static int
toInteger(java.lang.Object obj)
Converts anObject
to anint
.static java.lang.Integer
toIntegerObject(java.lang.Object obj)
Converts anObject
to anInteger
.static <T> java.util.Iterator<T>
toIterator(java.util.Collection<T> col)
Get an iterator from a collection, returning null if collection is nullstatic <T> java.util.List<T>
toList(java.util.Collection<T> collection)
static <T> java.util.List<T>
toList(T... data)
Creates a list from passed objects.static <T> java.util.List<T>
toListArray(T[] data)
static long
toLong(java.lang.Object obj)
Converts anObject
to along
.static java.lang.Long
toLongObject(java.lang.Object obj)
Converts anObject
to aLong
.static <K,V>
java.util.Map<K,V>toMap(java.lang.Object... kvs)
Creates a pseudo-literal map corresponding to key-values.static <K,V>
java.util.Map<K,V>toMap(java.util.function.Supplier<java.util.Map<K,V>> constructor, java.lang.Object... kvs)
Creates a pseudo-literal map corresponding to key-values.static <T> java.util.Set<T>
toSet(java.util.Collection<T> collection)
static <T> java.util.Set<T>
toSet(T... data)
Create a set from the passed objects.static <T> java.util.Set<T>
toSetArray(T[] data)
-
-
-
Method Detail
-
initCause
public static final <T extends java.lang.Throwable> T initCause(T throwable, java.lang.Throwable cause)
-
compare
public static <T> int compare(java.lang.Comparable<T> obj1, T obj2)
-
compare
public static <E> int compare(java.util.List<E> obj1, java.util.List<E> obj2)
-
toIterator
public static <T> java.util.Iterator<T> toIterator(java.util.Collection<T> col)
Get an iterator from a collection, returning null if collection is null- Parameters:
col
- The collection to be turned in to an iterator- Returns:
- The resulting Iterator
-
toMap
public static <K,V> java.util.Map<K,V> toMap(java.lang.Object... kvs)
Creates a pseudo-literal map corresponding to key-values.- Parameters:
kvs
- the key-value pairs- Returns:
- the corresponding map.
- Throws:
java.lang.IllegalArgumentException
- when the key-value list is not even.
-
toMap
public static <K,V> java.util.Map<K,V> toMap(java.util.function.Supplier<java.util.Map<K,V>> constructor, java.lang.Object... kvs)
Creates a pseudo-literal map corresponding to key-values.- Parameters:
constructor
- the constructor used to instantiate the mapkvs
- the key-value pairs- Returns:
- the corresponding map.
- Throws:
java.lang.IllegalArgumentException
- when the key-value list is not even.
-
printMap
public static <K,V> java.lang.String printMap(java.util.Map<? extends K,? extends V> theMap)
-
makeListWritable
public static <T> java.util.List<T> makeListWritable(java.util.Collection<? extends T> col)
-
makeMapWritable
public static <K,V> java.util.Map<K,V> makeMapWritable(java.util.Map<K,? extends V> map)
-
makeSetWritable
public static <T> java.util.Set<T> makeSetWritable(java.util.Collection<? extends T> col)
-
makeMapSerializable
public static <V> void makeMapSerializable(java.util.Map<java.lang.String,V> map)
This change a Map to be Serializable by removing all entries with values that are not Serializable.- Type Parameters:
V
-- Parameters:
map
-
-
makeArrayListSerializable
public static <V> void makeArrayListSerializable(java.util.ArrayList<java.lang.Object> arrayList)
This change an ArrayList to be Serializable by removing all entries that are not Serializable.- Parameters:
arrayList
-
-
sortMaps
public static java.util.List<java.util.Map<java.lang.Object,java.lang.Object>> sortMaps(java.util.List<java.util.Map<java.lang.Object,java.lang.Object>> listOfMaps, java.util.List<? extends java.lang.String> sortKeys)
Sort a List of Maps by specified consistent keys.- Parameters:
listOfMaps
- List of Map objects to sort.sortKeys
- List of Map keys to sort by.- Returns:
- a new List of sorted Maps.
-
getMapFromMap
public static <K,IK,V> java.util.Map<IK,V> getMapFromMap(java.util.Map<K,java.lang.Object> outerMap, K key)
Assuming outerMap not null; if null will throw a NullPointerException
-
getListFromMap
public static <K,V> java.util.List<V> getListFromMap(java.util.Map<K,java.lang.Object> outerMap, K key)
Assuming outerMap not null; if null will throw a NullPointerException
-
addToBigDecimalInMap
public static <K> java.math.BigDecimal addToBigDecimalInMap(java.util.Map<K,java.lang.Object> theMap, K mapKey, java.math.BigDecimal addNumber)
Assuming theMap not null; if null will throw a NullPointerException
-
removeFirst
public static <T> T removeFirst(java.util.List<T> lst)
-
collectionToSet
public static <T> java.util.Set<T> collectionToSet(java.util.Collection<T> c)
-
collectionToString
public static java.lang.String collectionToString(java.util.Collection<? extends java.lang.Object> values, java.lang.String delimiter)
Generates a String from given values delimited by delimiter.- Parameters:
values
-delimiter
-- Returns:
- String
-
toSet
@SafeVarargs public static <T> java.util.Set<T> toSet(T... data)
Create a set from the passed objects.- Parameters:
data
-- Returns:
- theSet
-
toSet
public static <T> java.util.Set<T> toSet(java.util.Collection<T> collection)
-
toSetArray
public static <T> java.util.Set<T> toSetArray(T[] data)
-
toList
@SafeVarargs public static <T> java.util.List<T> toList(T... data)
Creates a list from passed objects.- Parameters:
data
-- Returns:
- list
-
toList
public static <T> java.util.List<T> toList(java.util.Collection<T> collection)
-
toListArray
public static <T> java.util.List<T> toListArray(T[] data)
-
addToListInMap
public static <K,V> void addToListInMap(V element, java.util.Map<K,java.lang.Object> theMap, K listKey)
-
addToSetInMap
public static <K,V> void addToSetInMap(V element, java.util.Map<K,java.util.Set<V>> theMap, K setKey)
-
addToSortedSetInMap
public static <K,V> void addToSortedSetInMap(V element, java.util.Map<K,java.util.Set<V>> theMap, K setKey)
-
toDouble
public static double toDouble(java.lang.Object obj)
Converts anObject
to adouble
. Returns zero if conversion is not possible.- Parameters:
obj
- Object to convert- Returns:
- double value
-
toDoubleObject
public static java.lang.Double toDoubleObject(java.lang.Object obj)
Converts anObject
to aDouble
. Returnsnull
if conversion is not possible.- Parameters:
obj
- Object to convert- Returns:
- Double
-
toInteger
public static int toInteger(java.lang.Object obj)
Converts anObject
to anint
. Returns zero if conversion is not possible.- Parameters:
obj
- Object to convert- Returns:
- int value
-
toIntegerObject
public static java.lang.Integer toIntegerObject(java.lang.Object obj)
Converts anObject
to anInteger
. Returnsnull
if conversion is not possible.- Parameters:
obj
- Object to convert- Returns:
- Integer
-
toLong
public static long toLong(java.lang.Object obj)
Converts anObject
to along
. Returns zero if conversion is not possible.- Parameters:
obj
- Object to convert- Returns:
- long value
-
toLongObject
public static java.lang.Long toLongObject(java.lang.Object obj)
Converts anObject
to aLong
. Returnsnull
if conversion is not possible.- Parameters:
obj
- Object to convert- Returns:
- Long
-
addToDoubleInMap
public static <K> void addToDoubleInMap(java.util.Map<K,java.lang.Object> theMap, K key, java.lang.Double value)
Adds value to the key entry in theMap, or creates a new one if not already there- Parameters:
theMap
-key
-value
-
-
parseLocale
public static java.util.Locale parseLocale(java.lang.String localeString)
Parse a locale string Locale object- Parameters:
localeString
- The locale string (en_US)- Returns:
- Locale The new Locale object or null if no valid locale can be interpreted
-
ensureLocale
public static java.util.Locale ensureLocale(java.lang.Object localeObject)
The input can be a String, Locale, or even null and a valid Locale will always be returned; if nothing else works, returns the default locale.- Parameters:
localeObject
- An Object representing the locale
-
availableLocales
public static java.util.List<java.util.Locale> availableLocales()
Returns a List of available locales sorted by display name
-
getHostHeadersAllowed
public static java.util.List<java.lang.String> getHostHeadersAllowed()
List of domains or IP addresses to be checked to prevent Host Header Injection, no spaces after commas,no wildcard, can be extended of course...- Returns:
- List of domains or IP addresses to be checked to prevent Host Header Injection,
-
staticWait
@Deprecated public static void staticWait(long timeout) throws java.lang.InterruptedException
Deprecated.use Thread.sleep()- Throws:
java.lang.InterruptedException
-
copyFile
public static void copyFile(java.io.File sourceLocation, java.io.File targetLocation) throws java.io.IOException
- Throws:
java.io.IOException
-
getViewLastIndex
public static int getViewLastIndex(int listSize, int viewSize)
-
splitPhoneNumber
public static java.util.Map<java.lang.String,java.lang.String> splitPhoneNumber(java.lang.String phoneNumber, Delegator delegator)
-
-