Package 

Class SparseArrayCompat

  • All Implemented Interfaces:
    java.lang.Cloneable

    
    public class SparseArrayCompat<E>
     implements Cloneable
                        

    A copy of the current platform (VERSION_CODES#KITKAT) version of android.util.SparseArray. It provides a removeAt() method and other things.

    • Constructor Summary

      Constructors 
      Constructor Description
      SparseArrayCompat() Creates a new SparseArray containing no mappings.
      SparseArrayCompat(int initialCapacity) Creates a new SparseArray containing no mappings that will notrequire any additional memory allocation to store the specifiednumber of mappings.
    • Method Summary

      Modifier and Type Method Description
      SparseArrayCompat<E> clone()
      E get(int key) Gets the Object mapped from the specified key, or nullif no such mapping has been made.
      E get(int key, E valueIfKeyNotFound) Gets the Object mapped from the specified key, or the specified Objectif no such mapping has been made.
      E remove(int key) Removes the mapping from the specified key, if there was any.
      void removeAt(int index) Removes the mapping at the specified index.
      void removeAtRange(int index, int size) Remove a range of mappings as a batch.
      void put(int key, E value) Adds a mapping from the specified key to the specified value,replacing the previous mapping from the specified key if therewas one.
      int size() Returns the number of key-value mappings that this SparseArraycurrently stores.
      int keyAt(int index) Given an index in the range 0...size()-1, returnsthe key from the indexth key-value mapping that thisSparseArray stores.
      E valueAt(int index) Given an index in the range 0...size()-1, returnsthe value from the indexth key-value mapping that thisSparseArray stores.
      void setValueAt(int index, E value) Given an index in the range 0...size()-1, sets a newvalue for the indexth key-value mapping that thisSparseArray stores.
      int indexOfKey(int key) Returns the index for which keyAt would return thespecified key, or a negative number if the specifiedkey is not mapped.
      int indexOfValue(E value) Returns an index for which valueAt would return thespecified key, or a negative number if no keys map to thespecified value.
      void clear() Removes all key-value mappings from this SparseArray.
      void append(int key, E value) Puts a key/value pair into the array, optimizing for the case wherethe key is greater than all existing keys in the array.
      String toString() This implementation composes a string by iterating over its mappings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SparseArrayCompat

        SparseArrayCompat()
        Creates a new SparseArray containing no mappings.
      • SparseArrayCompat

        SparseArrayCompat(int initialCapacity)
        Creates a new SparseArray containing no mappings that will notrequire any additional memory allocation to store the specifiednumber of mappings.
    • Method Detail

      • get

         E get(int key)

        Gets the Object mapped from the specified key, or nullif no such mapping has been made.

      • get

         E get(int key, E valueIfKeyNotFound)

        Gets the Object mapped from the specified key, or the specified Objectif no such mapping has been made.

      • remove

         E remove(int key)

        Removes the mapping from the specified key, if there was any.

      • removeAt

         void removeAt(int index)

        Removes the mapping at the specified index.

        Parameters:
        index - index at which remove item
      • removeAtRange

         void removeAtRange(int index, int size)

        Remove a range of mappings as a batch.

        Parameters:
        index - Index to begin at
        size - Number of mappings to remove
      • put

         void put(int key, E value)

        Adds a mapping from the specified key to the specified value,replacing the previous mapping from the specified key if therewas one.

      • size

         int size()

        Returns the number of key-value mappings that this SparseArraycurrently stores.

      • keyAt

         int keyAt(int index)

        Given an index in the range 0...size()-1, returnsthe key from the indexth key-value mapping that thisSparseArray stores.

      • valueAt

         E valueAt(int index)

        Given an index in the range 0...size()-1, returnsthe value from the indexth key-value mapping that thisSparseArray stores.

      • setValueAt

         void setValueAt(int index, E value)

        Given an index in the range 0...size()-1, sets a newvalue for the indexth key-value mapping that thisSparseArray stores.

      • indexOfKey

         int indexOfKey(int key)

        Returns the index for which keyAt would return thespecified key, or a negative number if the specifiedkey is not mapped.

      • indexOfValue

         int indexOfValue(E value)

        Returns an index for which valueAt would return thespecified key, or a negative number if no keys map to thespecified value.

        Beware that this is a linear search, unlike lookups by key,and that multiple keys can map to the same value and this willfind only one of them.

        Note also that unlike most collections' {@code indexOf} methods,this method compares values using {@code ==} rather than {@code equals}.

      • clear

         void clear()

        Removes all key-value mappings from this SparseArray.

      • append

         void append(int key, E value)

        Puts a key/value pair into the array, optimizing for the case wherethe key is greater than all existing keys in the array.

      • toString

         String toString()

        This implementation composes a string by iterating over its mappings. Ifthis map contains itself as a value, the string "(this Map)"will appear in its place.