/*
 * Copyright (C) 2017 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 com.google.android.exoplayer2.trackselection;

import com.google.android.exoplayer2.RendererConfiguration;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.util.Util;

/**
 * The result of a {@link TrackSelector} operation.
 */
public final class TrackSelectorResult {

  /**
   * The groups provided to the {@link TrackSelector}.
   */
  public final TrackGroupArray groups;
  /**
   * A {@link TrackSelectionArray} containing the selection for each renderer.
   */
  public final TrackSelectionArray selections;
  /**
   * An opaque object that will be returned to {@link TrackSelector#onSelectionActivated(Object)}
   * should the selections be activated.
   */
  public final Object info;
  /**
   * A {@link RendererConfiguration} for each renderer, to be used with the selections.
   */
  public final RendererConfiguration[] rendererConfigurations;

  /**
   * @param groups The groups provided to the {@link TrackSelector}.
   * @param selections A {@link TrackSelectionArray} containing the selection for each renderer.
   * @param info An opaque object that will be returned to
   *     {@link TrackSelector#onSelectionActivated(Object)} should the selections be activated.
   * @param rendererConfigurations A {@link RendererConfiguration} for each renderer, to be used
   *     with the selections.
   */
  public TrackSelectorResult(TrackGroupArray groups, TrackSelectionArray selections, Object info,
      RendererConfiguration[] rendererConfigurations) {
    this.groups = groups;
    this.selections = selections;
    this.info = info;
    this.rendererConfigurations = rendererConfigurations;
  }

  /**
   * Returns whether this result is equivalent to {@code other} for all renderers.
   *
   * @param other The other {@link TrackSelectorResult}. May be null.
   * @return Whether this result is equivalent to {@code other} for all renderers.
   */
  public boolean isEquivalent(TrackSelectorResult other) {
    for (int i = 0; i < selections.length; i++) {
      if (!isEquivalent(other, i)) {
        return false;
      }
    }
    return true;
  }

  /**
   * Returns whether this result is equivalent to {@code other} for the renderer at the given index.
   * The results are equivalent if they have equal track selections and configurations for the
   * renderer.
   *
   * @param other The other {@link TrackSelectorResult}. May be null.
   * @param index The renderer index to check for equivalence.
   * @return Whether this result is equivalent to {@code other} for all renderers.
   */
  public boolean isEquivalent(TrackSelectorResult other, int index) {
    if (other == null) {
      return selections.get(index) == null && rendererConfigurations[index] == null;
    }
    return Util.areEqual(selections.get(index), other.selections.get(index))
        && Util.areEqual(rendererConfigurations[index], other.rendererConfigurations[index]);
  }

}

@@ -2443,26 +2443,94 @@
  May be null
+, in which case %7B@code false%7D%0A   *     will be returned in all cases
 .%0A
-
    * @return
@@ -2661,24 +2661,75 @@
 lt other) %7B%0A
+    if (other == null) %7B%0A      return false;%0A    %7D%0A
     for (int
@@ -3151,16 +3151,84 @@
  be null
+, in which case %7B@code false%7D%0A   *     will be returned in all cases
 .%0A   * @
@@ -3485,78 +3485,13 @@
 urn 
-selections.get(index) == null && rendererConfigurations%5Bindex%5D == null
+false
 ;%0A  

Fix possible track selection NPE