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, 2007 - 2016
18   *
19   */
20  package org.crosswire.jsword.book.basic;
21  
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.List;
25  
26  import org.crosswire.jsword.book.Book;
27  import org.crosswire.jsword.book.BookData;
28  import org.crosswire.jsword.book.Bookmark;
29  import org.crosswire.jsword.index.search.SearchRequest;
30  
31  /**
32   * A Bookmark remembers a particular view of one or more Books. What is viewed
33   * regarding a book set is either a SearchRequest or a key lookup request.
34   * 
35   * @see gnu.lgpl.License The GNU Lesser General Public License for details.
36   * @author DM Smith
37   */
38  public class DefaultBookmark implements Bookmark {
39      /**
40       * Create an empty default bookmark
41       */
42      public DefaultBookmark() {
43          books = new ArrayList<Book>();
44      }
45  
46      /* (non-Javadoc)
47       * @see org.crosswire.jsword.book.Bookmark#addBook(org.crosswire.jsword.book.Book)
48       */
49      public void addBook(Book book) {
50          books.add(book);
51      }
52  
53      /* (non-Javadoc)
54       * @see org.crosswire.jsword.book.Bookmark#getBooks()
55       */
56      public List<Book> getBooks() {
57          return Collections.unmodifiableList(books);
58      }
59  
60      /* (non-Javadoc)
61       * @see org.crosswire.jsword.book.Bookmark#setSearchRequest(org.crosswire.jsword.index.search.SearchRequest)
62       */
63      public void setSearchRequest(SearchRequest request) {
64          searchRequest = request;
65          lookupRequest = null;
66      }
67  
68      /* (non-Javadoc)
69       * @see org.crosswire.jsword.book.Bookmark#getSearchRequest()
70       */
71      public SearchRequest getSearchRequest() {
72          return searchRequest;
73      }
74  
75      /* (non-Javadoc)
76       * @see org.crosswire.jsword.book.Bookmark#setLookupRequest(java.lang.String)
77       */
78      public void setLookupRequest(String request) {
79          lookupRequest = request;
80          searchRequest = null;
81      }
82  
83      /* (non-Javadoc)
84       * @see org.crosswire.jsword.book.Bookmark#getLookupRequest()
85       */
86      public String getLookupRequest() {
87          return lookupRequest;
88      }
89  
90      /* (non-Javadoc)
91       * @see org.crosswire.jsword.book.Bookmark#getBookData()
92       */
93      public BookData getBookData() {
94          return null;
95      }
96  
97      @Override
98      public DefaultBookmark clone() {
99          DefaultBookmark clone = null;
100         try {
101             clone = (DefaultBookmark) super.clone();
102         } catch (CloneNotSupportedException e) {
103             assert false : e;
104         }
105         return clone;
106     }
107 
108     /**
109      * The list of books.
110      */
111     private transient List<Book> books;
112 
113     /**
114      * The lookup request.
115      */
116     private String lookupRequest;
117 
118     /**
119      * The search request.
120      */
121     private SearchRequest searchRequest;
122 
123     /**
124      * Serialization ID
125      */
126     private static final long serialVersionUID = 6959196267292499574L;
127 }
128