Change ReadOnlyList to inherit from ReadOnlyCollection.
authorTomaž Vajngerl <quikee@gmail.com>
Mon, 3 Aug 2009 20:10:48 +0000 (22:10 +0200)
committerDidier 'Ptitjes <ptitjes@free.fr>
Sun, 6 Sep 2009 23:09:49 +0000 (01:09 +0200)
Fixes part of bug 590677.

gee/readonlylist.vala

index 23db056..7412bf8 100644 (file)
@@ -31,93 +31,27 @@ using GLib;
  *
  * @see Gee.List
  */
-public class Gee.ReadOnlyList<G> : Object, Iterable<G>, Collection<G>, List<G> {
+public class Gee.ReadOnlyList<G> : Gee.ReadOnlyCollection<G>, List<G> {
 
        /**
-        * @inheritDoc
-        */
-       public int size {
-               get { return _list.size; }
-       }
-
-       /**
-        * @inheritDoc
-        */
-       public bool is_empty {
-               get { return _list.is_empty; }
-       }
-
-       /**
-        * The decorated list.
-        */
-       public List<G> list {
-               construct { _list = value; }
-       }
-
-       private List<G> _list;
-
-       /**
-        * Constructs a read-only set that mirrors the content of the specified
+        * Constructs a read-only list that mirrors the content of the specified
         * list.
         *
         * @param list the list to decorate (may be null).
         */
        public ReadOnlyList (List<G>? list = null) {
-               this.list = list;
-       }
-
-       /**
-        * @inheritDoc
-        */
-       public Type element_type {
-               get { return typeof (G); }
-       }
-
-       /**
-        * @inheritDoc
-        */
-       public Gee.Iterator<G> iterator () {
-               if (_list == null) {
-                       return new Iterator<G> ();
-               }
-
-               return _list.iterator ();
-       }
-
-       /**
-        * @inheritDoc
-        */
-       public bool contains (G item) {
-               if (_list == null) {
-                       return false;
-               }
-
-               return _list.contains (item);
+               base (list);
        }
 
        /**
         * @inheritDoc
         */
        public int index_of (G item) {
-               if (_list == null) {
+               if (_collection == null) {
                        return -1;
                }
 
-               return _list.index_of (item);
-       }
-
-       /**
-        * Unimplemented method (read only list).
-        */
-       public bool add (G item) {
-               assert_not_reached ();
-       }
-
-       /**
-        * Unimplemented method (read only list).
-        */
-       public bool remove (G item) {
-               assert_not_reached ();
+               return ((Gee.List<G>) _collection).index_of (item);
        }
 
        /**
@@ -138,11 +72,11 @@ public class Gee.ReadOnlyList<G> : Object, Iterable<G>, Collection<G>, List<G> {
         * @inheritDoc
         */
        public new G? get (int index) {
-               if (_list == null) {
+               if (_collection == null) {
                        return null;
                }
 
-               return _list.get (index);
+               return ((Gee.List<G>) _collection).get (index);
        }
 
        /**
@@ -153,13 +87,6 @@ public class Gee.ReadOnlyList<G> : Object, Iterable<G>, Collection<G>, List<G> {
        }
 
        /**
-        * @inheritDoc
-        */
-       public void clear () {
-               assert_not_reached ();
-       }
-
-       /**
         * Unimplemented method (read only list).
         */
        public List<G>? slice (int start, int stop) {
@@ -167,56 +94,25 @@ public class Gee.ReadOnlyList<G> : Object, Iterable<G>, Collection<G>, List<G> {
        }
 
        /**
-        * Unimplemented method (read only list).
-        */
-       public bool add_all (Collection<G> collection) {
-               assert_not_reached ();
-       }
-
-       /**
-        * @inheritDoc
-        */
-       public bool contains_all (Collection<G> collection) {
-               if (_list == null) {
-                       return false;
-               }
-               return _list.contains_all (collection);
-       }
-
-       /**
-        * Unimplemented method (read only list).
-        */
-       public bool remove_all (Collection<G> collection) {
-               assert_not_reached ();
-       }
-
-       /**
-        * Unimplemented method (read only list).
-        */
-       public bool retain_all (Collection<G> collection) {
-               assert_not_reached ();
-       }
-
-       /**
         * @inheritDoc
         */
        public G? first () {
-               if (_list == null) {
+               if (_collection == null) {
                        return null;
                }
 
-               return _list.first ();
+               return ((Gee.List<G>) _collection).first ();
        }
 
        /**
         * @inheritDoc
         */
        public G? last () {
-               if (_list == null) {
+               if (_collection == null) {
                        return null;
                }
 
-               return _list.last ();
+               return ((Gee.List<G>) _collection).last ();
        }
 
        /**
@@ -225,22 +121,5 @@ public class Gee.ReadOnlyList<G> : Object, Iterable<G>, Collection<G>, List<G> {
        public void insert_all (int index, Collection<G> collection) {
                assert_not_reached ();
        }
-
-       /**
-        * @inheritDoc
-        */
-       public G[] to_array() {
-               return _list.to_array ();
-       }
-
-       class Iterator<G> : Object, Gee.Iterator<G> {
-               public bool next () {
-                       return false;
-               }
-
-               public new G? get () {
-                       return null;
-               }
-       }
 }