Use non-nullable capacities and a constant to specify unbounded
authorDidier 'Ptitjes <ptitjes@free.fr>
Mon, 14 Sep 2009 16:34:09 +0000 (18:34 +0200)
committerDidier 'Ptitjes <ptitjes@free.fr>
Mon, 14 Sep 2009 16:34:09 +0000 (18:34 +0200)
gee/linkedlist.vala
gee/queue.vala
tests/testqueue.vala

index 7b4775f..802a278 100644 (file)
@@ -246,15 +246,15 @@ public class Gee.LinkedList<G> : AbstractList<G>, Queue<G>, Deque<G> {
        /**
         * @inheritDoc
         */
-       public int? capacity {
-               get { return null; }
+       public int capacity {
+               get { return UNBOUNDED_CAPACITY; }
        }
 
        /**
         * @inheritDoc
         */
-       public int? remaining_capacity {
-               get { return null; }
+       public int remaining_capacity {
+               get { return UNBOUNDED_CAPACITY; }
        }
 
        /**
index 321479b..cc67e56 100644 (file)
@@ -26,7 +26,7 @@
  * Although all Queue implementations do not limit the amount of elements they
  * can contain, this interface supports for capacity-bounded queues. When
  * capacity is not bound, then the {@link capacity} and
- * {@link remaining_capacity} both return null.
+ * {@link remaining_capacity} both return {@link UNBOUNDED_CAPACITY}.
  *
  * This interface defines methods that will never fail whatever the state of
  * the queue is. For capacity-bounded queues, those methods will either return
  * poll method to indicate that the queue contains no elements.
  */
 public interface Gee.Queue<G> : Collection<G> {
+
+       /**
+        * The unbounded capacity value.
+        */
+       public static const int UNBOUNDED_CAPACITY = -1;
+
        /**
         * The capacity of this queue (or null if capacity is not bound).
         */
-       public abstract int? capacity { get; }
+       public abstract int capacity { get; }
 
        /**
         * The remaining capacity of this queue (or null if capacity is not bound).
         */
-       public abstract int? remaining_capacity { get; }
+       public abstract int remaining_capacity { get; }
 
        /**
         * Specifies whether this queue is full.
index e872084..86833ae 100644 (file)
@@ -36,9 +36,9 @@ public abstract class QueueTests : CollectionTests {
                // Check the test queue is not null
                assert (test_queue != null);
 
-               if (test_queue.capacity == null) {
+               if (test_queue.capacity == Gee.Queue.UNBOUNDED_CAPACITY) {
                        // Unbounded capacity
-                       assert (test_queue.remaining_capacity == null);
+                       assert (test_queue.remaining_capacity == Gee.Queue.UNBOUNDED_CAPACITY);
                        assert (! test_queue.is_full);
                } else {
                        // Bounded capacity