File: abstractlist.vala

package info (click to toggle)
libgee 0.6.8-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,060 kB
  • ctags: 10,764
  • sloc: ansic: 59,313; sh: 11,421; makefile: 294; perl: 106
file content (119 lines) | stat: -rw-r--r-- 2,614 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* abstractlist.vala
 *
 * Copyright (C) 2007  Jürg Billeter
 * Copyright (C) 2009  Didier Villevalois
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Didier 'Ptitjes' Villevalois <ptitjes@free.fr>
 */

/**
 * Skeletal implementation of the {@link List} interface.
 *
 * Contains common code shared by all list implementations.
 *
 * @see ArrayList
 * @see LinkedList
 */
public abstract class Gee.AbstractList<G> : Gee.AbstractCollection<G>, List<G> {

	/**
	 * {@inheritDoc}
	 */
	public abstract ListIterator<G> list_iterator ();

	/**
	 * {@inheritDoc}
	 */
	public abstract new G? get (int index);

	/**
	 * {@inheritDoc}
	 */
	public abstract new void set (int index, G item);

	/**
	 * {@inheritDoc}
	 */
	public abstract int index_of (G item);

	/**
	 * {@inheritDoc}
	 */
	public abstract void insert (int index, G item);

	/**
	 * {@inheritDoc}
	 */
	public abstract G remove_at (int index);

	/**
	 * {@inheritDoc}
	 */
	public abstract List<G>? slice (int start, int stop);

	/**
	 * {@inheritDoc}
	 */
	public virtual G first () {
		return get (0);
	}

	/**
	 * {@inheritDoc}
	 */
	public virtual G last () {
		return get (size - 1);
	}

	/**
	 * {@inheritDoc}
	 */
	public virtual void insert_all (int index, Collection<G> collection) {
		foreach (G item in collection) {
			insert(index, item);
			index++;
		}
	}

	/**
	 * {@inheritDoc}
	 */
	public void sort (CompareFunc? compare = null) {
		if (compare == null) {
			compare = Functions.get_compare_func_for (typeof (G));
		}
		TimSort.sort<G> (this, compare);
	}

	private weak List<G> _read_only_view;

	/**
	 * {@inheritDoc}
	 */
	public virtual new List<G> read_only_view {
		owned get {
			List<G> instance = _read_only_view;
			if (_read_only_view == null) {
				instance = new ReadOnlyList<G> (this);
				_read_only_view = instance;
				instance.add_weak_pointer ((void**) (&_read_only_view));
			}
			return instance;
		}
	}
}