Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (C) 2014-2015 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.commons.collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.PresentForCodeCoverage;
import com.helger.commons.annotation.ReturnsImmutableObject;
import com.helger.commons.annotation.ReturnsMutableCopy;
import com.helger.commons.annotation.ReturnsMutableObject;
import com.helger.commons.collection.impl.ComparatorMapEntryKey;
import com.helger.commons.collection.impl.ComparatorMapEntryKeyComparable;
import com.helger.commons.collection.impl.ComparatorMapEntryValue;
import com.helger.commons.collection.impl.ComparatorMapEntryValueComparable;
import com.helger.commons.collection.impl.EmptySortedSet;
import com.helger.commons.collection.impl.NonBlockingStack;
import com.helger.commons.collection.iterate.CombinedIterator;
import com.helger.commons.collection.iterate.EmptyEnumeration;
import com.helger.commons.collection.iterate.EmptyIterator;
import com.helger.commons.collection.iterate.EnumerationFromIterator;
import com.helger.commons.collection.iterate.IIterableIterator;
import com.helger.commons.collection.iterate.IterableIteratorFromEnumeration;
import com.helger.commons.collection.iterate.ReverseListIterator;
import com.helger.commons.collection.multimap.IMultiMap;
import com.helger.commons.collection.multimap.IMultiMapSetBased;
import com.helger.commons.collection.multimap.MultiHashMapHashSetBased;
import com.helger.commons.compare.ComparatorComparable;
import com.helger.commons.compare.ESortOrder;
import com.helger.commons.lang.ClassHelper;
import com.helger.commons.state.EChange;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* Provides various helper methods to handle collections like {@link List},
* {@link Set} and {@link Map}.
*
* @author Philip Helger
*/
@Immutable
public final class CollectionHelper
{
@PresentForCodeCoverage
private static final CollectionHelper s_aInstance = new CollectionHelper ();
private CollectionHelper ()
{}
@Nullable
public static ECollectionBaseType getCollectionBaseTypeOfClass (@Nullable final Class > aClass)
{
if (aClass != null)
{
// Query Set before Collection, because Set is derived from Collection!
if (Set.class.isAssignableFrom (aClass))
return ECollectionBaseType.SET;
if (Collection.class.isAssignableFrom (aClass))
return ECollectionBaseType.COLLECTION;
if (Map.class.isAssignableFrom (aClass))
return ECollectionBaseType.MAP;
if (ClassHelper.isArrayClass (aClass))
return ECollectionBaseType.ARRAY;
if (Iterator.class.isAssignableFrom (aClass))
return ECollectionBaseType.ITERATOR;
if (Iterable.class.isAssignableFrom (aClass))
return ECollectionBaseType.ITERABLE;
if (Enumeration.class.isAssignableFrom (aClass))
return ECollectionBaseType.ENUMERATION;
}
return null;
}
@Nullable
public static ECollectionBaseType getCollectionBaseTypeOfObject (@Nullable final Object aObj)
{
return aObj == null ? null : getCollectionBaseTypeOfClass (aObj.getClass ());
}
public static boolean isCollectionClass (@Nullable final Class > aClass)
{
return getCollectionBaseTypeOfClass (aClass) != null;
}
public static boolean isCollectionObject (@Nullable final Object aObj)
{
return getCollectionBaseTypeOfObject (aObj) != null;
}
/**
* Get the passed object as a {@link List} object. This is helpful in case you
* want to compare the String array ["a", "b"] with the List<String>
* ("a", "b") If the passed object is not a recognized. container type, than a
* new list with one element is created!
*
* @param aObj
* The object to be converted. May not be null.
* @return The object as a collection. Never null.
*/
@Nonnull
public static List > getAsList (@Nonnull final Object aObj)
{
ValueEnforcer.notNull (aObj, "Object");
final ECollectionBaseType eType = getCollectionBaseTypeOfObject (aObj);
if (eType == null)
{
// It's not a supported container -> create a new list with one element
return newList (aObj);
}
switch (eType)
{
case COLLECTION:
// It's already a collection
if (aObj instanceof List >)
return (List >) aObj;
return newList ((Collection >) aObj);
case SET:
// Convert to list
return newList ((Set >) aObj);
case MAP:
// Use the entry set of the map as list
return newList (((Map , ?>) aObj).entrySet ());
case ARRAY:
// Convert the array to a list
return newList ((Object []) aObj);
case ITERATOR:
// Convert the iterator to a list
return newList ((Iterator >) aObj);
case ITERABLE:
// Convert the iterable to a list
return newList ((Iterable >) aObj);
case ENUMERATION:
// Convert the enumeration to a list
return newList ((Enumeration >) aObj);
default:
throw new IllegalStateException ("Unhandled collection type " + eType + "!");
}
}
@Nonnull
public static List extends ELEMENTTYPE> getNotNull (@Nullable final List extends ELEMENTTYPE> aList)
{
return aList == null ? CollectionHelper. newList () : aList;
}
@Nonnull
public static Set extends ELEMENTTYPE> getNotNull (@Nullable final Set extends ELEMENTTYPE> aSet)
{
return aSet == null ? CollectionHelper. newSet () : aSet;
}
@Nonnull
public static > SortedSet extends ELEMENTTYPE> getNotNull (@Nullable final SortedSet extends ELEMENTTYPE> aSortedSet)
{
return aSortedSet == null ? CollectionHelper. newSortedSet () : aSortedSet;
}
@Nonnull
public static Map extends KEYTYPE, ? extends VALUETYPE> getNotNull (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> aMap)
{
return aMap == null ? CollectionHelper. newMap () : aMap;
}
@Nonnull
public static , VALUETYPE> SortedMap extends KEYTYPE, ? extends VALUETYPE> getNotNull (@Nullable final SortedMap extends KEYTYPE, ? extends VALUETYPE> aSortedMap)
{
return aSortedMap == null ? CollectionHelper. newSortedMap () : aSortedMap;
}
@Nullable
@ReturnsImmutableObject
public static Collection makeUnmodifiable (@Nullable final Collection extends ELEMENTTYPE> aCollection)
{
return aCollection == null ? null : Collections.unmodifiableCollection (aCollection);
}
@Nullable
@ReturnsImmutableObject
public static List makeUnmodifiable (@Nullable final List extends ELEMENTTYPE> aList)
{
return aList == null ? null : Collections.unmodifiableList (aList);
}
@Nullable
@ReturnsImmutableObject
public static Set makeUnmodifiable (@Nullable final Set extends ELEMENTTYPE> aSet)
{
return aSet == null ? null : Collections.unmodifiableSet (aSet);
}
@Nullable
@ReturnsImmutableObject
public static Map makeUnmodifiable (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> aMap)
{
return aMap == null ? null : Collections.unmodifiableMap (aMap);
}
@Nullable
@ReturnsImmutableObject
public static > SortedSet makeUnmodifiable (@Nullable final SortedSet aSortedSet)
{
return aSortedSet == null ? null : Collections.unmodifiableSortedSet (aSortedSet);
}
@Nullable
@ReturnsImmutableObject
public static SortedMap makeUnmodifiable (@Nullable final SortedMap aSortedMap)
{
return aSortedMap == null ? null : Collections.unmodifiableSortedMap (aSortedMap);
}
@Nonnull
@ReturnsImmutableObject
public static Collection makeUnmodifiableNotNull (@Nullable final Collection extends ELEMENTTYPE> aCollection)
{
return aCollection == null ? CollectionHelper. newUnmodifiableList ()
: Collections.unmodifiableCollection (aCollection);
}
@Nonnull
@ReturnsImmutableObject
public static List makeUnmodifiableNotNull (@Nullable final List extends ELEMENTTYPE> aList)
{
return aList == null ? CollectionHelper. newUnmodifiableList () : Collections.unmodifiableList (aList);
}
@Nonnull
@ReturnsImmutableObject
public static Set makeUnmodifiableNotNull (@Nullable final Set extends ELEMENTTYPE> aSet)
{
return aSet == null ? CollectionHelper. newUnmodifiableSet () : Collections.unmodifiableSet (aSet);
}
@Nonnull
@ReturnsImmutableObject
public static Map makeUnmodifiableNotNull (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> aMap)
{
return aMap == null ? CollectionHelper. newUnmodifiableMap ()
: Collections.unmodifiableMap (aMap);
}
@Nonnull
@ReturnsImmutableObject
public static > SortedSet makeUnmodifiableNotNull (@Nullable final SortedSet aSortedSet)
{
return aSortedSet == null ? CollectionHelper. newUnmodifiableSortedSet ()
: Collections.unmodifiableSortedSet (aSortedSet);
}
@Nonnull
@ReturnsImmutableObject
public static , VALUETYPE> SortedMap makeUnmodifiableNotNull (@Nullable final SortedMap aSortedMap)
{
return Collections.unmodifiableSortedMap (aSortedMap == null ? CollectionHelper. newSortedMap ()
: aSortedMap);
}
/**
* Get all elements that are only contained in the first contained, and not in
* the second. This method implements aCont1 - aCont2.
*
* @param
* Set element type
* @param aCollection1
* The first container. May be null or empty.
* @param aCollection2
* The second container. May be null or empty.
* @return The difference and never null. Returns an empty set,
* if the first container is empty. Returns a copy of the first
* container, if the second container is empty. Returns
* aCont1 - aCont2 if both containers are non-empty.
*/
@Nullable
@ReturnsMutableCopy
public static Set getDifference (@Nullable final Collection extends ELEMENTTYPE> aCollection1,
@Nullable final Collection extends ELEMENTTYPE> aCollection2)
{
if (isEmpty (aCollection1))
return newSet ();
if (isEmpty (aCollection2))
return newSet (aCollection1);
final Set ret = newSet (aCollection1);
ret.removeAll (aCollection2);
return ret;
}
/**
* Get all elements that are contained in the first AND in the second
* container.
*
* @param
* Collection element type
* @param aCollection1
* The first container. May be null or empty.
* @param aCollection2
* The second container. May be null or empty.
* @return An empty set, if either the first or the second container are
* empty. Returns a set of elements that are contained in both
* containers, if both containers are non-empty. The return value is
* never null.
*/
@Nullable
@ReturnsMutableCopy
public static Set getIntersected (@Nullable final Collection extends ELEMENTTYPE> aCollection1,
@Nullable final Collection extends ELEMENTTYPE> aCollection2)
{
if (isEmpty (aCollection1))
return newSet ();
if (isEmpty (aCollection2))
return newSet ();
final Set ret = newSet (aCollection1);
ret.retainAll (aCollection2);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Map newMap ()
{
return new HashMap (0);
}
@Nonnull
@ReturnsMutableCopy
public static Map newMap (@Nullable final KEYTYPE aKey,
@Nullable final VALUETYPE aValue)
{
final Map ret = new HashMap (1);
ret.put (aKey, aValue);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Map newMap (@Nullable final ELEMENTTYPE... aValues)
{
if (ArrayHelper.isEmpty (aValues))
return new HashMap (0);
if ((aValues.length % 2) != 0)
throw new IllegalArgumentException ("The passed array needs an even number of elements!");
final Map ret = new HashMap (aValues.length / 2);
for (int i = 0; i < aValues.length; i += 2)
ret.put (aValues[i], aValues[i + 1]);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Map newMap (@Nullable final KEYTYPE [] aKeys,
@Nullable final VALUETYPE [] aValues)
{
// Are both empty?
if (ArrayHelper.isEmpty (aKeys) && ArrayHelper.isEmpty (aValues))
return new HashMap (0);
// keys OR values may be null here
if (ArrayHelper.getSize (aKeys) != ArrayHelper.getSize (aValues))
throw new IllegalArgumentException ("The passed arrays have different length!");
final Map ret = new HashMap (aKeys.length);
for (int i = 0; i < aKeys.length; ++i)
ret.put (aKeys[i], aValues[i]);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Map newMap (@Nullable final Collection extends KEYTYPE> aKeys,
@Nullable final Collection extends VALUETYPE> aValues)
{
// Are both empty?
if (isEmpty (aKeys) && isEmpty (aValues))
return new HashMap (0);
// keys OR values may be null here
if (getSize (aKeys) != getSize (aValues))
throw new IllegalArgumentException ("Number of keys is different from number of values");
final Map ret = new HashMap (aKeys.size ());
final Iterator extends KEYTYPE> itk = aKeys.iterator ();
final Iterator extends VALUETYPE> itv = aValues.iterator ();
while (itk.hasNext ())
ret.put (itk.next (), itv.next ());
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Map newMap (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> aMap)
{
if (isEmpty (aMap))
return new HashMap (0);
return new HashMap (aMap);
}
@Nonnull
@ReturnsMutableCopy
public static Map newMap (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> [] aMaps)
{
if (aMaps == null || aMaps.length == 0)
return new HashMap (0);
final Map ret = new HashMap ();
for (final Map extends KEYTYPE, ? extends VALUETYPE> aMap : aMaps)
ret.putAll (aMap);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Map newMap (@Nullable final Collection extends Map.Entry > aCollection)
{
if (isEmpty (aCollection))
return new HashMap (0);
final Map ret = new HashMap (aCollection.size ());
for (final Map.Entry aEntry : aCollection)
ret.put (aEntry.getKey (), aEntry.getValue ());
return ret;
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableMap ()
{
return Collections. emptyMap ();
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableMap (@Nullable final KEYTYPE aKey,
@Nullable final VALUETYPE aValue)
{
return Collections.singletonMap (aKey, aValue);
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableMap (@Nullable final ELEMENTTYPE... aValues)
{
return makeUnmodifiable (newMap (aValues));
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableMap (@Nullable final KEYTYPE [] aKeys,
@Nullable final VALUETYPE [] aValues)
{
return makeUnmodifiable (newMap (aKeys, aValues));
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableMap (@Nullable final Collection extends KEYTYPE> aKeys,
@Nullable final Collection extends VALUETYPE> aValues)
{
return makeUnmodifiable (newMap (aKeys, aValues));
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableMap (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> aMap)
{
return makeUnmodifiable (aMap);
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableMap (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> [] aMaps)
{
return makeUnmodifiable (newMap (aMaps));
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableMap (@Nullable final Collection extends Map.Entry > aCollection)
{
return makeUnmodifiable (newMap (aCollection));
}
@Nonnull
@ReturnsMutableCopy
public static Map newOrderedMap ()
{
return new LinkedHashMap (0);
}
@Nonnull
@ReturnsMutableCopy
public static Map newOrderedMap (@Nullable final KEYTYPE aKey,
@Nullable final VALUETYPE aValue)
{
final Map ret = new LinkedHashMap (1);
ret.put (aKey, aValue);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Map newOrderedMap (@Nullable final ELEMENTTYPE... aValues)
{
if (ArrayHelper.isEmpty (aValues))
return new LinkedHashMap (0);
if ((aValues.length % 2) != 0)
throw new IllegalArgumentException ("The passed array needs an even number of elements!");
final Map ret = new LinkedHashMap (aValues.length / 2);
for (int i = 0; i < aValues.length; i += 2)
ret.put (aValues[i], aValues[i + 1]);
return ret;
}
/**
* Retrieve a map that is ordered in the way the parameter arrays are passed
* in. Note that key and value arrays need to have the same length.
*
* @param
* The key type.
* @param
* The value type.
* @param aKeys
* The key array to use. May not be null.
* @param aValues
* The value array to use. May not be null.
* @return A {@link java.util.LinkedHashMap} containing the passed key-value
* entries. Never null.
*/
@Nonnull
@ReturnsMutableCopy
public static Map newOrderedMap (@Nullable final KEYTYPE [] aKeys,
@Nullable final VALUETYPE [] aValues)
{
// Are both empty?
if (ArrayHelper.isEmpty (aKeys) && ArrayHelper.isEmpty (aValues))
return new LinkedHashMap (0);
// keys OR values may be null here
if (ArrayHelper.getSize (aKeys) != ArrayHelper.getSize (aValues))
throw new IllegalArgumentException ("The passed arrays have different length!");
final Map ret = new LinkedHashMap (aKeys.length);
for (int i = 0; i < aKeys.length; ++i)
ret.put (aKeys[i], aValues[i]);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Map newOrderedMap (@Nullable final Collection extends KEYTYPE> aKeys,
@Nullable final Collection extends VALUETYPE> aValues)
{
// Are both empty?
if (isEmpty (aKeys) && isEmpty (aValues))
return new LinkedHashMap (0);
// keys OR values may be null here
if (getSize (aKeys) != getSize (aValues))
throw new IllegalArgumentException ("Number of keys is different from number of values");
final Map ret = new LinkedHashMap (aKeys.size ());
final Iterator extends KEYTYPE> itk = aKeys.iterator ();
final Iterator extends VALUETYPE> itv = aValues.iterator ();
while (itk.hasNext ())
ret.put (itk.next (), itv.next ());
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Map newOrderedMap (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> aMap)
{
if (isEmpty (aMap))
return new LinkedHashMap (0);
return new LinkedHashMap (aMap);
}
@Nonnull
@ReturnsMutableCopy
public static Map newOrderedMap (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> [] aMaps)
{
if (aMaps == null || aMaps.length == 0)
return new LinkedHashMap (0);
final Map ret = new LinkedHashMap ();
for (final Map extends KEYTYPE, ? extends VALUETYPE> aMap : aMaps)
ret.putAll (aMap);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Map newOrderedMap (@Nullable final Collection extends Map.Entry > aCollection)
{
if (isEmpty (aCollection))
return new LinkedHashMap (0);
final Map ret = new LinkedHashMap (aCollection.size ());
for (final Map.Entry aEntry : aCollection)
ret.put (aEntry.getKey (), aEntry.getValue ());
return ret;
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableOrderedMap ()
{
return Collections. emptyMap ();
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableOrderedMap (@Nullable final KEYTYPE aKey,
@Nullable final VALUETYPE aValue)
{
return Collections.singletonMap (aKey, aValue);
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableOrderedMap (@Nullable final ELEMENTTYPE... aValues)
{
return makeUnmodifiable (newOrderedMap (aValues));
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableOrderedMap (@Nullable final KEYTYPE [] aKeys,
@Nullable final VALUETYPE [] aValues)
{
return makeUnmodifiable (newOrderedMap (aKeys, aValues));
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableOrderedMap (@Nullable final Collection extends KEYTYPE> aKeys,
@Nullable final Collection extends VALUETYPE> aValues)
{
return makeUnmodifiable (newOrderedMap (aKeys, aValues));
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableOrderedMap (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> aOrderedMap)
{
return makeUnmodifiable (aOrderedMap);
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableOrderedMap (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> [] aOrderedMaps)
{
return makeUnmodifiable (newOrderedMap (aOrderedMaps));
}
@Nonnull
@ReturnsImmutableObject
public static Map newUnmodifiableOrderedMap (@Nullable final Collection extends Map.Entry > aCollection)
{
return makeUnmodifiable (newOrderedMap (aCollection));
}
@Nonnull
@ReturnsMutableCopy
public static , VALUETYPE> TreeMap newSortedMap ()
{
return new TreeMap (new ComparatorComparable ());
}
@Nonnull
@ReturnsMutableCopy
public static , VALUETYPE> TreeMap newSortedMap (@Nullable final KEYTYPE aKey,
@Nullable final VALUETYPE aValue)
{
final TreeMap ret = new TreeMap (new ComparatorComparable ());
ret.put (aKey, aValue);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static > TreeMap newSortedMap (@Nullable final ELEMENTTYPE... aValues)
{
if (ArrayHelper.isEmpty (aValues))
return new TreeMap (new ComparatorComparable ());
if ((aValues.length % 2) != 0)
throw new IllegalArgumentException ("The passed array needs an even number of elements!");
final TreeMap ret = new TreeMap (new ComparatorComparable ());
for (int i = 0; i < aValues.length; i += 2)
ret.put (aValues[i], aValues[i + 1]);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static , VALUETYPE> TreeMap newSortedMap (@Nullable final KEYTYPE [] aKeys,
@Nullable final VALUETYPE [] aValues)
{
// Are both empty?
if (ArrayHelper.isEmpty (aKeys) && ArrayHelper.isEmpty (aValues))
return new TreeMap (new ComparatorComparable ());
// keys OR values may be null here
if (ArrayHelper.getSize (aKeys) != ArrayHelper.getSize (aValues))
throw new IllegalArgumentException ("The passed arrays have different length!");
final TreeMap ret = new TreeMap (new ComparatorComparable ());
for (int i = 0; i < aKeys.length; ++i)
ret.put (aKeys[i], aValues[i]);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static , VALUETYPE> TreeMap newSortedMap (@Nullable final Collection extends KEYTYPE> aKeys,
@Nullable final Collection extends VALUETYPE> aValues)
{
// Are both empty?
if (isEmpty (aKeys) && isEmpty (aValues))
return new TreeMap (new ComparatorComparable ());
// keys OR values may be null here
if (getSize (aKeys) != getSize (aValues))
throw new IllegalArgumentException ("Number of keys is different from number of values");
final TreeMap ret = new TreeMap (new ComparatorComparable ());
final Iterator extends KEYTYPE> itk = aKeys.iterator ();
final Iterator extends VALUETYPE> itv = aValues.iterator ();
while (itk.hasNext ())
ret.put (itk.next (), itv.next ());
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static , VALUETYPE> TreeMap newSortedMap (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> aMap)
{
if (isEmpty (aMap))
return new TreeMap (new ComparatorComparable ());
final TreeMap ret = new TreeMap (new ComparatorComparable ());
ret.putAll (aMap);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static , VALUETYPE> TreeMap newSortedMap (@Nullable final Map extends KEYTYPE, ? extends VALUETYPE> [] aMaps)
{
if (aMaps == null || aMaps.length == 0)
return new TreeMap (new ComparatorComparable ());
final TreeMap ret = new TreeMap (new ComparatorComparable ());
for (final Map extends KEYTYPE, ? extends VALUETYPE> aMap : aMaps)
ret.putAll (aMap);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static , VALUETYPE> TreeMap newSortedMap (@Nullable final Collection extends Map.Entry > aCollection)
{
if (isEmpty (aCollection))
return new TreeMap (new ComparatorComparable ());
final TreeMap ret = new TreeMap (new ComparatorComparable ());
for (final Map.Entry aEntry : aCollection)
ret.put (aEntry.getKey (), aEntry.getValue ());
return ret;
}
@Nonnull
@ReturnsImmutableObject
public static , VALUETYPE> SortedMap newUnmodifiableSortedMap ()
{
return makeUnmodifiable (CollectionHelper. newSortedMap ());
}
@Nonnull
@ReturnsImmutableObject
public static , VALUETYPE> SortedMap newUnmodifiableSortedMap (@Nullable final KEYTYPE aKey,
@Nullable final VALUETYPE aValue)
{
return makeUnmodifiable (newSortedMap (aKey, aValue));
}
@Nonnull
@ReturnsImmutableObject
public static > SortedMap newUnmodifiableSortedMap (@Nullable final ELEMENTTYPE... aValues)
{
return makeUnmodifiable (newSortedMap (aValues));
}
@Nonnull
@ReturnsImmutableObject
public static , VALUETYPE> SortedMap newUnmodifiableSortedMap (@Nullable final KEYTYPE [] aKeys,
@Nullable final VALUETYPE [] aValues)
{
return makeUnmodifiable (newSortedMap (aKeys, aValues));
}
@Nonnull
@ReturnsImmutableObject
public static , VALUETYPE> SortedMap newUnmodifiableSortedMap (@Nullable final Collection extends KEYTYPE> aKeys,
@Nullable final Collection extends VALUETYPE> aValues)
{
return makeUnmodifiable (newSortedMap (aKeys, aValues));
}
@Nonnull
@ReturnsImmutableObject
public static , VALUETYPE> SortedMap newUnmodifiableSortedMap (@Nullable final SortedMap aMap)
{
return makeUnmodifiable (aMap);
}
@Nonnull
@ReturnsImmutableObject
public static , VALUETYPE> SortedMap newUnmodifiableSortedMap (@Nullable final Map [] aMaps)
{
return makeUnmodifiable (newSortedMap (aMaps));
}
@Nonnull
@ReturnsImmutableObject
public static , VALUETYPE> SortedMap newUnmodifiableSortedMap (@Nullable final Collection extends Map.Entry > aCollection)
{
return makeUnmodifiable (newSortedMap (aCollection));
}
@Nonnull
@ReturnsMutableCopy
public static Set newSet ()
{
return new HashSet (0);
}
@Nonnull
@ReturnsMutableCopy
public static Set newSet (@Nullable final ELEMENTTYPE aValue)
{
final Set ret = new HashSet (1);
ret.add (aValue);
return ret;
}
@Nonnull
@ReturnsMutableCopy
public static Set newSet (@Nullable final ELEMENTTYPE... aValues)
{
if (ArrayHelper.isEmpty (aValues))
return new HashSet (0);
final Set ret = new HashSet