public class

FastSafeIterableMap<K, V>

extends SafeIterableMap<java.lang.Object, java.lang.Object>

 java.lang.Object

androidx.arch.core.internal.SafeIterableMap<java.lang.Object, java.lang.Object>

↳androidx.arch.core.internal.FastSafeIterableMap<K, V>

Gradle dependencies

compile group: 'androidx.arch.core', name: 'core-common', version: '2.1.0'

  • groupId: androidx.arch.core
  • artifactId: core-common
  • version: 2.1.0

Artifact androidx.arch.core:core-common:2.1.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.arch.core:core-common android.arch.core:common

Androidx class mapping:

androidx.arch.core.internal.FastSafeIterableMap android.arch.core.internal.FastSafeIterableMap

Overview

Poor's man LinkedHashMap, which supports modifications during iterations. Takes more memory that SafeIterableMap It is NOT thread safe.

Summary

Constructors
publicFastSafeIterableMap()

Methods
public java.util.Map.Entry<java.lang.Object, java.lang.Object>ceil(java.lang.Object k)

Return an entry added to prior to an entry associated with the given key.

public booleancontains(java.lang.Object key)

Returns true if this map contains a mapping for the specified key.

protected androidx.arch.core.internal.SafeIterableMap.Entry<java.lang.Object, java.lang.Object>get(java.lang.Object k)

public java.lang.ObjectputIfAbsent(java.lang.Object key, java.lang.Object v)

If the specified key is not already associated with a value, associates it with the given value.

public java.lang.Objectremove(java.lang.Object key)

Removes the mapping for a key from this map if it is present.

from SafeIterableMap<K, V>descendingIterator, eldest, equals, hashCode, iterator, iteratorWithAdditions, newest, put, size, toString
from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Constructors

public FastSafeIterableMap()

Methods

protected androidx.arch.core.internal.SafeIterableMap.Entry<java.lang.Object, java.lang.Object> get(java.lang.Object k)

public java.lang.Object putIfAbsent(java.lang.Object key, java.lang.Object v)

If the specified key is not already associated with a value, associates it with the given value.

Parameters:

key: key with which the specified value is to be associated
v: value to be associated with the specified key

Returns:

the previous value associated with the specified key, or null if there was no mapping for the key

public java.lang.Object remove(java.lang.Object key)

Removes the mapping for a key from this map if it is present.

Parameters:

key: key whose mapping is to be removed from the map

Returns:

the previous value associated with the specified key, or null if there was no mapping for the key

public boolean contains(java.lang.Object key)

Returns true if this map contains a mapping for the specified key.

public java.util.Map.Entry<java.lang.Object, java.lang.Object> ceil(java.lang.Object k)

Return an entry added to prior to an entry associated with the given key.

Parameters:

k: the key

Source

/*
 * Copyright 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 androidx.arch.core.internal;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;

import java.util.HashMap;
import java.util.Map;

/**
 * Poor's man LinkedHashMap, which supports modifications during iterations.
 * Takes more memory that {@link SafeIterableMap}
 * It is NOT thread safe.
 *
 * @param <K> Key type
 * @param <V> Value type
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
public class FastSafeIterableMap<K, V> extends SafeIterableMap<K, V> {

    private HashMap<K, Entry<K, V>> mHashMap = new HashMap<>();

    @Override
    protected Entry<K, V> get(K k) {
        return mHashMap.get(k);
    }

    @Override
    public V putIfAbsent(@NonNull K key, @NonNull V v) {
        Entry<K, V> current = get(key);
        if (current != null) {
            return current.mValue;
        }
        mHashMap.put(key, put(key, v));
        return null;
    }

    @Override
    public V remove(@NonNull K key) {
        V removed = super.remove(key);
        mHashMap.remove(key);
        return removed;
    }

    /**
     * Returns {@code true} if this map contains a mapping for the specified
     * key.
     */
    public boolean contains(K key) {
        return mHashMap.containsKey(key);
    }

    /**
     * Return an entry added to prior to an entry associated with the given key.
     *
     * @param k the key
     */
    public Map.Entry<K, V> ceil(K k) {
        if (contains(k)) {
            return mHashMap.get(k).mPrevious;
        }
        return null;
    }
}