1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.launcher3.util;
18 
19 import android.util.SparseArray;
20 
21 import java.util.Iterator;
22 
23 /**
24  * Extension of {@link SparseArray} with some utility methods.
25  */
26 public class IntSparseArrayMap<E> extends SparseArray<E> implements Iterable<E> {
27 
containsKey(int key)28     public boolean containsKey(int key) {
29         return indexOfKey(key) >= 0;
30     }
31 
isEmpty()32     public boolean isEmpty() {
33         return size() <= 0;
34     }
35 
36     @Override
clone()37     public IntSparseArrayMap<E> clone() {
38         return (IntSparseArrayMap<E>) super.clone();
39     }
40 
41     @Override
iterator()42     public Iterator<E> iterator() {
43         return new ValueIterator();
44     }
45 
46     @Thunk class ValueIterator implements Iterator<E> {
47 
48         private int mNextIndex = 0;
49 
50         @Override
hasNext()51         public boolean hasNext() {
52             return mNextIndex < size();
53         }
54 
55         @Override
next()56         public E next() {
57             return valueAt(mNextIndex ++);
58         }
59 
60         @Override
remove()61         public void remove() {
62             throw new UnsupportedOperationException();
63         }
64     }
65 }
66