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