-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
k_list_mutable.dart
116 lines (97 loc) · 3.18 KB
/
k_list_mutable.dart
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
import 'package:dart_kollection/dart_kollection.dart';
/**
* A generic ordered collection of elements that supports adding and removing elements.
* @param E the type of elements contained in the list. The mutable list is invariant on its element type.
*/
abstract class KMutableList<T>
implements KList<T>, KMutableCollection<T>, KMutableListExtension<T> {
// Modification Operations
/**
* Adds the specified element to the end of this list.
*
* @return `true` because the list is always modified as the result of this operation.
*/
@override
bool add(T element);
@override
bool remove(T element);
// Bulk Modification Operations
/**
* Adds all of the elements of the specified collection to the end of this list.
*
* The elements are appended in the order they appear in the [elements] collection.
*
* @return `true` if the list was changed as the result of the operation.
*/
@override
bool addAll(KIterable<T> elements);
/**
* Inserts all of the elements in the specified collection [elements] into this list at the specified [index].
*
* @return `true` if the list was changed as the result of the operation.
*/
bool addAllAt(int index, KCollection<T> elements);
@override
bool removeAll(KIterable<T> elements);
@override
bool retainAll(KIterable<T> elements);
@override
void clear();
// Positional Access Operations
/**
* Replaces the element at the specified position in this list with the specified element.
*
* @return the element previously at the specified position.
*/
@nullable
T set(int index, T element);
/**
* Replaces the element at the specified position in this list with the specified element.
*/
void operator []=(int index, T element);
/**
* Inserts an element into the list at the specified [index].
*/
void addAt(int index, T element);
/**
* Removes an element at the specified [index] from the list.
*
* @return the element that has been removed.
*/
@nullable
T removeAt(int index);
@override
KMutableListIterator<T> listIterator([int index = 0]);
@override
KMutableList<T> subList(int fromIndex, int toIndex);
}
abstract class KMutableListExtension<T> {
/**
* Fills the list with the provided [value].
*
* Each element in the list gets replaced with the [value].
*/
void fill(T value);
/**
* Reverses elements in the list in-place.
*/
void reverse();
/**
* Sorts elements in the list in-place according to natural sort order of the value returned by specified [selector] function.
*/
void sortBy<R extends Comparable<R>>(R Function(T) selector);
/**
* Sorts elements in the list in-place descending according to natural sort order of the value returned by specified [selector] function.
*/
void sortByDescending<R extends Comparable<R>>(R Function(T) selector);
/**
* Sorts elements in the list in-place according to the specified [comparator]
*/
void sortWith(Comparator<T> comparator);
/**
* Swaps the elements at the specified positions in the specified list.
* (If the specified positions are equal, invoking this method leaves
* the list unchanged.)
*/
void swap(int indexA, int indexB);
}