org.jmlspecs.samples.stacks
Class BoundedStack
java.lang.Object
org.jmlspecs.samples.stacks.BoundedStack
- All Implemented Interfaces:
- BoundedStackInterface, BoundedThing
- public class BoundedStack
- 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 represents MAX_SIZE <- this.maxSize;
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]); |
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); |
theItems
protected Object[] theItems
- Specifications:
is in groups: theStack
maps theItems[*] \into theStack
nextFree
protected int nextFree
- Specifications:
is in groups: theStack
maxSize
protected int maxSize
- Specifications:
is in groups: MAX_SIZE
BoundedStack
public BoundedStack()
- Specifications:
-
public normal_behavior
assignable MAX_SIZE, size, theStack;
ensures this.theStack.equals(new org.jmlspecs.models.JMLObjectSequence());
ensures_redundantly this.theStack.isEmpty()&&this.size == 0;
BoundedStack
public BoundedStack(int maxSize)
- Specifications:
-
public normal_behavior
assignable MAX_SIZE, size, theStack;
ensures this.theStack.equals(new org.jmlspecs.models.JMLObjectSequence());
ensures_redundantly this.theStack.isEmpty()&&this.size == 0&&this.MAX_SIZE == maxSize;
theStackRep
protected JMLObjectSequence theStackRep()
- Specifications: pure
clone
public Object clone()
- Specified by:
clone
in interface BoundedThing
- Overrides:
clone
in class Object
- 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
- 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
- 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
- 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 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 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
- 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 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.