1 /* 2 * Copyright (C) 2006 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.internal.app; 18 19 import android.util.ArrayMap; 20 import android.util.SparseArray; 21 22 public class ProcessMap<E> { 23 final ArrayMap<String, SparseArray<E>> mMap 24 = new ArrayMap<String, SparseArray<E>>(); 25 get(String name, int uid)26 public E get(String name, int uid) { 27 SparseArray<E> uids = mMap.get(name); 28 if (uids == null) return null; 29 return uids.get(uid); 30 } 31 get(String name)32 public SparseArray<E> get(String name) { 33 SparseArray<E> uids = mMap.get(name); 34 return uids; 35 } 36 put(String name, int uid, E value)37 public E put(String name, int uid, E value) { 38 SparseArray<E> uids = mMap.get(name); 39 if (uids == null) { 40 uids = new SparseArray<E>(2); 41 mMap.put(name, uids); 42 } 43 uids.put(uid, value); 44 return value; 45 } 46 remove(String name, int uid)47 public E remove(String name, int uid) { 48 SparseArray<E> uids = mMap.get(name); 49 if (uids != null) { 50 final E old = uids.removeReturnOld(uid); 51 if (uids.size() == 0) { 52 mMap.remove(name); 53 } 54 return old; 55 } 56 return null; 57 } 58 getMap()59 public ArrayMap<String, SparseArray<E>> getMap() { 60 return mMap; 61 } 62 size()63 public int size() { 64 return mMap.size(); 65 } 66 clear()67 public void clear() { 68 mMap.clear(); 69 } 70 putAll(ProcessMap<E> other)71 public void putAll(ProcessMap<E> other) { mMap.putAll(other.mMap); } 72 } 73