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 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.passage; 21 22 import java.util.ArrayList; 23 import java.util.Iterator; 24 import java.util.List; 25 26 import org.slf4j.Logger; 27 import org.slf4j.LoggerFactory; 28 29 /** 30 * A default implementation of Key. 31 * 32 * <p> 33 * This implementation uses <tt>java.util.List</tt> to store keys. 34 * 35 * @see gnu.lgpl.License The GNU Lesser General Public License for details. 36 * @author Joe Walker 37 */ 38 public class DefaultKeyList extends AbstractKeyList { 39 /** 40 * Simple ctor 41 */ 42 public DefaultKeyList() { 43 super(null); 44 } 45 46 /** 47 * Simple ctor 48 * @param parent 49 * @param name 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 = LoggerFactory.getLogger(DefaultKeyList.class); 200 } 201