package it.unipr.mobdev;

import java.util.ArrayList;

import android.util.Log;

public class BookmarkManager {

	/*
	 * The instance is static so it is shared among all instances of the class. It is also private
	 * so it is accessible only within the class.
	 */
	private static BookmarkManager instance = null;
	
	private ArrayList<BookmarkDescriptor> bookmarkList = null;

	/*
	 * The constructor is private so it is accessible only within the class.
	 */
	private BookmarkManager(){
		Log.d(MainActivity.TAG,"Bookmakr Manager Created !");
		this.bookmarkList = new ArrayList<BookmarkDescriptor>();
	}
	
	public static BookmarkManager getInstance(){
		/*
		 * The constructor is called only if the static instance is null, so only the first time 
		 * that the getInstance() method is invoked.
		 * All the other times the same instance object is returned.
		 */
		if(instance == null)
			instance = new BookmarkManager();
		return instance;
	}
	
	public int addBookmark(BookmarkDescriptor bookmark){
		if(!this.bookmarkList.contains(bookmark))
		{
			this.bookmarkList.add(bookmark);
			return 0;
		}
		else
			return -1;
	}
	
	public void replaceBookmark(int position, BookmarkDescriptor bookmark){
		this.bookmarkList.set(position, bookmark);
	}
	
	public void removeBookmark(int position){
		this.bookmarkList.remove(position);
	}
	
	public void removeBookmark(BookmarkDescriptor bookmark){
		this.bookmarkList.remove(bookmark);
	}
	
	public ArrayList<BookmarkDescriptor> getBookmarkList(){
		return bookmarkList;
	}
	
}

