public final class

Lane

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.navigation.model.Lane

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

Configuration of a single lane of a road at a particular point in the navigation.

A Lane object describes all possible directions the driver could go from this lane, and indicates which directions the driver could take to stay on the navigation route.

Summary

Methods
public booleanequals(java.lang.Object other)

public java.util.List<LaneDirection>getDirections()

Returns the list of directions a driver can take from this Lane.

public inthashCode()

public java.lang.StringtoString()

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

Methods

public java.util.List<LaneDirection> getDirections()

Returns the list of directions a driver can take from this Lane.

See also: Lane.Builder.addDirection(LaneDirection)

public java.lang.String toString()

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.navigation.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 androidx.car.app.utils.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * Configuration of a single lane of a road at a particular point in the navigation.
 *
 * <p>A {@link Lane} object describes all possible directions the driver could go from this lane,
 * and indicates which directions the driver could take to stay on the navigation route.
 */
@CarProtocol
@KeepFields
public final class Lane {
    private final List<LaneDirection> mDirections;

    /**
     * Returns the list of directions a driver can take from this {@link Lane}.
     *
     * @see Builder#addDirection(LaneDirection)
     */
    @NonNull
    public List<LaneDirection> getDirections() {
        return CollectionUtils.emptyIfNull(mDirections);
    }

    @Override
    @NonNull
    public String toString() {
        return "[direction count: " + (mDirections != null ? mDirections.size() : 0) + "]";
    }

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

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

        Lane otherLane = (Lane) other;
        return Objects.equals(mDirections, otherLane.mDirections);
    }

    Lane(List<LaneDirection> directions) {
        mDirections = CollectionUtils.unmodifiableCopy(directions);
    }

    /** Constructs an empty instance, used by serialization code. */
    private Lane() {
        mDirections = Collections.emptyList();
    }

    /** A builder of {@link Lane}. */
    public static final class Builder {
        private final List<LaneDirection> mDirections = new ArrayList<>();

        /**
         * Adds a direction a driver can take from this lane.
         *
         * @throws NullPointerException if {@code direction} is {@code null}
         */
        @NonNull
        public Builder addDirection(@NonNull LaneDirection direction) {
            mDirections.add(requireNonNull(direction));
            return this;
        }

        /** Constructs the {@link Lane} defined by this builder. */
        @NonNull
        public Lane build() {
            return new Lane(mDirections);
        }

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