Class MapUtils

java.lang.Object
overit.geocallapp.utilities.datatype.MapUtils

public class MapUtils extends Object
Utility class providing enhanced map operations with null safety and additional functionality beyond standard Java Map methods.

This class provides utility methods for safe map operations, including retrieval of values with default fallbacks and enhanced type safety.

Since:
1.0
  • Constructor Details

    • MapUtils

      public MapUtils()
  • Method Details

    • getOrElse

      public static <K, V> V getOrElse(Map<K,V> map, K key, V defaultValue)
      Retrieves a value from a map or returns a default value if the key is not found or maps to null.

      This method provides a functional programming style alternative to Map.getOrDefault(Object, Object) with additional validation to ensure non-null parameters.

      Type Parameters:
      K - the type of keys maintained by the map
      V - the type of mapped values
      Parameters:
      map - the map from which to retrieve the value (must not be null)
      key - the key whose associated value is to be returned (must not be null)
      defaultValue - the default value to return if the key is not found or maps to null
      Returns:
      the value associated with the key, or the default value if the key is not found or maps to null
      Since:
      1.0