001: /* LongList
002: *
003: * $Id: LongList.java 4648 2006-09-25 16:25:53Z paul_jack $
004: * Created on Dec 18, 2003
005: *
006: * Copyright (C) 2003 Internet Archive.
007: *
008: * This file is part of the Heritrix web crawler (crawler.archive.org).
009: *
010: * Heritrix is free software; you can redistribute it and/or modify
011: * it under the terms of the GNU Lesser Public License as published by
012: * the Free Software Foundation; either version 2.1 of the License, or
013: * any later version.
014: *
015: * Heritrix is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU Lesser Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser Public License
021: * along with Heritrix; if not, write to the Free Software
022: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023: */
024: package org.archive.crawler.settings;
025:
026: /** List of Long values
027: *
028: * @author John Erik Halse
029: */
030: public class LongList extends ListType<Long> {
031:
032: private static final long serialVersionUID = -7542494945185808903L;
033:
034: /** Creates a new LongList.
035: *
036: * @param name of the list.
037: * @param description of the list. This string should be suitable for using
038: * in a user interface.
039: */
040: public LongList(String name, String description) {
041: super (name, description);
042: }
043:
044: /** Creates a new LongList and initializes it with the values from
045: * another LongList.
046: *
047: * @param name of the list.
048: * @param description of the list. This string should be suitable for using
049: * in a user interface.
050: * @param l the list from which this lists gets its initial values.
051: */
052: public LongList(String name, String description, LongList l) {
053: super (name, description);
054: addAll(l);
055: }
056:
057: /** Creates a new LongList and initializes it with the values from
058: * an array of {@link java.lang.Long}.
059: *
060: * @param name of the list.
061: * @param description of the list. This string should be suitable for using
062: * in a user interface.
063: * @param l the array from which this lists gets its initial values.
064: */
065: public LongList(String name, String description, Long[] l) {
066: super (name, description);
067: addAll(l);
068: }
069:
070: /** Creates a new LongList and initializes it with the values from
071: * an array of long.
072: *
073: * @param name of the list.
074: * @param description of the list. This string should be suitable for using
075: * in a user interface.
076: * @param l the array from which this lists gets its initial values.
077: */
078: public LongList(String name, String description, long[] l) {
079: super (name, description);
080: addAll(l);
081: }
082:
083: /** Add a new {@link java.lang.Long} at the specified index to this list.
084: *
085: * @param index index at which the specified element is to be inserted.
086: * @param element the value to be added.
087: */
088: public void add(int index, Long element) {
089: super .add(index, element);
090: }
091:
092: /** Add a new <code>long</code> at the specified index to this list.
093: *
094: * @param index index at which the specified element is to be inserted.
095: * @param element the value to be added.
096: */
097: public void add(int index, long element) {
098: super .add(index, new Long(element));
099: }
100:
101: /** Add a new {@link java.lang.Long} at the end of this list.
102: *
103: * @param element the value to be added.
104: */
105: public void add(Long element) {
106: super .add(element);
107: }
108:
109: /** Add a new long at the end of this list.
110: *
111: * @param element the value to be added.
112: */
113: public void add(long element) {
114: super .add(new Long(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(LongList 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(Long[] 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(long[] 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 Long set(int index, Long element) {
160: return (Long) 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 Long 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 Long checkType(Object element) throws ClassCastException {
174: if (element instanceof Long) {
175: return (Long) element;
176: } else {
177: return (Long) SettingsHandler.StringToType(
178: (String) element, SettingsHandler.LONG);
179: }
180: }
181: }
|