Class MapUtils

java.lang.Object
com.jbstrap.core.utils.MapUtils

public final class MapUtils extends Object
Map handling utility methods
Since:
4.0
Author:
JBStrap
  • Method Details

    • getElementFromIndex

      public static <K, V> Map.Entry<K,V> getElementFromIndex(Map<K,V> input, Integer index)
      Gets an element of a map, based on the specified index
      Type Parameters:
      K - The map key type
      V - The map value type
      Parameters:
      input - The source map
      index - The index of the element
      Returns:
      The map element corresponding to the specified index, or null if not found
    • putElementAtIndex

      public static <K, V> void putElementAtIndex(Map<K,V> input, Integer index, Map.Entry<K,V> entry)
      Places an element in the specified map, by the specified index. The values after the specified index will be shifted by one position.
      Type Parameters:
      K - The map key type
      V - The map value type
      Parameters:
      input - The map where the element will be inserted
      index - The index of the element
      entry - The element that will be inserted
    • putElementAtIndex

      public static <K, V> void putElementAtIndex(Map<K,V> input, Integer index, K key, V value)
      Places an element in the specified map, by the specified index. The values after the specified index will be shifted by one position.
      Type Parameters:
      K - The map key type
      V - The map value type
      Parameters:
      input - The map where the element will be inserted
      index - The index of the element
      key - The key of the element that will be inserted
      value - The value of the element that will be inserted
    • moveMapElement

      public static <K, V> void moveMapElement(Map<K,V> input, Integer sourceIndex, Integer targetIndex)
      Moves the specified map element to another position
      Type Parameters:
      K - The map key type
      V - The map value type
      Parameters:
      input - The source map that has the element that needs to be moved
      sourceIndex - The source index of the element
      targetIndex - The target index where the element will be moved to