\CodePro Analytix Evaluation\src\com\instantiations\example\stack\SimpleStack.java
Violations: 0 high, 18 medium, 3 low
 
Violations
Missing file comment Missing Javadoc comment for method "isEmpty" Constant on right side of comparison
Missing @version tag for type SimpleStack Constant on right side of comparison Missing Javadoc comment for method "grow"
toString() is missing Missing Javadoc comment for method "push" Local variable not initialized: elementCount
Missing default constructor Nested assignment Local variable should be final: elementCount
Missing Javadoc comment for field Missing Javadoc comment for method "peek" Local variable not initialized: newElements
Missing Javadoc comment for field Constant on right side of comparison Local variable should be final: newElements
Missing Javadoc comment for method "SimpleStack" Missing Javadoc comment for method "pop" Invalid numeric literal: 10
 
Source
1 package com.instantiations.example.stack;
2
3 import java.util.EmptyStackException;
4
5 /**
6  * The class <code>SimpleStack</code> is a simple implementation of a stack
7  * that does not contain any design-by-contract (DBC) information. Other than
8  * the absence of the DBC tags, this class is identical to the class
9  * {@link DBCStack} so that the results of generating test classes can be
10  * compared.
11  * 
12  * @author Donna Devon
13  */
14 public class SimpleStack
15 {
16    private Object[] elements;
17
18    private int top;
19
20    public SimpleStack(int initialCapacity)
21    {
22       elements = new Object[initialCapacity];
23    }
24
25    public boolean isEmpty()
26    {
27       return top == 0;
28    }
29
30    public void push(Object object)
31    {
32       if (top == elements.length) {
33          grow();
34       }
35       elements[top++] = object;
36    }
37
38    public Object peek()
39    {
40       if (top == 0) {
41          throw new EmptyStackException();
42       }
43       return elements[top - 1];
44    }
45
46    public Object pop()
47    {
48       if (top == 0) {
49          throw new EmptyStackException();
50       }
51       return elements[--top];
52    }
53
54    private void grow()
55    {
56       int elementCount;
57       Object[] newElements;
58
59       elementCount = elements.length;
60       newElements = new Object[elementCount + 10];
61       System.arraycopy(elements, 0, newElements, 0, elementCount);
62       elements = newElements;
63    }
64 }
Powered by CodePro AnalytiX