Clover coverage report - baseCode - 0.2.5 Coverage timestamp: Tue Apr 12 2005 11:31:58 EDT FRAMES NO FRAMES |
file stats: | LOC: | 90 |  | Methods: | 8
| NCLOC: | 50 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
Queue.java | 83.3% | 95.7% | 100% | 94.6% |

1 |  |
     package baseCode.dataStructure;
2 |  |
3 |  |
     /**
4 |  |
      * Simple Queue implementation.
5 |  |
      * <p>
6 |  |
      * Copyright (c) 2004
7 |  |
      * </p>
8 |  |
      * <p>
9 |  |
      * Institution: Columbia University
10 |  |
      * </p>
11 |  |
      *
12 |  |
      * @author Paul Pavlidis
13 |  |
      * @version $Id: Queue.java,v 1.4 2004/07/29 08:38:49 pavlidis Exp $
14 |  |
      * @deprecated -- use java.util.List instead.
15 |  |
      */
16 |  |
     public class Queue {
17 |  |
18 |  |
        private Object[] queue;
19 |  |
        private int front;
20 |  |
        private int back;
21 |  |
        private int currentSize;
22 |  |
23 |  |
        private final static int DEFAULTCAPACITY = 10000;
24 |  |
25 | 8 |
        public Queue() {
26 | 8 |
           this( DEFAULTCAPACITY );
27 |  |
        }
28 |  |
29 | 12 |
        public Queue( int capacity ) {
30 | 12 |
           queue = new Object[capacity];
31 | 12 |
           makeEmpty();
32 |  |
        }
33 |  |
34 |  |
        /**
35 |  |
         * @param obj Object
36 |  |
         */
37 | 121 |
        public void enqueue( Object obj ) {
38 | 121 |
           if ( isFull() ) {
39 | 1 |
              throw new IndexOutOfBoundsException(
40 |  |
                    "Attempt to enqueue in a full queue" );
41 |  |
           }
42 | 120 |
           back = increment( back );
43 | 120 |
           queue[back] = obj;
44 | 120 |
           currentSize++;
45 |  |
        }
46 |  |
47 |  |
        /**
48 |  |
         * @return Object
49 |  |
         */
50 | 110 |
        public Object dequeue() {
51 | 110 |
           if ( isEmpty() ) {
52 | 2 |
              return null;
53 |  |
           }
54 | 108 |
           currentSize--;
55 | 108 |
           Object f = queue[front];
56 | 108 |
           queue[front] = null;
57 | 108 |
           front = increment( front );
58 | 108 |
           return f;
59 |  |
        }
60 |  |
61 |  |
        /**
62 |  |
         * @return boolean
63 |  |
         */
64 | 207 |
        public boolean isEmpty() {
65 | 207 |
           return currentSize == 0;
66 |  |
        }
67 |  |
68 |  |
        /**
69 |  |
         * @return boolean
70 |  |
         */
71 | 121 |
        public boolean isFull() {
72 | 121 |
           return queue.length == currentSize;
73 |  |
        }
74 |  |
75 |  |
        /**
76 |  |
         *
77 |  |
         */
78 | 12 |
        public void makeEmpty() {
79 | 12 |
           currentSize = 0;
80 | 12 |
           front = 0;
81 | 12 |
           back = -1;
82 |  |
        }
83 |  |
84 | 228 |
        private int increment( int i ) {
85 | 228 |
           if ( ++i == queue.length ) {
86 | 0 |
              i = 0;
87 |  |
           }
88 | 228 |
           return i;
89 |  |
        }
90 |  |
     }