Package de.mhus.lib.core
Class MCollection
- java.lang.Object
-
- de.mhus.lib.core.MCollection
-
public class MCollection extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static List<?>EMPTY_LIST
-
Constructor Summary
Constructors Constructor Description MCollection()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> voidaddAll(List<T> list, T[] items)static <T> voidaddAll(Set<T> list, T[] items)static Stringappend(String list, char separator, String item)Append the item to the end of the list using the separator.static <T> T[]append(T[] array, T... newElements)static booleancontains(Object[] array, Object item)Returns true of array is not null and the value of item is included in the array.static booleancontains(String list, char separator, String item)Returns true if the given item is part of the list.static <T> voidcopyArray(T[] array, Collection<T> list)Fills a list at the end with the values of an array, ignoring null values.static <T> T[]cropArray(T[] from, int start, int stop)Cut a part from an array and create a new array with the values.static booleanequals(byte[] nr1, byte[] nr2)static booleanequals(char[] nr1, char[] nr2)static booleanequals(double[] nr1, double[] nr2)static booleanequals(int[] nr1, int[] nr2)static booleanequals(Object[] nr1, Object[] nr2)static <T> T[]extendArray(T[] from, int left, int right)static int[]fillIntArray(int from, int to)static <T> voidforEach(T[] array, Consumer<T> consumer)Execute the consumer for each entry of the array.static <T extends List<?>>
TgetEmptyList()static <T> T[]insert(T[] array, int index, T... newElements)static booleanisAllNull(Object[] array)static booleanisEmpty(Object[] array)static booleanisEmpty(Collection<?> col)static booleanisEmpty(Map<?,?> map)static booleanisSet(Object[] array)static booleanisSet(Collection<?> col)static booleanisSet(Map<?,?> map)static <T> Iterable<T>iterate(Iterator<T> iterator)static int[]order(int[] array, boolean unique)static long[]order(long[] array, boolean unique)static Stringremove(String list, char separator, String item)Remove the given item from the list once.static <T> T[]remove(T[] array, int offset, int len)static <T> voidremoveDuplicates(List<T> list)remove duplicated entriesstatic <T> voidremoveDuplicates(List<T> list, Comparator<T> comparator)remove duplicated entries, Attention exponential runtime behavior !!! Running from beginning to the end, the first element will be left, following removed.static <T> Tsearch(Iterable<T> iter, Predicate<? super T> filter)Search for an entry and return it use the filter to find it.static Stringset(String list, char separator, String item)Append the item to the end of the list using the separator if not already exists.static <K> List<K>sorted(List<K> in)If sort is possible (instance of Comparable) the function will create a new instance of list, copy and sort all the entries from the source into the new list and returns the created list.static <K> List<K>sorted(List<K> in, Comparator<K> comp)The function will create a new instance of list, copy and sort all the entries from the source into the new list and returns the created list.static <K,V>
Map<K,V>sorted(Map<K,V> in)Returns a new instance of Map with sorted keys.static <K,V>
Map<K,V>sorted(Map<K,V> in, Comparator<K> comp)static <T> HashSet<T>toHashSet(T[] items)static <T> List<T>toList(Collection<? extends T> set)static <T> List<T>toList(T[] array)static Map<String,Object>toLowerCaseKeys(Map<String,Object> parameters)Create a new map and convert all string keys to lower case.static <T> List<T>toReadOnlyList(List<? extends T> in)static <T> Set<T>toSet(Collection<? extends T> list)static Map<String,String>toStringMap(IProperties in, boolean ignoreNull)static Map<String,String>toStringMap(Map<Object,Object> in, boolean ignoreNull)static <T> TreeSet<T>toTreeSet(T[] items)static <T> voidupdateEach(T[] array, Function<T,T> manipulator)Process for each entry in the array.
-
-
-
Field Detail
-
EMPTY_LIST
public static final List<?> EMPTY_LIST
-
-
Method Detail
-
contains
public static boolean contains(Object[] array, Object item)
Returns true of array is not null and the value of item is included in the array. It compares with the equals() method of the array item. Also a item value of null will be compared.- Parameters:
array-item-- Returns:
- true if contains the item
-
copyArray
public static <T> void copyArray(T[] array, Collection<T> list)Fills a list at the end with the values of an array, ignoring null values.- Parameters:
array-list-
-
removeDuplicates
public static <T> void removeDuplicates(List<T> list)
remove duplicated entries- Parameters:
list-
-
removeDuplicates
public static <T> void removeDuplicates(List<T> list, Comparator<T> comparator)
remove duplicated entries, Attention exponential runtime behavior !!! Running from beginning to the end, the first element will be left, following removed.- Parameters:
list-comparator-
-
append
@SafeVarargs public static <T> T[] append(T[] array, T... newElements)
-
insert
@SafeVarargs public static <T> T[] insert(T[] array, int index, T... newElements)
-
remove
public static <T> T[] remove(T[] array, int offset, int len)
-
order
public static int[] order(int[] array, boolean unique)
-
order
public static long[] order(long[] array, boolean unique)
-
fillIntArray
public static int[] fillIntArray(int from, int to)
-
toStringMap
public static Map<String,String> toStringMap(Map<Object,Object> in, boolean ignoreNull)
-
toStringMap
public static Map<String,String> toStringMap(IProperties in, boolean ignoreNull)
-
toList
public static <T> List<T> toList(T[] array)
-
toTreeSet
public static <T> TreeSet<T> toTreeSet(T[] items)
-
toHashSet
public static <T> HashSet<T> toHashSet(T[] items)
-
addAll
public static <T> void addAll(List<T> list, T[] items)
-
addAll
public static <T> void addAll(Set<T> list, T[] items)
-
getEmptyList
public static <T extends List<?>> T getEmptyList()
-
toList
public static <T> List<T> toList(Collection<? extends T> set)
-
toSet
public static <T> Set<T> toSet(Collection<? extends T> list)
-
contains
public static boolean contains(String list, char separator, String item)
Returns true if the given item is part of the list. The list itself is a char separated list of items. White spaces are not allowed! The search is case sensitive.- Parameters:
list- The list of itemsseparator- The separator between the list itemsitem- The searched item- Returns:
- true if the item is part of the list
-
append
public static String append(String list, char separator, String item)
Append the item to the end of the list using the separator. If list is empty the item will be the first element.- Parameters:
list- The list of itemsseparator- The item separatoritem- New item to append- Returns:
- The new list
-
set
public static String set(String list, char separator, String item)
Append the item to the end of the list using the separator if not already exists. If list is empty the item will be the first element.- Parameters:
list- The list of itemsseparator- The item separatoritem- New item to append- Returns:
- The new list
-
remove
public static String remove(String list, char separator, String item)
Remove the given item from the list once.- Parameters:
list- List of itemsseparator- Separator between the itemsitem- The item to remove- Returns:
- New list with removed item
-
sorted
public static <K,V> Map<K,V> sorted(Map<K,V> in)
Returns a new instance of Map with sorted keys.- Parameters:
in-- Returns:
- a new sorted map
-
sorted
public static <K> List<K> sorted(List<K> in)
If sort is possible (instance of Comparable) the function will create a new instance of list, copy and sort all the entries from the source into the new list and returns the created list. If the list could not be sorted the original list object will be returned.- Parameters:
in-- Returns:
- A new sorted list
-
sorted
public static <K,V> Map<K,V> sorted(Map<K,V> in, Comparator<K> comp)
-
sorted
public static <K> List<K> sorted(List<K> in, Comparator<K> comp)
The function will create a new instance of list, copy and sort all the entries from the source into the new list and returns the created list.- Parameters:
in-comp-- Returns:
- A new sorted list
-
updateEach
public static <T> void updateEach(T[] array, Function<T,T> manipulator)Process for each entry in the array. Return the new value for each entry.- Parameters:
array-manipulator-
-
forEach
public static <T> void forEach(T[] array, Consumer<T> consumer)Execute the consumer for each entry of the array.- Parameters:
array-consumer-
-
isEmpty
public static boolean isEmpty(Collection<?> col)
-
isEmpty
public static boolean isEmpty(Map<?,?> map)
-
isSet
public static boolean isSet(Collection<?> col)
-
isSet
public static boolean isSet(Map<?,?> map)
-
isEmpty
public static boolean isEmpty(Object[] array)
-
isSet
public static boolean isSet(Object[] array)
-
isAllNull
public static boolean isAllNull(Object[] array)
-
toLowerCaseKeys
public static Map<String,Object> toLowerCaseKeys(Map<String,Object> parameters)
Create a new map and convert all string keys to lower case.- Parameters:
parameters-- Returns:
- map with lower case keys
-
equals
public static boolean equals(byte[] nr1, byte[] nr2)
-
equals
public static boolean equals(int[] nr1, int[] nr2)
-
equals
public static boolean equals(double[] nr1, double[] nr2)
-
equals
public static boolean equals(char[] nr1, char[] nr2)
-
cropArray
public static <T> T[] cropArray(T[] from, int start, int stop)Cut a part from an array and create a new array with the values.- Parameters:
from-start-stop-- Returns:
- new cropped array
-
extendArray
public static <T> T[] extendArray(T[] from, int left, int right)- Parameters:
from-left-right-- Returns:
- new extended array
-
-