| DefaultKeyList.java |
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 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * 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 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: DefaultKeyList.java 2050 2010-12-09 15:31:45Z dmsmith $
21 */
22 package org.crosswire.jsword.passage;
23
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.List;
27
28 import org.crosswire.common.util.Logger;
29
30 /**
31 * A default implementation of Key.
32 *
33 * <p>
34 * This implementation uses <tt>java.util.List</tt> to store keys.
35 *
36 * @see gnu.lgpl.License for license details.<br>
37 * The copyright to this program is held by it's authors.
38 * @author Joe Walker [joe at eireneh dot com]
39 */
40 public class DefaultKeyList extends AbstractKeyList {
41 /**
42 * Simple ctor
43 */
44 public DefaultKeyList() {
45 super(null);
46 }
47
48 /**
49 * Simple ctor
50 */
51 public DefaultKeyList(Key parent, String name) {
52 super(name);
53 this.parent = parent;
54 }
55
56 /*
57 * (non-Javadoc)
58 *
59 * @see org.crosswire.jsword.passage.Key#canHaveChildren()
60 */
61 public boolean canHaveChildren() {
62 return false;
63 }
64
65 /*
66 * (non-Javadoc)
67 *
68 * @see org.crosswire.jsword.passage.Key#getChildCount()
69 */
70 public int getChildCount() {
71 return 0;
72 }
73
74 /*
75 * (non-Javadoc)
76 *
77 * @see org.crosswire.jsword.passage.Key#getCardinality()
78 */
79 public int getCardinality() {
80 return keys.size();
81 }
82
83 /*
84 * (non-Javadoc)
85 *
86 * @see org.crosswire.jsword.passage.Key#isEmpty()
87 */
88 @Override
89 public boolean isEmpty() {
90 return keys.isEmpty();
91 }
92
93 /*
94 * (non-Javadoc)
95 *
96 * @see
97 * org.crosswire.jsword.passage.Key#contains(org.crosswire.jsword.passage
98 * .Key)
99 */
100 @Override
101 public boolean contains(Key key) {
102 return keys.contains(key);
103 }
104
105 /*
106 * (non-Javadoc)
107 *
108 * @see org.crosswire.jsword.passage.Key#iterator()
109 */
110 public Iterator<Key> iterator() {
111 return keys.iterator();
112 }
113
114 /*
115 * (non-Javadoc)
116 *
117 * @see
118 * org.crosswire.jsword.passage.Key#add(org.crosswire.jsword.passage.Key)
119 */
120 public void addAll(Key key) {
121 keys.add(key);
122 }
123
124 /*
125 * (non-Javadoc)
126 *
127 * @see
128 * org.crosswire.jsword.passage.Key#remove(org.crosswire.jsword.passage.Key)
129 */
130 public void removeAll(Key key) {
131 keys.remove(key);
132 }
133
134 /*
135 * (non-Javadoc)
136 *
137 * @see org.crosswire.jsword.passage.Key#clear()
138 */
139 public void clear() {
140 keys.clear();
141 }
142
143 /*
144 * (non-Javadoc)
145 *
146 * @see org.crosswire.jsword.passage.Key#get(int)
147 */
148 public Key get(int index) {
149 return keys.get(index);
150 }
151
152 /*
153 * (non-Javadoc)
154 *
155 * @see
156 * org.crosswire.jsword.passage.Key#indexOf(org.crosswire.jsword.passage
157 * .Key)
158 */
159 public int indexOf(Key that) {
160 return keys.indexOf(that);
161 }
162
163 /*
164 * (non-Javadoc)
165 *
166 * @see org.crosswire.jsword.passage.Key#getParent()
167 */
168 public Key getParent() {
169 return parent;
170 }
171
172 /*
173 * (non-Javadoc)
174 *
175 * @see org.crosswire.jsword.passage.Key#blur(int)
176 */
177 public void blur(int by, RestrictionType restrict) {
178 log.warn("attempt to blur a non-blur-able list");
179 }
180
181 /**
182 * The parent of this key
183 */
184 private Key parent;
185
186 /**
187 * The store of Keys
188 */
189 private List<Key> keys = new ArrayList<Key>();
190
191 /**
192 * Serialization ID
193 */
194 private static final long serialVersionUID = -1633375337613230599L;
195
196 /**
197 * The log stream
198 */
199 private static final Logger log = Logger.getLogger(DefaultKeyList.class);
200 }
201