3 * Copyright (C) 2007 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
24 * An ordered collection.
27 public interface Gee.List<G> : Collection<G> {
29 * Returns a ListIterator that can be used for iteration over this list.
31 * @return a ListIterator that can be used for iteration over this list
33 public abstract new ListIterator<G> list_iterator ();
36 * Returns the item at the specified index in this list.
38 * @param index zero-based index of the item to be returned
40 * @return the item at the specified index in the list
42 public abstract G get (int index);
45 * Sets the item at the specified index in this list.
47 * @param index zero-based index of the item to be set
49 public abstract void set (int index, G item);
52 * Returns the index of the first occurence of the specified item in
55 * @return the index of the first occurence of the specified item, or
56 * -1 if the item could not be found
58 public abstract int index_of (G item);
61 * Inserts an item into this list at the specified position.
63 * @param index zero-based index at which item is inserted
64 * @param item item to insert into the list
66 public abstract void insert (int index, G item);
69 * Removes the item at the specified index of this list.
71 * @param index zero-based index of the item to be removed
73 * @return the removed element
75 public abstract G remove_at (int index);
78 * Returns a slice of this list.
80 * @param start zero-based index of the begin of the slice
81 * @param stop zero-based index after the end of the slice
83 * @return A list containing a slice of this list
85 public abstract List<G>? slice (int start, int stop);
88 * Returns the first item of the list. Fails if the list is empty.
90 * @return first item in the list
92 public virtual G first () {
97 * Returns the last item of the list. Fails if the list is empty.
99 * @return last item in the list
101 public virtual G last () {
102 return get (size - 1);
106 * Inserts items into this list for the input collection at the
107 * specified position.
109 * @param index zero-based index of the items to be inserted
110 * @param collection collection of items to be inserted
112 public virtual void insert_all (int index, Collection<G> collection) {
113 foreach (G item in collection) {
120 * Sorts items by comparing with the specified compare function.
122 * @param compare_func compare function to use to compare items
124 public virtual void sort (owned CompareDataFunc<G>? compare_func = null) {
125 if (compare_func == null) {
126 compare_func = Functions.get_compare_func_for (typeof (G));
128 TimSort.sort<G> (this, compare_func);
132 * The read-only view of this list.
134 public abstract new List<G> read_only_view { owned get; }
137 * Returns an immutable empty list.
139 * @return an immutable empty list
141 public static List<G> empty<G> () {
142 return new LinkedList<G> ().read_only_view;