public abstract void clear ();
+ public virtual G[] to_array() {
+ G[] array = new G[size];
+ int index = 0;
+ foreach (G element in this) {
+ array[index] = element;
+ }
+ return array;
+ }
+
//
// Inherited from Iterable<G>
//
return slice;
}
+ public override G[] to_array() {
+ G[] array = new G[_size];
+ Memory.copy(array, _items, sizeof(G) * _size);
+ return array;
+ }
+
private void shift (int start, int delta) {
assert (start >= 0);
assert (start <= _size);
* read-only collections.
*/
public abstract void clear ();
+
+ /**
+ * Returns an array containing all of items from this collection.
+ *
+ * @return an array containing all of items from this collection
+ */
+ public abstract G[] to_array();
}
assert_not_reached ();
}
+ public G[] to_array() {
+ return _collection.to_array ();
+ }
+
private class Iterator<G> : Object, Gee.Iterator<G> {
public bool next () {
return false;
assert_not_reached ();
}
+ public G[] to_array() {
+ return _list.to_array ();
+ }
+
class Iterator<G> : Object, Gee.Iterator<G> {
public bool next () {
return false;
assert_not_reached ();
}
+ public G[] to_array() {
+ return _set.to_array ();
+ }
+
private class Iterator<G> : Object, Gee.Iterator<G> {
public bool next () {
return false;
assert (!iterator.next());
}
+void test_arraylist_to_array () {
+ var arraylistOfString = new ArrayList<string> ();
+
+ // Check iterate list
+ arraylistOfString.add ("42");
+ arraylistOfString.add ("43");
+ arraylistOfString.add ("44");
+
+ string[] array = (string[]) arraylistOfString.to_array ();
+ assert (array[0] == "42");
+ assert (array[1] == "43");
+ assert (array[2] == "44");
+}
+
void main (string[] args) {
Test.init (ref args);
Test.add_func ("/Arraylist/Collection/contains", test_arraylist_contains);
Test.add_func ("/Arraylist/Collection/remove", test_arraylist_remove);
Test.add_func ("/Arraylist/Collection/size", test_arraylist_size);
+ Test.add_func ("/Arraylist/Collection/to_array", test_arraylist_to_array);
// Methods of Iterable interface
Test.add_func ("/Arraylist/Iterable/iterator", test_arraylist_iterator);