• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import java.util.stream.Stream;
23 import java.util.stream.StreamSupport;
24 
25 /**
26  * Extension of {@link SparseArray} with some utility methods.
27  */
28 public class IntSparseArrayMap<E> extends SparseArray<E> implements Iterable<E> {
29 
containsKey(int key)30     public boolean containsKey(int key) {
31         return indexOfKey(key) >= 0;
32     }
33 
isEmpty()34     public boolean isEmpty() {
35         return size() <= 0;
36     }
37 
38     @Override
clone()39     public IntSparseArrayMap<E> clone() {
40         return (IntSparseArrayMap<E>) super.clone();
41     }
42 
43     @Override
iterator()44     public Iterator<E> iterator() {
45         return new ValueIterator();
46     }
47 
stream()48     public Stream<E> stream() {
49         return StreamSupport.stream(spliterator(), false);
50     }
51 
52     @Thunk class ValueIterator implements Iterator<E> {
53 
54         private int mNextIndex = 0;
55 
56         @Override
hasNext()57         public boolean hasNext() {
58             return mNextIndex < size();
59         }
60 
61         @Override
next()62         public E next() {
63             return valueAt(mNextIndex ++);
64         }
65 
66         @Override
remove()67         public void remove() {
68             throw new UnsupportedOperationException();
69         }
70     }
71 }
72