Coverage Report - org.crosswire.jsword.book.AbstractBookList
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractBookList
0%
0/16
0%
0/4
1.4
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2005 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.book;
 21  
 
 22  
 import java.util.Collections;
 23  
 import java.util.List;
 24  
 import java.util.concurrent.CopyOnWriteArrayList;
 25  
 
 26  
 import org.crosswire.common.util.CollectionUtil;
 27  
 
 28  
 /**
 29  
  * A basic implementation of BookList. The methods in this abstract class are
 30  
  * duplicates of those in Books, so bugs fixed in one should be fixed in the
 31  
  * other too.
 32  
  * 
 33  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 34  
  * @author Joe Walker
 35  
  */
 36  
 public abstract class AbstractBookList implements BookList {
 37  
     /**
 38  
      * Build a default BookList
 39  
      */
 40  0
     public AbstractBookList() {
 41  0
         listeners = new CopyOnWriteArrayList<BooksListener>();
 42  0
     }
 43  
 
 44  
     /* (non-Javadoc)
 45  
      * @see org.crosswire.jsword.book.BookList#getBooks(org.crosswire.jsword.book.BookFilter)
 46  
      */
 47  
     public List<Book> getBooks(BookFilter filter) {
 48  0
         List<Book> temp = CollectionUtil.createList(new BookFilterIterator(getBooks(), filter));
 49  0
         return Collections.unmodifiableList(temp);
 50  
     }
 51  
 
 52  
     /* (non-Javadoc)
 53  
      * @see org.crosswire.jsword.book.BookList#addBooksListener(org.crosswire.jsword.book.BooksListener)
 54  
      */
 55  
     public void addBooksListener(BooksListener li) {
 56  0
         listeners.add(li);
 57  0
     }
 58  
 
 59  
     /* (non-Javadoc)
 60  
      * @see org.crosswire.jsword.book.BookList#removeBooksListener(org.crosswire.jsword.book.BooksListener)
 61  
      */
 62  
     public  void removeBooksListener(BooksListener li) {
 63  0
         listeners.remove(li);
 64  0
     }
 65  
 
 66  
     /**
 67  
      * Kick of an event sequence
 68  
      * 
 69  
      * @param source
 70  
      *            The event source
 71  
      * @param book
 72  
      *            The changed Book
 73  
      * @param added
 74  
      *            Is it added?
 75  
      */
 76  
     protected void fireBooksChanged(Object source, Book book, boolean added) {
 77  0
         BooksEvent ev = new BooksEvent(source, book, added);
 78  0
         for (BooksListener listener : listeners) {
 79  0
             if (added) {
 80  0
                 listener.bookAdded(ev);
 81  
             } else {
 82  0
                 listener.bookRemoved(ev);
 83  
             }
 84  
         }
 85  0
     }
 86  
 
 87  
     /**
 88  
      * The list of listeners
 89  
      */
 90  0
     private List<BooksListener> listeners = new CopyOnWriteArrayList<BooksListener>();
 91  
 }