/*
 * Copyright (C) 2016 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.source.hls.playlist;

import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.MimeTypes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Represents an HLS master playlist.
 */
public final class HlsMasterPlaylist extends HlsPlaylist {

  /**
   * Represents a url in an HLS master playlist.
   */
  public static final class HlsUrl {

    /**
     * The http url from which the media playlist can be obtained.
     */
    public final String url;
    /**
     * Format information associated with the HLS url.
     */
    public final Format format;

    /**
     * Creates an HLS url from a given http url.
     *
     * @param url The url.
     * @return An HLS url.
     */
    public static HlsUrl createMediaPlaylistHlsUrl(String url) {
      Format format = Format.createContainerFormat("0", MimeTypes.APPLICATION_M3U8, null, null,
          Format.NO_VALUE, 0, null);
      return new HlsUrl(url, format);
    }

    /**
     * @param url See {@link #url}.
     * @param format See {@link #format}.
     */
    public HlsUrl(String url, Format format) {
      this.url = url;
      this.format = format;
    }

  }

  /**
   * The list of variants declared by the playlist.
   */
  public final List<HlsUrl> variants;
  /**
   * The list of demuxed audios declared by the playlist.
   */
  public final List<HlsUrl> audios;
  /**
   * The list of subtitles declared by the playlist.
   */
  public final List<HlsUrl> subtitles;

  /**
   * The format of the audio muxed in the variants. May be null if the playlist does not declare any
   * muxed audio.
   */
  public final Format muxedAudioFormat;
  /**
   * The format of the closed captions declared by the playlist. May be empty if the playlist
   * explicitly declares no captions are available, or null if the playlist does not declare any
   * captions information.
   */
  public final List<Format> muxedCaptionFormats;

  /**
   * @param baseUri See {@link #baseUri}.
   * @param tags See {@link #tags}.
   * @param variants See {@link #variants}.
   * @param audios See {@link #audios}.
   * @param subtitles See {@link #subtitles}.
   * @param muxedAudioFormat See {@link #muxedAudioFormat}.
   * @param muxedCaptionFormats See {@link #muxedCaptionFormats}.
   */
  public HlsMasterPlaylist(String baseUri, List<String> tags, List<HlsUrl> variants,
      List<HlsUrl> audios, List<HlsUrl> subtitles, Format muxedAudioFormat,
      List<Format> muxedCaptionFormats) {
    super(baseUri, tags);
    this.variants = Collections.unmodifiableList(variants);
    this.audios = Collections.unmodifiableList(audios);
    this.subtitles = Collections.unmodifiableList(subtitles);
    this.muxedAudioFormat = muxedAudioFormat;
    this.muxedCaptionFormats = muxedCaptionFormats != null
        ? Collections.unmodifiableList(muxedCaptionFormats) : null;
  }

  /**
   * Returns a copy of this playlist which includes only the renditions identified by the given
   * urls.
   *
   * @param renditionUrls List of rendition urls.
   * @return A copy of this playlist which includes only the renditions identified by the given
   *     urls.
   */
  public HlsMasterPlaylist copy(List<String> renditionUrls) {
    return new HlsMasterPlaylist(baseUri, tags, copyRenditionList(variants, renditionUrls),
        copyRenditionList(audios, renditionUrls), copyRenditionList(subtitles, renditionUrls),
        muxedAudioFormat, muxedCaptionFormats);
  }

  /**
   * Creates a playlist with a single variant.
   *
   * @param variantUrl The url of the single variant.
   * @return A master playlist with a single variant for the provided url.
   */
  public static HlsMasterPlaylist createSingleVariantMasterPlaylist(String variantUrl) {
    List<HlsUrl> variant = Collections.singletonList(HlsUrl.createMediaPlaylistHlsUrl(variantUrl));
    List<HlsUrl> emptyList = Collections.emptyList();
    return new HlsMasterPlaylist(null, Collections.<String>emptyList(), variant, emptyList,
        emptyList, null, null);
  }

  private static List<HlsUrl> copyRenditionList(List<HlsUrl> variants, List<String> variantUrls) {
    List<HlsUrl> copyVariants = new ArrayList<>();
    for (int i = 0; i < variants.size(); i++) {
      HlsUrl variant = variants.get(i);
      if (variantUrls.contains(variant.url)) {
        copyVariants.add(variant);
      }
    }
    return copyVariants;
  }

}

@@ -3945,24 +3945,25 @@
 opyRendition
+s
 List(variant
@@ -3998,24 +3998,25 @@
 opyRendition
+s
 List(audios,
@@ -4041,24 +4041,25 @@
 opyRendition
+s
 List(subtitl
@@ -4739,16 +4739,17 @@
 endition
+s
 List(Lis
@@ -4758,23 +4758,25 @@
 HlsUrl%3E 
-variant
+rendition
 s, List%3C
@@ -4783,24 +4783,17 @@
 String%3E 
-variantU
+u
 rls) %7B%0A 
@@ -4811,24 +4811,28 @@
 Url%3E cop
-yVariant
+iedRendition
 s = new 
@@ -4843,16 +4843,27 @@
 yList%3C%3E(
+urls.size()
 );%0A    f
@@ -4881,23 +4881,25 @@
  0; i %3C 
-variant
+rendition
 s.size()
@@ -4924,25 +4924,29 @@
 Url 
-variant = variant
+rendition = rendition
 s.ge
@@ -4961,24 +4961,17 @@
     if (
-variantU
+u
 rls.cont
@@ -4975,23 +4975,25 @@
 ontains(
-variant
+rendition
 .url)) %7B
@@ -5008,29 +5008,35 @@
  cop
-yVariants.add(variant
+iedRenditions.add(rendition
 );%0A 
@@ -5066,16 +5066,20 @@
  cop
-yVariant
+iedRendition
 s;%0A 

Change copyRenditionsList parameters names