JML

org.jmlspecs.samples.stacks
Class BoundedStackImplementation

java.lang.Object
  extended byorg.jmlspecs.samples.stacks.BoundedStackImplementation
All Implemented Interfaces:
BoundedStackInterface, BoundedThing

public class BoundedStackImplementation
extends Object
implements BoundedStackInterface


Class Specifications
protected invariant 0 <= this.nextFree&&this.nextFree <= this.theItems.length;
protected invariant this.theItems != null;
protected invariant ( \forall int i; 0 <= i&&i < this.nextFree; this.theItems[i] != null);
private invariant this.theItems.length == org.jmlspecs.samples.stacks.BoundedStackImplementation.MAX_STACK_ITEMS;
protected represents theStack <- this.theStackRep();
protected represents_redundantly theStack \such_that this.theStack != null&&this.theStack.int_length() == this.nextFree&&( \forall int i; 0 <= i&&i < this.nextFree; this.theStack.itemAt(i) == this.theItems[i]);
private represents MAX_SIZE <- org.jmlspecs.samples.stacks.BoundedStackImplementation.MAX_STACK_ITEMS;

Specifications inherited from class Object
represents objectState <- org.jmlspecs.lang.JMLDataGroup.IT;
public represents _getClass <- \typeof(this);

Specifications inherited from interface BoundedStackInterface
instance public invariant this.theStack != null;
instance public invariant_redundantly this.theStack.int_length() <= this.MAX_SIZE;
instance public invariant ( \forall int i; 0 <= i&&i < this.theStack.int_length(); this.theStack.itemAt(i) != null);
instance public represents size <- this.theStack.int_length();
public initially this.theStack != null&&this.theStack.isEmpty();

Specifications inherited from interface BoundedThing
instance public invariant this.MAX_SIZE > 0;
instance public invariant 0 <= this.size&&this.size <= this.MAX_SIZE;
instance public constraint this.MAX_SIZE == \old(this.MAX_SIZE);

Model Field Summary
 
Model fields inherited from class java.lang.Object
_getClass, objectState, theString
 
Model fields inherited from interface org.jmlspecs.samples.stacks.BoundedStackInterface
theStack
 
Model fields inherited from interface org.jmlspecs.samples.stacks.BoundedThing
MAX_SIZE, size
 
Ghost Field Summary
 
Ghost fields inherited from class java.lang.Object
objectTimesFinalized, owner
 
Field Summary
private static int MAX_STACK_ITEMS
           
protected  int nextFree
           
protected  Object[] theItems
           
 
Constructor Summary
BoundedStackImplementation()
           
 
Model Method Summary
protected  JMLObjectSequence theStackRep()
           
 
Model methods inherited from class java.lang.Object
hashValue
 
Method Summary
 Object clone()
           
 int getSizeLimit()
           
 boolean isEmpty()
           
 boolean isFull()
           
 void pop()
           
protected  void printStack()
           
 void push(Object x)
           
 Object top()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

theItems

protected Object[] theItems
Specifications:
maps theItems[*] \into theStack

nextFree

protected int nextFree
Specifications:
is in groups: theStack

MAX_STACK_ITEMS

private static int MAX_STACK_ITEMS
Constructor Detail

BoundedStackImplementation

public BoundedStackImplementation()
Specifications:
protected normal_behavior
assignable size, theStack;
assignable_redundantly theItems, nextFree;
ensures this.nextFree == 0;
Model Method Detail

theStackRep

protected JMLObjectSequence theStackRep()
Specifications: pure
Method Detail

clone

public Object clone()
             throws CloneNotSupportedException
Specified by:
clone in interface BoundedThing
Overrides:
clone in class Object
Throws:
CloneNotSupportedException
Specifications:
     also
protected behavior
assignable \nothing;
ensures java.util.Arrays.equals(this.theItems,((org.jmlspecs.samples.stacks.BoundedStackImplementation)\result ).theItems)&&this.nextFree == ((org.jmlspecs.samples.stacks.BoundedStackImplementation)\result ).nextFree&&this != \result ;
ensures_redundantly \result != null;
Specifications inherited from overridden method in class Object:
       non_null
protected normal_behavior
requires this instanceof java.lang.Cloneable;
assignable \nothing;
ensures \result != null;
ensures \typeof(\result ) == \typeof(this);
ensures (* \result is a clone of this *);
     also
