| 1 | /* List.java -- An ordered collection which allows indexed access
|
|---|
| 2 | Copyright (C) 1998, 2001 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.util;
|
|---|
| 40 |
|
|---|
| 41 | /**
|
|---|
| 42 | * An ordered collection (also known as a list). This collection allows
|
|---|
| 43 | * access to elements by position, as well as control on where elements
|
|---|
| 44 | * are inserted. Unlike sets, duplicate elements are permitted by this
|
|---|
| 45 | * general contract (if a subclass forbids duplicates, this should be
|
|---|
| 46 | * documented).
|
|---|
| 47 | * <p>
|
|---|
| 48 | *
|
|---|
| 49 | * List places additional requirements on <code>iterator</code>,
|
|---|
| 50 | * <code>add</code>, <code>remove</code>, <code>equals</code>, and
|
|---|
| 51 | * <code>hashCode</code>, in addition to requiring more methods. List
|
|---|
| 52 | * indexing is 0-based (like arrays), although some implementations may
|
|---|
| 53 | * require time proportional to the index to obtain an arbitrary element.
|
|---|
| 54 | * The List interface is incompatible with Set; you cannot implement both
|
|---|
| 55 | * simultaneously.
|
|---|
| 56 | * <p>
|
|---|
| 57 | *
|
|---|
| 58 | * Lists also provide a <code>ListIterator</code> which allows bidirectional
|
|---|
| 59 | * traversal and other features atop regular iterators. Lists can be
|
|---|
| 60 | * searched for arbitrary elements, and allow easy insertion and removal
|
|---|
| 61 | * of multiple elements in one method call.
|
|---|
| 62 | * <p>
|
|---|
| 63 | *
|
|---|
| 64 | * Note: While lists may contain themselves as elements, this leads to
|
|---|
| 65 | * undefined (usually infinite recursive) behavior for some methods like
|
|---|
| 66 | * hashCode or equals.
|
|---|
| 67 | *
|
|---|
| 68 | * @author Original author unknown
|
|---|
| 69 | * @author Eric Blake <[email protected]>
|
|---|
| 70 | * @see Collection
|
|---|
| 71 | * @see Set
|
|---|
| 72 | * @see ArrayList
|
|---|
| 73 | * @see LinkedList
|
|---|
| 74 | * @see Vector
|
|---|
| 75 | * @see Arrays#asList(Object[])
|
|---|
| 76 | * @see Collections#nCopies(int, Object)
|
|---|
| 77 | * @see Collections#EMPTY_LIST
|
|---|
| 78 | * @see AbstractList
|
|---|
| 79 | * @see AbstractSequentialList
|
|---|
| 80 | * @since 1.2
|
|---|
| 81 | * @status updated to 1.4
|
|---|
| 82 | */
|
|---|
| 83 | public interface List extends Collection
|
|---|
| 84 | {
|
|---|
| 85 | /**
|
|---|
| 86 | * Insert an element into the list at a given position (optional operation).
|
|---|
| 87 | * This shifts all existing elements from that position to the end one
|
|---|
| 88 | * index to the right. This version of add has no return, since it is
|
|---|
| 89 | * assumed to always succeed if there is no exception.
|
|---|
| 90 | *
|
|---|
| 91 | * @param index the location to insert the item
|
|---|
| 92 | * @param o the object to insert
|
|---|
| 93 | * @throws UnsupportedOperationException if this list does not support the
|
|---|
| 94 | * add operation
|
|---|
| 95 | * @throws IndexOutOfBoundsException if index < 0 || index > size()
|
|---|
| 96 | * @throws ClassCastException if o cannot be added to this list due to its
|
|---|
| 97 | * type
|
|---|
| 98 | * @throws IllegalArgumentException if o cannot be added to this list for
|
|---|
| 99 | * some other reason
|
|---|
| 100 | */
|
|---|
| 101 | void add(int index, Object o);
|
|---|
| 102 |
|
|---|
| 103 | /**
|
|---|
| 104 | * Add an element to the end of the list (optional operation). If the list
|
|---|
| 105 | * imposes restraints on what can be inserted, such as no null elements,
|
|---|
| 106 | * this should be documented.
|
|---|
| 107 | *
|
|---|
| 108 | * @param o the object to add
|
|---|
| 109 | * @return true, as defined by Collection for a modified list
|
|---|
| 110 | * @throws UnsupportedOperationException if this list does not support the
|
|---|
| 111 | * add operation
|
|---|
| 112 | * @throws ClassCastException if o cannot be added to this list due to its
|
|---|
| 113 | * type
|
|---|
| 114 | * @throws IllegalArgumentException if o cannot be added to this list for
|
|---|
| 115 | * some other reason
|
|---|
| 116 | */
|
|---|
| 117 | boolean add(Object o);
|
|---|
| 118 |
|
|---|
| 119 | /**
|
|---|
| 120 | * Insert the contents of a collection into the list at a given position
|
|---|
|
|---|