Package de.alpharogroup.collections.map
Class MapExtensions
- java.lang.Object
-
- de.alpharogroup.collections.map.MapExtensions
-
public final class MapExtensions extends java.lang.ObjectExtensions class for use with Map objects.
-
-
Constructor Summary
Constructors Constructor Description MapExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
KgetKeyFromValue(@NonNull java.util.Map<K,V> map, V value)Returns the first founded key from the given value or null if nothing is found.static <K,V>
java.util.Collection<K>getKeysFromValue(@NonNull java.util.Map<K,V> map, V value)Returns a Collection from all founded keys from the given value or null if nothing found.static <K,V extends java.lang.Comparable<? super V>>
java.util.Map<K,V>sortByValue(@NonNull java.util.Map<K,V> map, boolean reversed)Sort the given Map by its values and returns a sorted list by the values of the given Mapstatic <K,V extends java.lang.Comparable<? super V>>
java.util.Map<K,V>sortByValue(@NonNull java.util.Map<K,V> map, @NonNull java.util.Comparator<? super V> comparator)Sort the given Map by its values and returns a sorted list by the values of the given Mapstatic <K,V extends java.lang.Comparable<? super V>>
java.util.List<java.util.Map.Entry<K,V>>sortByValueAsList(@NonNull java.util.Map<K,V> map, boolean reversed)Sort the given Map by its values and returns a sorted list by the values of the given Mapstatic <K,V extends java.lang.Comparable<? super V>>
java.util.List<java.util.Map.Entry<K,V>>sortByValueAsList(@NonNull java.util.Map<K,V> map, @NonNull java.util.Comparator<? super V> comparator)Sort the given Map by its values and returns a sorted list by the values of the given Mapstatic <T> java.util.Map<T,T>toGenericMap(@NonNull T[][] twoDimArray)Converts a two dimensional Array to a Map.static java.util.Map<java.lang.String,java.lang.String>toMap(java.lang.String[][] twoDimArray)Converts a two dimensional String Array to a Map.
-
-
-
Method Detail
-
sortByValueAsList
public static <K,V extends java.lang.Comparable<? super V>> java.util.List<java.util.Map.Entry<K,V>> sortByValueAsList(@NonNull @NonNull java.util.Map<K,V> map, boolean reversed)Sort the given Map by its values and returns a sorted list by the values of the given Map- Type Parameters:
K- the generic type of the keyV- the generic type of the value- Parameters:
map- The Map to sortreversed- the flag if the result should be in reversed order- Returns:
- a sorted list by the values of the given Map
-
sortByValueAsList
public static <K,V extends java.lang.Comparable<? super V>> java.util.List<java.util.Map.Entry<K,V>> sortByValueAsList(@NonNull @NonNull java.util.Map<K,V> map, @NonNull @NonNull java.util.Comparator<? super V> comparator)Sort the given Map by its values and returns a sorted list by the values of the given Map- Type Parameters:
K- the generic type of the keyV- the generic type of the value- Parameters:
map- The Map to sortcomparator- the comparator to sort- Returns:
- a sorted list by the values of the given Map
-
sortByValue
public static <K,V extends java.lang.Comparable<? super V>> java.util.Map<K,V> sortByValue(@NonNull @NonNull java.util.Map<K,V> map, boolean reversed)Sort the given Map by its values and returns a sorted list by the values of the given Map- Type Parameters:
K- the generic type of the keyV- the generic type of the value- Parameters:
map- the Map to sortreversed- the flag if the result should be in reversed order- Returns:
- a sorted Map by the values of the given Map
-
sortByValue
public static <K,V extends java.lang.Comparable<? super V>> java.util.Map<K,V> sortByValue(@NonNull @NonNull java.util.Map<K,V> map, @NonNull @NonNull java.util.Comparator<? super V> comparator)Sort the given Map by its values and returns a sorted list by the values of the given Map- Type Parameters:
K- the generic type of the keyV- the generic type of the value- Parameters:
map- the Map to sortcomparator- the comparator to sort- Returns:
- a sorted Map by the values of the given Map
-
getKeyFromValue
public static <K,V> K getKeyFromValue(@NonNull @NonNull java.util.Map<K,V> map, V value)Returns the first founded key from the given value or null if nothing is found.- Type Parameters:
K- the generic type of the keyV- the generic type of the value- Parameters:
map- The Map.value- The value.- Returns:
- Returns the first key from the given value or null if nothing found.
-
getKeysFromValue
public static <K,V> java.util.Collection<K> getKeysFromValue(@NonNull @NonNull java.util.Map<K,V> map, V value)Returns a Collection from all founded keys from the given value or null if nothing found.- Type Parameters:
K- the generic type of the keyV- the generic type of the value- Parameters:
map- The Map.value- The value.- Returns:
- Returns the key from the given value or an empty Collection if nothing found.
-
toGenericMap
public static <T> java.util.Map<T,T> toGenericMap(@NonNull @NonNull T[][] twoDimArray)Converts a two dimensional Array to a Map.- Type Parameters:
T- the generic type- Parameters:
twoDimArray- The two dimensional Array.- Returns:
- The map produced from the two dimensional Array.
-
toMap
public static java.util.Map<java.lang.String,java.lang.String> toMap(java.lang.String[][] twoDimArray)
Converts a two dimensional String Array to a Map.- Parameters:
twoDimArray- The two dimensional String Array.- Returns:
- The map produced from the two dimensional String Array.
-
-