Tag Provider, list to array function, surface builder fix

This commit is contained in:
paulevsGitch 2021-12-04 11:16:13 +03:00
parent f8eb65d600
commit 7f17e1261c
6 changed files with 52 additions and 8 deletions

View file

@ -1,5 +1,6 @@
package ru.bclib.util;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@ -13,7 +14,7 @@ public class CollectionsUtil {
* @param list {@link List} to make mutable.
* @return {@link ArrayList} or original {@link List} if it is mutable.
*/
public static <E extends Object> List<E> getMutable(List<E> list) {
public static <E> List<E> getMutable(List<E> list) {
if (list instanceof ArrayList) {
return list;
}
@ -25,7 +26,7 @@ public class CollectionsUtil {
* @param set {@link Set} to make mutable.
* @return {@link HashSet} or original {@link Set} if it is mutable.
*/
public static <E extends Object> Set<E> getMutable(Set<E> set) {
public static <E> Set<E> getMutable(Set<E> set) {
if (set instanceof HashSet) {
return set;
}
@ -37,10 +38,24 @@ public class CollectionsUtil {
* @param map {@link Map} to make mutable.
* @return {@link HashMap} or original {@link Map} if it is mutable.
*/
public static <K extends Object, V extends Object> Map<K, V> getMutable(Map<K, V> map) {
public static <K, V> Map<K, V> getMutable(Map<K, V> map) {
if (map instanceof HashMap) {
return map;
}
return new HashMap<>(map);
}
/**
* Converts list into array.
* @param list {@link List} to convert.
* @return array of list elements. If list is empty will return empty {@link Object} array.
*/
public static <E> E[] toArray(List<E> list) {
if (list.isEmpty()) {
return (E[]) new Object[0];
}
E[] result = (E[]) Array.newInstance(list.get(0).getClass(), list.size());
result = list.toArray(result);
return result;
};
}