| SetKeyList.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: SetKeyList.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 import java.util.Set;
28
29 import org.crosswire.common.util.Logger;
30
31 /**
32 * A Key that uses a Set of Keys as it's store of data.
33 *
34 * @see gnu.lgpl.License for license details.<br>
35 * The copyright to this program is held by it's authors.
36 * @author Joe Walker [joe at eireneh dot com]
37 */
38 public class SetKeyList extends AbstractKeyList {
39 /**
40 * Simple ctor
41 */
42 public SetKeyList(Set<Key> set) {
43 this(set, null, null);
44 }
45
46 /**
47 * Simple ctor
48 */
49 public SetKeyList(Set<Key> set, String name) {
50 this(set, null, name);
51 }
52
53 /**
54 * Simple ctor
55 */
56 public SetKeyList(Set<Key> set, Key parent) {
57 this(set, parent, null);
58 }
59
60 /**
61 * Simple ctor
62 */
63 public SetKeyList(Set<Key> set, Key parent, String name) {
64 super(name);
65 this.parent = parent;
66 list.addAll(set);
67 }
68
69 /*
70 * (non-Javadoc)
71 *
72 * @see
73 * org.crosswire.jsword.passage.Key#add(org.crosswire.jsword.passage.Key)
74 */
75 public void addAll(Key key) {
76 list.add(key);
77 }
78
79 /*
80 * (non-Javadoc)
81 *
82 * @see org.crosswire.jsword.passage.Key#clear()
83 */
84 public void clear() {
85 list.clear();
86 }
87
88 /*
89 * (non-Javadoc)
90 *
91 * @see
92 * org.crosswire.jsword.passage.Key#contains(org.crosswire.jsword.passage
93 * .Key)
94 */
95 @Override
96 public boolean contains(Key key) {
97 return list.contains(key);
98 }
99
100 /*
101 * (non-Javadoc)
102 *
103 * @see java.lang.Object#equals(java.lang.Object)
104 */
105 @Override
106 public boolean equals(Object obj) {
107 if (obj instanceof SetKeyList) {
108 SetKeyList that = (SetKeyList) obj;
109 return list.equals(that.list);
110 }
111 return false;
112 }
113
114 /*
115 * (non-Javadoc)
116 *
117 * @see java.lang.Object#hashCode()
118 */
119 @Override
120 public int hashCode() {
121 return list.hashCode();
122 }
123
124 /*
125 * (non-Javadoc)
126 *
127 * @see org.crosswire.jsword.passage.Key#isEmpty()
128 */
129 @Override
130 public boolean isEmpty() {
131 return list.isEmpty();
132 }
133
134 /*
135 * (non-Javadoc)
136 *
137 * @see org.crosswire.jsword.passage.Key#iterator()
138 */
139 public Iterator<Key> iterator() {
140 return list.iterator();
141 }
142
143 /*
144 * (non-Javadoc)
145 *
146 * @see
147 * org.crosswire.jsword.passage.Key#remove(org.crosswire.jsword.passage.Key)
148 */
149 public void removeAll(Key key) {
150 list.remove(key);
151 }
152
153 /*
154 * (non-Javadoc)
155 *
156 * @see org.crosswire.jsword.passage.Key#getCardinality()
157 */
158 public int getCardinality() {
159 return list.size();
160 }
161
162 /*
163 * (non-Javadoc)
164 *
165 * @see org.crosswire.jsword.passage.Key#canHaveChildren()
166 */
167 public boolean canHaveChildren() {
168 return false;
169 }
170
171 /*
172 * (non-Javadoc)
173 *
174 * @see org.crosswire.jsword.passage.Key#getChildCount()
175 */
176 public int getChildCount() {
177 return 0;
178 }
179
180 /*
181 * (non-Javadoc)
182 *
183 * @see org.crosswire.jsword.passage.Key#get(int)
184 */
185 public Key get(int index) {
186 return list.get(index);
187 }
188
189 /*
190 * (non-Javadoc)
191 *
192 * @see
193 * org.crosswire.jsword.passage.Key#indexOf(org.crosswire.jsword.passage
194 * .Key)
195 */
196 public int indexOf(Key that) {
197 return list.indexOf(that);
198 }
199
200 /*
201 * (non-Javadoc)
202 *
203 * @see org.crosswire.jsword.passage.Key#getParent()
204 */
205 public Key getParent() {
206 return parent;
207 }
208
209 /*
210 * (non-Javadoc)
211 *
212 * @see org.crosswire.jsword.passage.Key#blur(int)
213 */
214 public void blur(int by, RestrictionType restrict) {
215 log.warn("attempt to blur a non-blur-able list");
216 }
217
218 /**
219 * The parent of this key
220 */
221 private Key parent;
222
223 /**
224 * The Set that we are proxying to
225 */
226 private List<Key> list = new ArrayList<Key>();
227
228 /**
229 * Serialization ID
230 */
231 private static final long serialVersionUID = -1460162676283475117L;
232
233 /**
234 * The log stream
235 */
236 private static final Logger log = Logger.getLogger(SetKeyList.class);
237 }
238