public class

Quirks

extends java.lang.Object

 java.lang.Object

↳androidx.camera.viewfinder.internal.quirk.Quirks

Gradle dependencies

compile group: 'androidx.camera.viewfinder', name: 'viewfinder-view', version: '1.4.0-alpha08'

  • groupId: androidx.camera.viewfinder
  • artifactId: viewfinder-view
  • version: 1.4.0-alpha08

Artifact androidx.camera.viewfinder:viewfinder-view:1.4.0-alpha08 it located at Google repository (https://maven.google.com/)

Overview

Wraps a list of Quirks, allowing to easily retrieve a Quirk instance by its class.

Summary

Constructors
publicQuirks(java.util.List<Quirk> quirks)

Wraps the provided list of quirks.

Methods
public booleancontains(java.lang.Class<Quirk> quirkClass)

Returns whether this collection of quirks contains a quirk with the provided type.

public Quirkget(java.lang.Class<Quirk> quirkClass)

Retrieves a Quirk instance given its type.

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

Constructors

public Quirks(java.util.List<Quirk> quirks)

Wraps the provided list of quirks.

Methods

public Quirk get(java.lang.Class<Quirk> quirkClass)

Retrieves a Quirk instance given its type.

Unlike Quirks.contains(Class), a quirk can only be retrieved by the exact class. If a superclass or superinterface is provided, null will be returned, even if a quirk with the provided superclass or superinterface exists in this collection.

Parameters:

quirkClass: The type of quirk to retrieve.

Returns:

A Quirk instance of the provided type, or null if it isn't found.

public boolean contains(java.lang.Class<Quirk> quirkClass)

Returns whether this collection of quirks contains a quirk with the provided type.

This checks whether the provided quirk type is the exact class, a superclass, or a superinterface of any of the contained quirks, and will return true in all cases.

Parameters:

quirkClass: The type of quirk to check for existence in this container.

Returns:

true if this container contains a quirk with the given type, false otherwise.

Source

/*
 * Copyright 2022 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.viewfinder.internal.quirk;

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

import java.util.ArrayList;
import java.util.List;

/**
 * Wraps a list of {@link Quirk}s, allowing to easily retrieve a {@link Quirk} instance by its
 * class.
 */
public class Quirks {

    @NonNull
    private final List<Quirk> mQuirks;

    /** Wraps the provided list of quirks. */
    public Quirks(@NonNull final List<Quirk> quirks) {
        mQuirks = new ArrayList<>(quirks);
    }

    /**
     * Retrieves a {@link Quirk} instance given its type.
     *
     * <p>Unlike {@link #contains(Class)}, a quirk can only be retrieved by the exact class. If a
     * superclass or superinterface is provided, {@code null} will be returned, even if a quirk
     * with the provided superclass or superinterface exists in this collection.
     *
     * @param quirkClass The type of quirk to retrieve.
     * @return A {@link Quirk} instance of the provided type, or {@code null} if it isn't found.
     */
    @SuppressWarnings("unchecked")
    @Nullable
    public <T extends Quirk> T get(@NonNull final Class<T> quirkClass) {
        for (final Quirk quirk : mQuirks) {
            if (quirk.getClass() == quirkClass) {
                return (T) quirk;
            }
        }
        return null;
    }

    /**
     * Returns whether this collection of quirks contains a quirk with the provided type.
     *
     * <p>This checks whether the provided quirk type is the exact class, a superclass, or a
     * superinterface of any of the contained quirks, and will return true in all cases.
     * @param quirkClass The type of quirk to check for existence in this container.
     * @return {@code true} if this container contains a quirk with the given type, {@code false}
     * otherwise.
     */
    public boolean contains(@NonNull Class<? extends Quirk> quirkClass) {
        for (Quirk quirk : mQuirks) {
            if (quirkClass.isAssignableFrom(quirk.getClass())) {
                return true;
            }
        }

        return false;
    }
}