Class MapUtils

java.lang.Object
org.apache.gravitino.utils.MapUtils

public class MapUtils extends Object
Utility class for working with maps.
  • Method Details

    • getPrefixMap

      public static Map<String,String> getPrefixMap(Map<String,String> m, String prefix)
      Returns a map with all keys that start with the given prefix.
      Parameters:
      m - The map to filter.
      prefix - The prefix to filter by.
      Returns:
      A map with all keys that start with the given prefix.
    • getPrefixMap

      public static Map<String,String> getPrefixMap(Map<String,String> m, String prefix, boolean keepPrefix)
      Returns a map with all keys that start with the given prefix.
      Parameters:
      m - The map to filter.
      prefix - The prefix to filter by.
      keepPrefix - Whether to keep the prefix in the key or not.
      Returns:
      A map with all keys that start with the given prefix.
    • getMapWithoutPrefix

      public static Map<String,String> getMapWithoutPrefix(Map<String,String> m, String prefix)
      Returns a new map containing entries whose keys do NOT start with the given prefix.
      Parameters:
      m - the original map
      prefix - the prefix to exclude
      Returns:
      a filtered map without entries whose keys start with the prefix
    • getFilteredMap

      public static Map<String,String> getFilteredMap(Map<String,String> m, Predicate predicate)
      Returns a map with all keys that match the predicate.
      Parameters:
      m - The map to filter.
      predicate - The predicate expression to filter the keys.
      Returns:
      A map with all keys that match the predicate.
    • unmodifiableMap

      public static Map<String,String> unmodifiableMap(Map<String,String> m)
      Returns an unmodifiable map.
      Parameters:
      m - The map to make unmodifiable.
      Returns:
      An unmodifiable map.
    • propertyAsInt

      public static int propertyAsInt(Map<String,String> properties, String property, int defaultValue)
      Extract an integer value from the properties map with provided key. If provided key not exist in the properties map, it will return default value.
      Parameters:
      properties - input map
      property - provided key
      defaultValue - default value
      Returns:
      integer value from the properties map with provided key.
    • propertyAsLong

      public static long propertyAsLong(Map<String,String> properties, String property, long defaultValue)
      Extract a long value from the properties map with provided key. If provided key not exist in the properties map, it will return default value.
      Parameters:
      properties - input map
      property - provided key
      defaultValue - default value
      Returns:
      long value from the properties map with provided key.