FileDocCategorySizeDatePackage
MapCollections.javaAPI DocAndroid 5.1 API15492Thu Mar 12 22:22:10 GMT 2015android.util

MapCollections

public abstract class MapCollections extends Object
Helper for writing standard Java collection interfaces to a data structure like {@link ArrayMap}.
hide

Fields Summary
EntrySet
mEntrySet
KeySet
mKeySet
ValuesCollection
mValues
Constructors Summary
Methods Summary
protected abstract voidcolClear()

protected abstract java.lang.ObjectcolGetEntry(int index, int offset)

protected abstract java.util.MapcolGetMap()

protected abstract intcolGetSize()

protected abstract intcolIndexOfKey(java.lang.Object key)

protected abstract intcolIndexOfValue(java.lang.Object key)

protected abstract voidcolPut(K key, V value)

protected abstract voidcolRemoveAt(int index)

protected abstract VcolSetValue(int index, V value)

public static booleancontainsAllHelper(java.util.Map map, java.util.Collection collection)

        Iterator<?> it = collection.iterator();
        while (it.hasNext()) {
            if (!map.containsKey(it.next())) {
                return false;
            }
        }
        return true;
    
public static booleanequalsSetHelper(java.util.Set set, java.lang.Object object)

        if (set == object) {
            return true;
        }
        if (object instanceof Set) {
            Set<?> s = (Set<?>) object;

            try {
                return set.size() == s.size() && set.containsAll(s);
            } catch (NullPointerException ignored) {
                return false;
            } catch (ClassCastException ignored) {
                return false;
            }
        }
        return false;
    
public java.util.SetgetEntrySet()

        if (mEntrySet == null) {
            mEntrySet = new EntrySet();
        }
        return mEntrySet;
    
public java.util.SetgetKeySet()

        if (mKeySet == null) {
            mKeySet = new KeySet();
        }
        return mKeySet;
    
public java.util.CollectiongetValues()

        if (mValues == null) {
            mValues = new ValuesCollection();
        }
        return mValues;
    
public static booleanremoveAllHelper(java.util.Map map, java.util.Collection collection)

        int oldSize = map.size();
        Iterator<?> it = collection.iterator();
        while (it.hasNext()) {
            map.remove(it.next());
        }
        return oldSize != map.size();
    
public static booleanretainAllHelper(java.util.Map map, java.util.Collection collection)

        int oldSize = map.size();
        Iterator<K> it = map.keySet().iterator();
        while (it.hasNext()) {
            if (!collection.contains(it.next())) {
                it.remove();
            }
        }
        return oldSize != map.size();
    
public java.lang.Object[]toArrayHelper(int offset)

        final int N = colGetSize();
        Object[] result = new Object[N];
        for (int i=0; i<N; i++) {
            result[i] = colGetEntry(i, offset);
        }
        return result;
    
public T[]toArrayHelper(T[] array, int offset)

        final int N  = colGetSize();
        if (array.length < N) {
            @SuppressWarnings("unchecked") T[] newArray
                = (T[]) Array.newInstance(array.getClass().getComponentType(), N);
            array = newArray;
        }
        for (int i=0; i<N; i++) {
            array[i] = (T)colGetEntry(i, offset);
        }
        if (array.length > N) {
            array[N] = null;
        }
        return array;