1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.archive.crawler.settings;
25
26 /*** List of Integer values
27 *
28 * @author John Erik Halse
29 */
30 public class IntegerList extends ListType<Integer> {
31
32 private static final long serialVersionUID = -637584927948877976L;
33
34 /*** Creates a new IntegerList.
35 *
36 * @param name of the list.
37 * @param description of the list. This string should be suitable for using
38 * in a user interface.
39 */
40 public IntegerList(String name, String description) {
41 super(name, description);
42 }
43
44 /*** Creates a new IntegerList and initializes it with the values from
45 * another IntegerList.
46 *
47 * @param name of the list.
48 * @param description of the list. This string should be suitable for using
49 * in a user interface.
50 * @param l the list from which this lists gets its initial values.
51 */
52 public IntegerList(String name, String description, IntegerList l) {
53 super(name, description);
54 addAll(l);
55 }
56
57 /*** Creates a new IntegerList and initializes it with the values from
58 * an array of Integers.
59 *
60 * @param name of the list.
61 * @param description of the list. This string should be suitable for using
62 * in a user interface.
63 * @param l the array from which this lists gets its initial values.
64 */
65 public IntegerList(String name, String description, Integer[] l) {
66 super(name, description);
67 addAll(l);
68 }
69
70 /*** Creates a new IntegerList and initializes it with the values from
71 * an int array.
72 *
73 * @param name of the list.
74 * @param description of the list. This string should be suitable for using
75 * in a user interface.
76 * @param l the array from which this lists gets its initial values.
77 */
78 public IntegerList(String name, String description, int[] l) {
79 super(name, description);
80 addAll(l);
81 }
82
83 /*** Add a new {@link java.lang.Integer} at the specified index to this list.
84 *
85 * @param index index at which the specified element is to be inserted.
86 * @param element the value to be added.
87 */
88 public void add(int index, Integer element) {
89 super.add(index, element);
90 }
91
92 /*** Add a new <code>int</code> at the specified index to this list.
93 *
94 * @param index index at which the specified element is to be inserted.
95 * @param element the value to be added.
96 */
97 public void add(int index, int element) {
98 super.add(index, new Integer(element));
99 }
100
101 /*** Add a new {@link java.lang.Integer} at the end of this list.
102 *
103 * @param element the value to be added.
104 */
105 public void add(Integer element) {
106 super.add(element);
107 }
108
109 /*** Add a new int at the end of this list.
110 *
111 * @param element the value to be added.
112 */
113 public void add(int element) {
114 super.add(new Integer(element));
115 }
116
117 /*** Appends all of the elements in the specified list to the end of this
118 * list, in the order that they are returned by the specified lists's
119 * iterator.
120 *
121 * The behavior of this operation is unspecified if the specified
122 * collection is modified while the operation is in progress.
123 *
124 * @param l list whose elements are to be added to this list.
125 */
126 public void addAll(IntegerList l) {
127 super.addAll(l);
128 }
129
130 /*** Appends all of the elements in the specified array to the end of this
131 * list, in the same order that they are in the array.
132 *
133 * @param l array whose elements are to be added to this list.
134 */
135 public void addAll(Integer[] l) {
136 for (int i = 0; i < l.length; i++) {
137 add(l[i]);
138 }
139 }
140
141 /*** Appends all of the elements in the specified array to the end of this
142 * list, in the same order that they are in the array.
143 *
144 * @param l array whose elements are to be added to this list.
145 */
146 public void addAll(int[] l) {
147 for (int i = 0; i < l.length; i++) {
148 add(l[i]);
149 }
150 }
151
152 /*** Replaces the element at the specified position in this list with the
153 * specified element.
154 *
155 * @param index index at which the specified element is to be inserted.
156 * @param element element to be inserted.
157 * @return the element previously at the specified position.
158 */
159 public Integer set(int index, Integer element) {
160 return (Integer) super.set(index, element);
161 }
162
163 /*** Check if element is of right type for this list.
164 *
165 * If this method gets a String, it tries to convert it to
166 * the an Integer before eventually throwing an exception.
167 *
168 * @param element element to check.
169 * @return element of the right type.
170 * @throws ClassCastException is thrown if the element was of wrong type
171 * and could not be converted.
172 */
173 public Integer checkType(Object element) throws ClassCastException {
174 if (element instanceof Integer) {
175 return (Integer)element;
176 } else {
177 return (Integer)
178 SettingsHandler.StringToType(
179 (String) element,
180 SettingsHandler.INTEGER);
181 }
182 }
183 }