Class UtilMisc

java.lang.Object
org.apache.ofbiz.base.util.UtilMisc

public final class UtilMisc extends Object
UtilMisc - Misc Utility Functions
  • Method Details

    • initCause

      public static <T extends Throwable> T initCause(T throwable, Throwable cause)
    • compare

      public static <T> int compare(Comparable<T> obj1, T obj2)
    • compare

      public static <E> int compare(List<E> obj1, List<E> obj2)
    • toIterator

      public static <T> Iterator<T> toIterator(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> Map<K,V> toMap(Object... kvs)
      Creates a pseudo-literal map corresponding to key-values.
      Parameters:
      kvs - the key-value pairs
      Returns:
      the corresponding map.
      Throws:
      IllegalArgumentException - when the key-value list is not even.
    • toMap

      public static <K, V> Map<K,V> toMap(Supplier<Map<K,V>> constructor, Object... kvs)
      Creates a pseudo-literal map corresponding to key-values.
      Parameters:
      constructor - the constructor used to instantiate the map
      kvs - the key-value pairs
      Returns:
      the corresponding map.
      Throws:
      IllegalArgumentException - when the key-value list is not even.
    • printMap

      public static <K, V> String printMap(Map<? extends K,? extends V> theMap)
    • makeListWritable

      public static <T> List<T> makeListWritable(Collection<? extends T> col)
    • makeMapWritable

      public static <K, V> Map<K,V> makeMapWritable(Map<K,? extends V> map)
    • makeMapSerializable

      public static <V> void makeMapSerializable(Map<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(ArrayList<Object> arrayList)
      This change an ArrayList to be Serializable by removing all entries that are not Serializable.
      Parameters:
      arrayList -
    • sortMaps

      public static List<Map<Object,Object>> sortMaps(List<Map<Object,Object>> listOfMaps, List<? extends 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> Map<IK,V> getMapFromMap(Map<K,Object> outerMap, K key)
      Assuming outerMap not null; if null will throw a NullPointerException
    • getListFromMap

      public static <K, V> List<V> getListFromMap(Map<K,Object> outerMap, K key)
      Assuming outerMap not null; if null will throw a NullPointerException
    • addToBigDecimalInMap

      public static <K> BigDecimal addToBigDecimalInMap(Map<K,Object> theMap, K mapKey, BigDecimal addNumber)
      Assuming theMap not null; if null will throw a NullPointerException
    • removeFirst

      public static <T> T removeFirst(List<T> lst)
    • collectionToSet

      public static <T> Set<T> collectionToSet(Collection<T> c)
    • collectionToString

      public static String collectionToString(Collection<? extends Object> values, String delimiter)
      Generates a String from given values delimited by delimiter.
      Parameters:
      values -
      delimiter -
      Returns:
      String
    • toSet

      @SafeVarargs public static <T> Set<T> toSet(T... data)
      Create a set from the passed objects.
      Parameters:
      data -
      Returns:
      theSet
    • toSet

      public static <T> Set<T> toSet(Collection<T> collection)
    • toSetArray

      public static <T> Set<T> toSetArray(T[] data)
    • toList

      @SafeVarargs public static <T> List<T> toList(T... data)
      Creates a list from passed objects.
      Parameters:
      data -
      Returns:
      list
    • toListArray

      public static <T> List<T> toListArray(T[] data)
    • addToListInMap

      public static <K, V> void addToListInMap(V element, Map<K,Object> theMap, K listKey)
    • addToSetInMap

      public static <K, V> void addToSetInMap(V element, Map<K,Set<V>> theMap, K setKey)
    • addToSortedSetInMap

      public static <K, V> void addToSortedSetInMap(V element, Map<K,Set<V>> theMap, K setKey)
    • toDouble

      public static double toDouble(Object obj)
      Converts an Object to a double. Returns zero if conversion is not possible.
      Parameters:
      obj - Object to convert
      Returns:
      double value
    • toDoubleObject

      public static Double toDoubleObject(Object obj)
      Converts an Object to a Double. Returns null if conversion is not possible.
      Parameters:
      obj - Object to convert
      Returns:
      Double
    • toInteger

      public static int toInteger(Object obj)
      Converts an Object to an int. Returns zero if conversion is not possible.
      Parameters:
      obj - Object to convert
      Returns:
      int value
    • toIntegerObject

      public static Integer toIntegerObject(Object obj)
      Converts an Object to an Integer. Returns null if conversion is not possible.
      Parameters:
      obj - Object to convert
      Returns:
      Integer
    • toLong

      public static long toLong(Object obj)
      Converts an Object to a long. Returns zero if conversion is not possible.
      Parameters:
      obj - Object to convert
      Returns:
      long value
    • toLongObject

      public static Long toLongObject(Object obj)
      Converts an Object to a Long. Returns null if conversion is not possible.
      Parameters:
      obj - Object to convert
      Returns:
      Long
    • addToDoubleInMap

      public static <K> void addToDoubleInMap(Map<K,Object> theMap, K key, 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 Locale parseLocale(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 Locale ensureLocale(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 List<Locale> availableLocales()
      Returns a List of available locales sorted by display name
    • getHostHeadersAllowed

      public static List<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 InterruptedException
      Deprecated.
      use Thread.sleep()
      Throws:
      InterruptedException
    • copyFile

      public static void copyFile(File sourceLocation, File targetLocation) throws IOException
      Throws:
      IOException
    • getViewLastIndex

      public static int getViewLastIndex(int listSize, int viewSize)
    • splitPhoneNumber

      public static Map<String,String> splitPhoneNumber(String phoneNumber, Delegator delegator)