summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-09-15 01:07:59 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-09-15 01:07:59 +0000
commitabcfcbbbfe0cf346e9341ac17da195e1099e4a96 (patch)
tree77fbb216ef74c0bc286bd68257e737a9ff9e8a38 /core/java
parent26a5e89adade912873e15ccc7c19f9e4492fa4be (diff)
parent81e806a72aa977e6cd7aceafc31a22f3d88e104d (diff)
Merge "Move LazyIntToIntMap to services.jar"
Diffstat (limited to 'core/java')
-rw-r--r--core/java/com/android/internal/textservice/LazyIntToIntMap.java67
1 files changed, 0 insertions, 67 deletions
diff --git a/core/java/com/android/internal/textservice/LazyIntToIntMap.java b/core/java/com/android/internal/textservice/LazyIntToIntMap.java
deleted file mode 100644
index ca9936c5fcda..000000000000
--- a/core/java/com/android/internal/textservice/LazyIntToIntMap.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.internal.textservice;
-
-import android.annotation.NonNull;
-import android.util.SparseIntArray;
-
-import com.android.internal.annotations.VisibleForTesting;
-
-import java.util.function.IntUnaryOperator;
-
-/**
- * Simple int-to-int key-value-store that is to be lazily initialized with the given
- * {@link IntUnaryOperator}.
- */
-@VisibleForTesting
-public final class LazyIntToIntMap {
-
- private final SparseIntArray mMap = new SparseIntArray();
-
- @NonNull
- private final IntUnaryOperator mMappingFunction;
-
- /**
- * @param mappingFunction int to int mapping rules to be (lazily) evaluated
- */
- public LazyIntToIntMap(@NonNull IntUnaryOperator mappingFunction) {
- mMappingFunction = mappingFunction;
- }
-
- /**
- * Deletes {@code key} and associated value.
- * @param key key to be deleted
- */
- public void delete(int key) {
- mMap.delete(key);
- }
-
- /**
- * @param key key associated with the value
- * @return value associated with the {@code key}. If this is the first time to access
- * {@code key}, then {@code mappingFunction} passed to the constructor will be evaluated
- */
- public int get(int key) {
- final int index = mMap.indexOfKey(key);
- if (index >= 0) {
- return mMap.valueAt(index);
- }
- final int value = mMappingFunction.applyAsInt(key);
- mMap.append(key, value);
- return value;
- }
-}