protected normal_behavior
requires this.getClass().isArray();
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((java.lang.Object[])\result ).length == ((java.lang.Object[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((java.lang.Object[])this).length; ((java.lang.Object[])\result )[i] == ((java.lang.Object[])this)[i]);
     also
requires this.getClass().isArray();
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures java.lang.reflect.Array.getLength(\result ) == java.lang.reflect.Array.getLength(this);
ensures ( \forall int i; 0 <= i&&i < java.lang.reflect.Array.getLength(this); ( \exists java.lang.Object result_i; result_i == java.lang.reflect.Array.get(\result ,i); (result_i == null&&java.lang.reflect.Array.get(this,i) == null)||(result_i != null&&result_i.equals(java.lang.reflect.Array.get(this,i)))));
     also
protected exceptional_behavior
requires !(this instanceof java.lang.Cloneable);
assignable \nothing;
signals_only java.lang.CloneNotSupportedException;
     also
protected normal_behavior
requires \elemtype(\typeof(this)) <: \type(java.lang.Object);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((java.lang.Object[])\result ).length == ((java.lang.Object[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((java.lang.Object[])this).length; ((java.lang.Object[])\result )[i] == ((java.lang.Object[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(int);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((int[])\result ).length == ((int[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((int[])this).length; ((int[])\result )[i] == ((int[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(byte);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((byte[])\result ).length == ((byte[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((byte[])this).length; ((byte[])\result )[i] == ((byte[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(char);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((char[])\result ).length == ((char[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((char[])this).length; ((char[])\result )[i] == ((char[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(long);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((long[])\result ).length == ((long[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((long[])this).length; ((long[])\result )[i] == ((long[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(short);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((short[])\result ).length == ((short[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((short[])this).length; ((short[])\result )[i] == ((short[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(boolean);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((boolean[])\result ).length == ((boolean[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((boolean[])this).length; ((boolean[])\result )[i] == ((boolean[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(float);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((float[])\result ).length == ((float[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((float[])this).length; (java.lang.Float.isNaN(((float[])\result )[i])&&java.lang.Float.isNaN(((float[])this)[i]))||((float[])\result )[i] == ((float[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(double);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((double[])\result ).length == ((double[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((double[])this).length; (java.lang.Double.isNaN(((double[])\result )[i])&&java.lang.Double.isNaN(((double[])this)[i]))||((double[])\result )[i] == ((double[])this)[i]);
Specifications inherited from overridden method in interface BoundedThing:
     also
public behavior
assignable \nothing;
ensures \result instanceof org.jmlspecs.samples.stacks.BoundedThing&&this.size == ((org.jmlspecs.samples.stacks.BoundedThing)\result ).size;
signals_only java.lang.CloneNotSupportedException;

getSizeLimit

public int getSizeLimit()
Specified by:
getSizeLimit in interface BoundedThing
Specifications: (inherited)pure
     also
protected normal_behavior
ensures \result == this.theItems.length;
    implies_that
private normal_behavior
ensures \result == org.jmlspecs.samples.stacks.BoundedStackImplementation.MAX_STACK_ITEMS;
Specifications inherited from overridden method in interface BoundedThing:
       pure
public normal_behavior
ensures \result == this.MAX_SIZE;

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface BoundedThing
Specifications: (inherited)pure
     also
protected normal_behavior
ensures \result == (this.nextFree == 0);
Specifications inherited from overridden method in interface BoundedThing:
       pure
public normal_behavior
ensures \result <==> this.size == 0;

isFull

public boolean isFull()
Specified by:
isFull in interface BoundedThing
Specifications: (inherited)pure
     also
protected normal_behavior
ensures \result == (this.nextFree == this.theItems.length);
Specifications inherited from overridden method in interface BoundedThing:
       pure
public normal_behavior
ensures \result <==> this.size == this.MAX_SIZE;

pop

public void pop()
         throws BoundedStackException
Specified by:
pop in interface BoundedStackInterface
Throws:
BoundedStackException
Specifications:
     also
protected normal_behavior
requires this.nextFree != 0;
assignable theStack;
assignable_redundantly nextFree;
ensures this.nextFree == \old(this.nextFree-1)&&\not_modified(theItems);
ensures_redundantly java.util.Arrays.equals(this.theItems,\old(this.theItems));
     also
protected exceptional_behavior
requires this.nextFree == 0;
assignable \nothing;
signals_only org.jmlspecs.samples.stacks.BoundedStackException;
Specifications inherited from overridden method in interface BoundedStackInterface:
public normal_behavior
requires !this.theStack.isEmpty();
assignable size, theStack;
ensures this.theStack.equals(\old(this.theStack.trailer()));
     also
public exceptional_behavior
requires this.theStack.isEmpty();
assignable \nothing;
signals_only org.jmlspecs.samples.stacks.BoundedStackException;
    implies_that
public behavior
requires !this.theStack.isEmpty();
assignable size, theStack;
ensures this.theStack.equals(\old(this.theStack.trailer()));
signals (java.lang.Exception) false;
     also
public behavior
requires this.theStack.isEmpty();
assignable \nothing;
ensures false;
signals_only org.jmlspecs.samples.stacks.BoundedStackException;
signals (java.lang.Exception) true;
     also
public behavior
requires !this.theStack.isEmpty()||this.theStack.isEmpty();
assignable size, theStack;
ensures \old(!this.theStack.isEmpty()) ==> this.theStack.equals(\old(this.theStack.trailer()));
ensures \old(this.theStack.isEmpty()) ==> \not_assigned(size)&&\not_assigned(theStack);
signals_only org.jmlspecs.samples.stacks.BoundedStackException;
signals (java.lang.Exception) \old(!this.theStack.isEmpty()) ==> false;
signals (java.lang.Exception) \old(this.theStack.isEmpty()) ==> \not_assigned(size)&&\not_assigned(theStack);

push

public void push(Object x)
          throws BoundedStackException
Specified by:
push in interface BoundedStackInterface
Throws:
BoundedStackException
Specifications:
     also
protected normal_behavior
requires this.nextFree < this.theItems.length&&x != null;
assignable theStack;
assignable_redundantly nextFree, theItems[this.nextFree];
ensures this.theItems[(int)(this.nextFree-1)] == x&&( \forall int i; 0 <= i&&i < \old(this.nextFree-1); this.theItems[i] == \old(this.theItems[i]))&&this.nextFree == \old(this.nextFree+1);
     also
protected exceptional_behavior
requires this.nextFree >= this.theItems.length||x == null;
assignable \nothing;
signals (org.jmlspecs.samples.stacks.BoundedStackException) this.nextFree >= this.theItems.length;
signals (java.lang.NullPointerException) x == null;
Specifications inherited from overridden method push(Object x) in interface BoundedStackInterface:
public normal_behavior
requires this.theStack.int_length() < this.MAX_SIZE&&x != null;
assignable size, theStack;
ensures this.theStack.equals(\old(this.theStack.insertFront(x)));
ensures_redundantly this.theStack != null&&this.top() == x&&this.theStack.int_length() == \old(this.theStack.int_length()+1);
     also
public exceptional_behavior
requires this.theStack.int_length() >= this.MAX_SIZE||x == null;
assignable \nothing;
signals_only org.jmlspecs.samples.stacks.BoundedStackException, java.lang.NullPointerException;
signals (org.jmlspecs.samples.stacks.BoundedStackException) this.theStack.int_length() == this.MAX_SIZE;
signals (java.lang.NullPointerException) x == null;

top

public Object top()
           throws BoundedStackException
Specified by:
top in interface BoundedStackInterface
Throws:
BoundedStackException
Specifications: (inherited)pure
     also
protected normal_behavior
requires this.nextFree != 0;
assignable \nothing;
ensures \result == this.theItems[(int)(this.nextFree-1)];
     also
protected exceptional_behavior
requires this.nextFree == 0;
assignable \nothing;
signals (org.jmlspecs.samples.stacks.BoundedStackException e) \fresh(e)&&e != null&&e.getMessage() != null&&e.getMessage().equals("empty stack");
Specifications inherited from overridden method in interface BoundedStackInterface:
       pure
public normal_behavior
requires !this.theStack.isEmpty();
ensures \result == this.theStack.first()&&\result != null;
     also
public exceptional_behavior
requires this.theStack.isEmpty();
signals_only org.jmlspecs.samples.stacks.BoundedStackException;
signals (org.jmlspecs.samples.stacks.BoundedStackException e) \fresh(e)&&e != null&&e.getMessage() != null&&e.getMessage().equals("empty stack");

toString

public String toString()
Overrides:
toString in class Object
Specifications:
     also
public normal_behavior
assignable \nothing;
ensures \result != null&&(* a string encoding of this is returned *);
Specifications inherited from overridden method in class Object:
       non_null
public normal_behavior
assignable objectState;
ensures \result != null&&\result .equals(this.theString);
ensures (* \result is a string representation of this object *);
     also
public code normal_behavior
assignable \nothing;
ensures \result != null&&(* \result is the instance's class name, followed by an @, followed by the instance's hashcode in hex *);
     also
public code model_program { ... }
    implies_that
assignable objectState;
ensures \result != null;

printStack

protected void printStack()
Specifications:
protected normal_behavior
assignable System.out;
ensures (* prints a version of stack to System.out *);

JML

JML is Copyright (C) 1998-2002 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This release depends on code from the MultiJava project and is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.