public class

TagBundle

extends java.lang.Object

 java.lang.Object

↳androidx.camera.core.impl.TagBundle

Subclasses:

MutableTagBundle

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-core', version: '1.2.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-core
  • version: 1.2.0-alpha01

Artifact androidx.camera:camera-core:1.2.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

A TagBundle is an immutable tags collection which does not allow insertion/removal.

Summary

Fields
protected final java.util.Map<java.lang.String, java.lang.Object>mTagMap

It is used to store all the keys and Tags

Constructors
protectedTagBundle(java.util.Map<java.lang.String, java.lang.Object> tagMap)

Methods
public static TagBundlecreate(<any> source)

Creates a TagBundle with one entry.

public static TagBundleemptyBundle()

Creates an empty TagBundle.

public static TagBundlefrom(TagBundle otherTagBundle)

Creates a TagBundle from another TagBundle.

public java.lang.ObjectgetTag(java.lang.String key)

Gets the tag associated with the key.

public java.util.Set<java.lang.String>listKeys()

Lists all keys contained within this TagBundle.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

protected final java.util.Map<java.lang.String, java.lang.Object> mTagMap

It is used to store all the keys and Tags

Constructors

protected TagBundle(java.util.Map<java.lang.String, java.lang.Object> tagMap)

Methods

public static TagBundle emptyBundle()

Creates an empty TagBundle.

Returns:

an empty TagBundle containing no tag.

public static TagBundle create(<any> source)

Creates a TagBundle with one entry.

Returns:

a TagBundle containing one tag.

public static TagBundle from(TagBundle otherTagBundle)

Creates a TagBundle from another TagBundle.

This will copy keys and values from the provided TagBundle.

Parameters:

otherTagBundle: TagBundle containing keys/values to be copied.

Returns:

A new TagBundle pre-populated with keys/values.

public java.lang.Object getTag(java.lang.String key)

Gets the tag associated with the key.

Parameters:

key: The key for query.

Returns:

The tag associated with the key.

public java.util.Set<java.lang.String> listKeys()

Lists all keys contained within this TagBundle.

Returns:

A java.util.Set of keys contained within this configuration. It returns an empty set if there are no keys in this TagBundle.

Source

/*
 * Copyright 2020 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.camera.core.impl;

import android.util.ArrayMap;
import android.util.Pair;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import java.util.Map;
import java.util.Set;

/**
 * A TagBundle is an immutable tags collection which does not allow insertion/removal.
 */
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
public class TagBundle {
    /** It is used to store all the keys and Tags */
    protected final Map<String, Object> mTagMap;

    protected TagBundle(@NonNull Map<String, Object> tagMap) {
        mTagMap = tagMap;
    }

    private static final TagBundle EMPTY_TAGBUNDLE = new TagBundle(new ArrayMap<>());

    /**
     * Creates an empty TagBundle.
     *
     * @return an empty TagBundle containing no tag.
     */
    @NonNull
    public static TagBundle emptyBundle() {
        return EMPTY_TAGBUNDLE;
    }

    /**
     * Creates a TagBundle with one entry.
     *
     * @return a TagBundle containing one tag.
     */
    @NonNull
    public static TagBundle create(@NonNull Pair<String, Object> source) {
        Map<String, Object> map = new ArrayMap<>();
        map.put(source.first, source.second);
        return new TagBundle(map);
    }

    /**
     * Creates a TagBundle from another TagBundle.
     *
     * <p>This will copy keys and values from the provided TagBundle.
     *
     * @param otherTagBundle TagBundle containing keys/values to be copied.
     * @return A new TagBundle pre-populated with keys/values.
     */
    @NonNull
    public static TagBundle from(@NonNull TagBundle otherTagBundle) {
        Map<String, Object> tags = new ArrayMap<>();
        for (String key: otherTagBundle.listKeys()) {
            tags.put(key, otherTagBundle.getTag(key));
        }

        return new TagBundle(tags);
    }

    /**
     * Gets the tag associated with the key.
     *
     * @param key      The key for query.
     * @return The tag associated with the key.
     */
    @Nullable
    public Object getTag(@NonNull String key) {
        return mTagMap.get(key);
    }

    /**
     * Lists all keys contained within this TagBundle.
     *
     * @return A {@link Set} of keys contained within this configuration. It returns an empty set
     * if there are no keys in this TagBundle.
     */
    @NonNull
    public Set<String> listKeys() {
        return mTagMap.keySet();
    }
}