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
17package com.android.launcher3.util;
18
19import android.util.LongSparseArray;
20
21import java.util.Iterator;
22
23/**
24 * Extension of {@link LongSparseArray} with some utility methods.
25 */
26public class LongArrayMap<E> extends LongSparseArray<E> implements Iterable<E> {
27
28    public boolean containsKey(long key) {
29        return indexOfKey(key) >= 0;
30    }
31
32    public boolean isEmpty() {
33        return size() <= 0;
34    }
35
36    @Override
37    public LongArrayMap<E> clone() {
38        return (LongArrayMap<E>) super.clone();
39    }
40
41    @Override
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
51        public boolean hasNext() {
52            return mNextIndex < size();
53        }
54
55        @Override
56        public E next() {
57            return valueAt(mNextIndex ++);
58        }
59
60        @Override
61        public void remove() {
62            throw new UnsupportedOperationException();
63        }
64    }
65}
66