gt: 		if (location < 0 || location > playList.size()) {
context: /*
   * aTunes
   * Copyright (C) Alex Aranda, Sylvain Gaudard and contributors
   *
   * See http://www.atunes.org/wiki/index.php?title=Contributing for information about contributors
   *
   * http://www.atunes.org
   * http://sourceforge.net/projects/atunes
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version 2
   * of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   */
  
  package net.sourceforge.atunes.kernel.modules.playlist;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.List;
  
  import net.sourceforge.atunes.gui.GuiUtils;
  import net.sourceforge.atunes.kernel.AbstractHandler;
  import net.sourceforge.atunes.kernel.PlayListEventListeners;
  import net.sourceforge.atunes.model.IApplicationArguments;
  import net.sourceforge.atunes.model.IAudioObject;
  import net.sourceforge.atunes.model.IAudioObjectComparator;
  import net.sourceforge.atunes.model.IContextHandler;
  import net.sourceforge.atunes.model.IDialogFactory;
  import net.sourceforge.atunes.model.IFilter;
  import net.sourceforge.atunes.model.IFilterHandler;
  import net.sourceforge.atunes.model.IListMessageDialog;
  import net.sourceforge.atunes.model.ILocalAudioObject;
  import net.sourceforge.atunes.model.ILocalAudioObjectValidator;
  import net.sourceforge.atunes.model.IPlayList;
  import net.sourceforge.atunes.model.IPlayListAudioObject;
  import net.sourceforge.atunes.model.IPlayListEventListener;
  import net.sourceforge.atunes.model.IPlayListHandler;
  import net.sourceforge.atunes.model.IPlayListIOService;
  import net.sourceforge.atunes.model.IPlayerHandler;
  import net.sourceforge.atunes.model.IRepository;
  import net.sourceforge.atunes.model.IRepositoryHandler;
  import net.sourceforge.atunes.model.ISearchHandler;
  import net.sourceforge.atunes.model.ISearchNode;
  import net.sourceforge.atunes.model.IStatePlayer;
  import net.sourceforge.atunes.model.IStatePlaylist;
  import net.sourceforge.atunes.utils.CollectionUtils;
  import net.sourceforge.atunes.utils.I18nUtils;
  import net.sourceforge.atunes.utils.Logger;
  import net.sourceforge.atunes.utils.StringUtils;
  
  /**
   * The Class PlayListHandler.
   */
  public final class PlayListHandler extends AbstractHandler implements
  		IPlayListHandler, IPlayListEventListener {
  
  	/** The play list tab controller. */
  	private PlayListTabController playListTabController;
  
  	/**
  	 * Play list Controller
  	 */
  	private PlayListController playListController;
  
  	private IPlayerHandler playerHandler;
  
  	private PlayListEventListeners playListEventListeners;
  
  	private IFilter playListFilter;
  
  	private IFilterHandler filterHandler;
  
  	private PlayListNameCreator playListNameCreator;
  
  	private PlayListPersistor playListPersistor;
  
  	private ListOfPlayListsCreator listOfPlayListsCreator;
  
  	private IPlayListsContainer playListsContainer;
  
  	private IStatePlayer statePlayer;
  
  	private IStatePlaylist statePlaylist;
  
  	private PlayListCreator playListCreator;
  
  	private PlayListInformationInStatusBar playListInformationInStatusBar;
  
  	private IContextHandler contextHandler;
  
  	private IDialogFactory dialogFactory;
  
  	private ISearchHandler searchHandler;
  
  	/**
  	 * @param searchHandler
  	 */
  	public void setSearchHandler(final ISearchHandler searchHandler) {
  		this.searchHandler = searchHandler;
  	}
  
  	/**
  	 * @param dialogFactory
  	 */
  	public void setDialogFactory(final IDialogFactory dialogFactory) {
  		this.dialogFactory = dialogFactory;
  	}
  
  	/**
  	 * @param contextHandler
  	 */
  	public void setContextHandler(final IContextHandler contextHandler) {
  		this.contextHandler = contextHandler;
  	}
  
  	/**
  	 * @param playListInformationInStatusBar
  	 */
  	public void setPlayListInformationInStatusBar(
  			final PlayListInformationInStatusBar playListInformationInStatusBar) {
  		this.playListInformationInStatusBar = playListInformationInStatusBar;
  	}
  
  	/**
  	 * @param playListCreator
  	 */
  	public void setPlayListCreator(final PlayListCreator playListCreator) {
  		this.playListCreator = playListCreator;
  	}
  
  	/**
  	 * @param statePlaylist
  	 */
  	public void setStatePlaylist(final IStatePlaylist statePlaylist) {
  		this.statePlaylist = statePlaylist;
  	}
  
  	/**
  	 * @param statePlayer
  	 */
  	public void setStatePlayer(final IStatePlayer statePlayer) {
  		this.statePlayer = statePlayer;
  	}
  
  	/**
  	 * @param playListsContainer
  	 */
  	public void setPlayListsContainer(
  			final IPlayListsContainer playListsContainer) {
  		this.playListsContainer = playListsContainer;
  	}
  
  	/**
  	 * @param playListTabController
  	 */
  	public void setPlayListTabController(
  			final PlayListTabController playListTabController) {
  		this.playListTabController = playListTabController;
  	}
  
  	/**
  	 * @param playListController
  	 */
  	public void setPlayListController(
  			final PlayListController playListController) {
  		this.playListController = playListController;
  	}
  
  	/**
  	 * @param listOfPlayListsCreator
  	 */
  	public void setListOfPlayListsCreator(
  			final ListOfPlayListsCreator listOfPlayListsCreator) {
  		this.listOfPlayListsCreator = listOfPlayListsCreator;
  	}
  
  	/**
  	 * @param playListPersistor
  	 */
  	public void setPlayListPersistor(final PlayListPersistor playListPersistor) {
  		this.playListPersistor = playListPersistor;
  	}
  
  	/**
  	 * @param playListNameCreator
  	 */
  	public void setPlayListNameCreator(
  			final PlayListNameCreator playListNameCreator) {
  		this.playListNameCreator = playListNameCreator;
  	}
  
  	/**
  	 * @param filterHandler
  	 */
  	public void setFilterHandler(final IFilterHandler filterHandler) {
  		this.filterHandler = filterHandler;
  	}
  
  	/**
  	 * @param playListFilter
  	 */
  	public void setPlayListFilter(final IFilter playListFilter) {
  		this.playListFilter = playListFilter;
  	}
  
  	/**
  	 * @param playListEventListeners
  	 */
  	public void setPlayListEventListeners(
  			final PlayListEventListeners playListEventListeners) {
  		this.playListEventListeners = playListEventListeners;
  	}
  
  	/**
  	 * @param playerHandler
  	 */
  	public void setPlayerHandler(final IPlayerHandler playerHandler) {
  		this.playerHandler = playerHandler;
  	}
  
  	@Override
  	protected void initHandler() {
  		// Add audio file removed listener
  		getBean(IRepositoryHandler.class).addAudioFilesRemovedListener(this);
  	}
  
  	@Override
  	public void applicationStarted() {
  	}
  
  	@Override
  	public void allHandlersInitialized() {
  		// Create drag and drop listener
  		this.playListController.enableDragAndDrop();
  	}
  
  	/**
  	 * Sets visible play list as active
  	 */
  	@Override
  	public void setVisiblePlayListActive() {
  		this.playListsContainer.setVisiblePlayListActive();
  	}
  
  	@Override
  	public int getPlayListCount() {
  		return this.playListsContainer.getPlayListsCount();
  	}
  
  	@Override
  	public void newPlayList(final List<IAudioObject> audioObjects) {
  		newPlayList(this.playListNameCreator.getNameForPlaylist(
  				this.playListsContainer, null), audioObjects);
  	}
  
  	@Override
  	public void newPlayList(final String nameOfNewPlayList,
  			final List<? extends IAudioObject> audioObjects) {
  		addNewPlayList(this.playListCreator.getNewPlayList(nameOfNewPlayList,
  				audioObjects));
  		playListsChanged();
  	}
  
  	@Override
  	public void newDynamicPlayList(final ISearchNode query,
  			final Collection<IAudioObject> initialObjects) {
  		String name = query.toString();
  
  		addNewPlayList(this.playListCreator.getNewDynamicPlayList(name, query,
  				initialObjects, 0, null));
  		playListsChanged();
  	}
  
  	void addNewPlayList(final IPlayList playList) {
  		// Each play list added to container must have its listeners, state
  		// player and mode
  		playList.setStatePlayer(this.statePlayer);
  		playList.setMode(PlayListMode.getPlayListMode(playList,
  				this.statePlayer));
  		playList.setPlayListEventListeners(this.playListEventListeners);
  
  		this.playListsContainer.addPlayList(playList);
  		this.playListTabController.newPlayList(this.playListNameCreator
  				.getNameForPlaylist(this.playListsContainer, playList),
  				getBean(PlayListIconSelector.class).getIcon(playList));
  	}
  
  	@Override
  	public void renameCurrentVisiblePlayList(final String newName) {
  		if (newName != null) {
  			int index = this.playListTabController.getSelectedPlayListIndex();
  			this.playListsContainer.getPlayListAt(index).setName(newName);
  			this.playListTabController.renamePlayList(index, newName);
  			playListsChanged();
  		}
  	}
  
  	@Override
  	public String getCurrentVisiblePlayListName() {
  		return this.playListTabController
  				.getPlayListName(this.playListTabController
  						.getSelectedPlayListIndex());
  	}
  
  	@Override
  	public void nextPlayList() {
  		int currentIndex = this.playListsContainer.getVisiblePlayListIndex();
  		if (currentIndex < (getPlayListCount() - 1)) {
  			this.playListTabController.forceSwitchTo(currentIndex + 1);
  		} else {
  			this.playListTabController.forceSwitchTo(0);
  		}
  	}
  
  	@Override
  	public void previousPlayList() {
  		int currentIndex = this.playListsContainer.getVisiblePlayListIndex();
  		if (currentIndex == 0) {
  			this.playListTabController.forceSwitchTo(getPlayListCount() - 1);
  		} else {
  			this.playListTabController.forceSwitchTo(currentIndex - 1);
  		}
  	}
  
  	@Override
  	public void switchToPlaylist(final int index) {
  		// If play list is the same, do nothing, except if this method is called
  		// when deleting a play list
  		if (index == this.playListsContainer.getVisiblePlayListIndex()) {
  			return;
  		}
  
  		// don't stop player if user has setup the option
  		if (this.statePlaylist.isStopPlayerOnPlayListSwitch()) {
  			this.playerHandler.stopCurrentAudioObject(false);
  		}
  
  		// Remove filter from current play list before change play list
  		setFilter(null);
  
  		this.playListsContainer.setVisiblePlayListIndex(index);
  
  		IPlayList newSelectedPlayList = this.playListsContainer
  				.getPlayListAt(index);
  
  		// Set selection interval to none
  		this.playListController.clearSelection();
  
  		setPlayList(newSelectedPlayList);
  	}
  
  	/**
  	 * Sets the play list.
  	 * 
  	 * @param playList
  	 *            the new play list
  	 */
  	void setPlayList(final IPlayList playList) {
  		GuiUtils.callInEventDispatchThread(new Runnable() {
  			@Override
  			public void run() {
  				// Set selection interval to none
  				PlayListHandler.this.playListController.clearSelection();
  
  				PlayListHandler.this.playListInformationInStatusBar
  						.showPlayListInformation(playList);
  
  				// Update table model
  				PlayListHandler.this.playListController
  						.setVisiblePlayList(getVisiblePlayList());
  				PlayListHandler.this.playListController.refreshPlayList();
  
  				// If playlist is active then perform an auto scroll
  				if (isActivePlayListVisible()) {
  					PlayListHandler.this.playListController
  							.scrollPlayList(false);
  				}
  			}
  		});
  	}
  
  	@Override
  	public boolean isVisiblePlayList(final int index) {
  		return this.playListsContainer.getVisiblePlayListIndex() == index;
  	}
  
  	@Override
  	public IAudioObject getCurrentAudioObjectFromVisiblePlayList() {
  		if (getVisiblePlayList() != null) {
  			return getVisiblePlayList().getCurrentAudioObject();
  		}
  		return null;
  	}
  
  	@Override
  	public IAudioObject getCurrentAudioObjectFromCurrentPlayList() {
  		if (getActivePlayList() != null) {
  			return getActivePlayList().getCurrentAudioObject();
  		}
  		return null;
  	}
  
  	@Override
  	public IPlayList getActivePlayList() {
  		return this.playListsContainer.getActivePlayList();
  	}
  
  	@Override
  	public IPlayList getVisiblePlayList() {
  		return this.playListsContainer.getVisiblePlayList();
  	}
  
  	@Override
  	public void addToVisiblePlayList(
  			final List<? extends IAudioObject> audioObjects) {
  		addToPlayList(getVisiblePlayList().size(), audioObjects,
  				getVisiblePlayList());
  	}
  
  	@Override
  	public void addToVisiblePlayList(final int location,
  			final List<? extends IAudioObject> audioObjects) {
  		addToPlayList(location, audioObjects, getVisiblePlayList());
  	}
  
  	@Override
  	public void addToActivePlayList(
  			final List<? extends IAudioObject> audioObjects) {
  		addToPlayList(getActivePlayList().size(), audioObjects,
  				getActivePlayList());
  	}
  
  	@Override
  	public void addToActivePlayList(final int location,
  			final List<? extends IAudioObject> audioObjects) {
  		addToPlayList(location, audioObjects, getActivePlayList());
  	}
  
  	private void addToPlayList(final int location,
  			final List<? extends IAudioObject> audioObjects,
  			final IPlayList playList) {
  		// If null or empty, nothing to do
  		if (CollectionUtils.isEmpty(audioObjects)) {
  			return;
  		}
  
  		// If play list is filtered remove filter
  		if (isFiltered()) {
  			setFilter(null);
  		}
  
  		int newLocation = location;
  		// Add audio objects to play list
  