Home | History | Annotate | Download | only in model
      1 /*
      2  * Copyright (C) 2017 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.systemui.recents.model;
     18 
     19 import android.util.ArrayMap;
     20 import android.util.Log;
     21 import android.util.SparseArray;
     22 
     23 import com.android.systemui.recents.model.Task.TaskKey;
     24 
     25 import java.io.PrintWriter;
     26 
     27 /**
     28  * Like {@link TaskKeyLruCache}, but without LRU functionality.
     29  */
     30 public class TaskKeyStrongCache<V> extends TaskKeyCache<V> {
     31 
     32     private static final String TAG = "TaskKeyCache";
     33 
     34     private final ArrayMap<Integer, V> mCache = new ArrayMap<>();
     35 
     36     final void copyEntries(TaskKeyStrongCache<V> other) {
     37         for (int i = other.mKeys.size() - 1; i >= 0; i--) {
     38             TaskKey key = other.mKeys.valueAt(i);
     39             put(key, other.mCache.get(key.id));
     40         }
     41     }
     42 
     43     public void dump(String prefix, PrintWriter writer) {
     44         String innerPrefix = prefix + "  ";
     45         writer.print(prefix); writer.print(TAG);
     46         writer.print(" numEntries="); writer.print(mKeys.size());
     47         writer.println();
     48         int keyCount = mKeys.size();
     49         for (int i = 0; i < keyCount; i++) {
     50             writer.print(innerPrefix); writer.println(mKeys.get(mKeys.keyAt(i)));
     51         }
     52     }
     53 
     54     @Override
     55     protected V getCacheEntry(int id) {
     56         return mCache.get(id);
     57     }
     58 
     59     @Override
     60     protected void putCacheEntry(int id, V value) {
     61         mCache.put(id, value);
     62     }
     63 
     64     @Override
     65     protected void removeCacheEntry(int id) {
     66         mCache.remove(id);
     67     }
     68 
     69     @Override
     70     protected void evictAllCache() {
     71         mCache.clear();
     72     }
     73 }
     74