public final class

Metadata

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.model.Metadata

Gradle dependencies

compile group: 'androidx.car.app', name: 'app', version: '1.7.0-beta01'

  • groupId: androidx.car.app
  • artifactId: app
  • version: 1.7.0-beta01

Artifact androidx.car.app:app:1.7.0-beta01 it located at Google repository (https://maven.google.com/)

Overview

A metadata class used for attaching additional properties to models.

Summary

Fields
public static final MetadataEMPTY_METADATA

An empty Metadata instance.

Methods
public booleanequals(java.lang.Object other)

public PlacegetPlace()

Returns a Place instance set in the metadata.

public inthashCode()

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

Fields

public static final Metadata EMPTY_METADATA

An empty Metadata instance.

Methods

public Place getPlace()

Returns a Place instance set in the metadata.

See also: Metadata.Builder.setPlace(Place)

public int hashCode()

public boolean equals(java.lang.Object other)

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.car.app.model;

import static java.util.Objects.requireNonNull;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.car.app.annotations.CarProtocol;
import androidx.car.app.annotations.KeepFields;

import java.util.Objects;

/** A metadata class used for attaching additional properties to models. */
@CarProtocol
@KeepFields
public final class Metadata {
    /** An empty {@link Metadata} instance. */
    public static final Metadata EMPTY_METADATA = new Builder().build();
    @Nullable
    private final Place mPlace;

    /**
     * Returns a {@link Place} instance set in the metadata.
     *
     * @see Builder#setPlace(Place)
     */
    @Nullable
    public Place getPlace() {
        return mPlace;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(mPlace);
    }

    @Override
    public boolean equals(@Nullable Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof Metadata)) {
            return false;
        }
        Metadata otherMetadata = (Metadata) other;

        return Objects.equals(mPlace, otherMetadata.mPlace);
    }

    Metadata(Builder builder) {
        mPlace = builder.mPlace;
    }

    /** Default constructor for serialization. */
    private Metadata() {
        mPlace = null;
    }

    /** A builder for {@link Metadata}. */
    public static final class Builder {
        @Nullable
        Place mPlace;

        /**
         * Sets a {@link Place} used for showing {@link Distance} and {@link PlaceMarker}
         * information.
         *
         * @throws NullPointerException if {@code place} is {@code null}
         */
        @NonNull
        public Builder setPlace(@NonNull Place place) {
            mPlace = requireNonNull(place);
            return this;
        }

        /**
         * Returns a {@link Metadata} instance defined by this builder.
         */
        @NonNull
        public Metadata build() {
            return new Metadata(this);
        }

        /** Returns an empty {@link Builder} instance. */
        public Builder() {
        }

        /**
         * Returns a new {@link Builder} with the data from the given {@link Metadata} instance.
         *
         * @throws NullPointerException if {@code icon} is {@code null}
         */
        public Builder(@NonNull Metadata metadata) {
            mPlace = requireNonNull(metadata).getPlace();
        }
    }
}