JML

java.util
Class HashSet

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended byjava.util.HashSet
All Implemented Interfaces:
Cloneable, Collection, Serializable, Set
Direct Known Subclasses:
JTypeDeclaration.PleomorphSet, LinkedHashSet

public class HashSet
extends AbstractSet
implements Set, Cloneable, Serializable

JML's specification of java.util.HashSet.

Author:
Katie Becker, Gary T. Leavens

Class Specifications
public invariant this.initialCapacity >= 0;
public invariant this.loadFactor > 0.0;
public represents addOperationSupported <- true;
public represents removeOperationSupported <- true;

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

Specifications inherited from interface Set
instance public represents theCollection <- this.theSet.toBag();

Specifications inherited from interface Collection
instance public invariant this.elementType == this.theCollection.elementType;
instance public invariant this.containsNull == this.theCollection.containsNull;
instance public invariant !this.nullElementsSupported ==> !this.containsNull;

Model Field Summary
 int initialCapacity
           
 float loadFactor
           
 
Model fields inherited from class java.lang.Object
_getClass, objectState, theString
 
Model fields inherited from interface java.util.Set
theSet
 
Model fields inherited from interface java.util.Collection
addOperationSupported, elementState, nullElementsSupported, removeOperationSupported, theCollection
 
Ghost Field Summary
 
Ghost fields inherited from class java.lang.Object
objectTimesFinalized, owner
 
Ghost fields inherited from interface java.util.Collection
containsNull, elementType
 
Field Summary
(package private) static long serialVersionUID
           
 
Constructor Summary
  HashSet()
           
  HashSet(int initialCapacity)
           
  HashSet(int initialCapacity, float loadFactor)
           
(package private) HashSet(int initialCapacity, float loadFactor, boolean dummy)
           
  HashSet(Collection c)
           
 
Model Method Summary
 
Model methods inherited from class java.lang.Object
hashValue
 
Model methods inherited from interface java.util.Collection
hashValue
 
Method Summary
 boolean add(nullable Object o)
           
 void clear()
           
 Object clone()
           
 boolean contains(nullable Object o)
           
 boolean isEmpty()
           
 Iterator iterator()
           
 boolean remove(nullable Object o)
           
 int size()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Model Field Detail

initialCapacity

public int initialCapacity

loadFactor

public float loadFactor
Field Detail

serialVersionUID

static final long serialVersionUID
Constructor Detail

HashSet

public HashSet()
Specifications:
public normal_behavior
assignable theSet, initialCapacity, loadFactor;
ensures this.theSet != null&&this.theSet.isEmpty();
ensures this.loadFactor == 0.75;
ensures this.initialCapacity == 16;

HashSet

public HashSet(Collection c)
Specifications:
public normal_behavior
requires c != null;
assignable theSet, initialCapacity, loadFactor;
ensures this.loadFactor == 0.75&&this.theSet.equals(org.jmlspecs.models.JMLEqualsSet.convertFrom(c));

HashSet

public HashSet(int initialCapacity,
               float loadFactor)
Specifications:
public normal_behavior
requires initialCapacity >= 0;
assignable theSet, this.initialCapacity, this.loadFactor;
ensures this.theSet != null&&this.theSet.isEmpty();
ensures this.initialCapacity == initialCapacity&&this.loadFactor == loadFactor;

HashSet

public HashSet(int initialCapacity)
Specifications:
public normal_behavior
assignable theSet, this.initialCapacity, this.loadFactor;
ensures this.theSet != null&&this.theSet.isEmpty();
ensures this.initialCapacity == initialCapacity&&this.loadFactor == 0.75;

HashSet

HashSet(int initialCapacity,
        float loadFactor,
        boolean dummy)
Method Detail

iterator

public Iterator iterator()
Specified by:
iterator in interface Set
Specifications: pure
Specifications inherited from overridden method in class AbstractCollection:
       pure
Specifications inherited from overridden method in interface Set:
       pure
Specifications inherited from overridden method in interface Collection:
       pure non_null
public normal_behavior
assignable \nothing;
ensures \result != null;
ensures \result .elementType == this.elementType;
ensures this.containsNull == \result .returnsNull;
     also
public normal_behavior
ensures ( \forall int i; 0 <= i&&i < this.size(); this.theCollection.has(\result .nthNextElement(i)));
ensures ( \forall java.lang.Object o; ; this.theCollection.has(o) ==> ( \exists int i; 0 <= i&&i < this.size(); o.equals(\result .nthNextElement(i))));
ensures this.size() > 0 ==> \result .hasNext((int)(this.size()-1));
ensures !\result .hasNext((int)(this.size()));
ensures_redundantly ( \forall int i; 0 <= i&&i < this.size(); this.contains(\result .nthNextElement(i)));
ensures_redundantly this.size() != 0 ==> \result .moreElements;

size

public int size()
Specified by:
size in interface Set
Specifications: pure
Specifications inherited from overridden method in class AbstractCollection:
       pure
Specifications inherited from overridden method in interface Set:
       pure
Specifications inherited from overridden method in interface Collection:
       pure
public normal_behavior
assignable \nothing;
ensures \result == this.theCollection.int_size();
ensures \result >= 0;

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Set
Overrides:
isEmpty in class AbstractCollection
Specifications: pure
Specifications inherited from overridden method in class AbstractCollection:
       pure
Specifications inherited from overridden method in interface Set:
       pure
Specifications inherited from overridden method in interface Collection:
       pure
public normal_behavior
assignable \nothing;
ensures \result <==> this.theCollection.isEmpty();
     also
public normal_behavior
ensures \result == (this.size() == 0);

contains

public boolean contains(nullable Object o)
Specified by:
contains in interface Set
Overrides:
contains in class AbstractCollection
Specifications: pure
Specifications inherited from overridden method in class AbstractCollection:
       pure
Specifications inherited from overridden method in interface Set:
       pure
Specifications inherited from overridden method contains(Object o) in interface Collection:
       pure
public behavior
assignable \nothing;
ensures !this.containsNull&&o == null ==> !\result ;
ensures (o == null)||\typeof(o) <: this.elementType||!\result ;
ensures \result <==> this.theCollection.has(o);
signals_only java.lang.ClassCastException, java.lang.NullPointerException;
signals (java.lang.ClassCastException) (* \typeof(o) is incompatible with the elementType of this collection *);
signals (java.lang.NullPointerException) o == null;

add

public boolean add(nullable Object o)
Specified by:
add in interface Set
Overrides:
add in class AbstractCollection
Specifications inherited from overridden method in class AbstractCollection:
      --- None ---
Specifications inherited from overridden method add(Object o) in interface Set:
     also
public behavior
assignable theCollection;
ensures \result <==> !\old(this.theSet.has(o));
ensures this.theSet.equals(\old(this.theSet.insert(o)));
Specifications inherited from overridden method add(Object o) in interface Collection:
public behavior
requires !this.containsNull ==> o != null;
requires (o == null)||\typeof(o) <: this.elementType;
assignable theCollection;
ensures \result ==> this.theCollection.equals(\old(this.theCollection.insert(o)));
ensures \result &&\old(this.size() < 2147483647) ==> this.size() == \old(this.size()+1);
ensures !\result ==> this.size() == \old(this.size());
ensures !\result ==> \not_modified(theCollection);
ensures this.contains(o);
ensures_redundantly !\result ==> \old(this.contains(o));
signals_only java.lang.UnsupportedOperationException, java.lang.NullPointerException, java.lang.ClassCastException, java.lang.IllegalArgumentException;
signals (java.lang.UnsupportedOperationException) (* this does not support add *);
signals (java.lang.NullPointerException) (* not allowed to add null *);
signals (java.lang.ClassCastException) (* class of specified element prevents it from being added to this *);
signals (java.lang.IllegalArgumentException) (* some aspect of this element prevents it from being added to this *);

remove

public boolean remove(nullable Object o)
Specified by:
remove in interface Set
Overrides:
remove in class AbstractCollection
Specifications inherited from overridden method in class AbstractCollection:
      --- None ---
Specifications inherited from overridden method remove(Object o) in interface Set:
    implies_that
public behavior
assignable theCollection;
assignable_redundantly theSet;
ensures !this.theSet.has(o);
ensures_redundantly !this.theCollection.has(o);
Specifications inherited from overridden method remove(Object o) in interface Collection:
public behavior
requires !this.containsNull ==> o != null;
requires (o == null)||\typeof(o) <: this.elementType;
assignable theCollection;
ensures \result ==> this.theCollection.equals(\old(this.theCollection.remove(o)));
ensures \result &&\old(this.size() <= 2147483647) ==> this.size() == \old(this.size()-1)&&this.size() < 2147483647&&this.size() >= 0;
ensures !\result ||\old(this.size() == 2147483647) ==> this.size() == \old(this.size());
signals_only java.lang.UnsupportedOperationException, java.lang.ClassCastException;
signals (java.lang.UnsupportedOperationException) (* this does not support remove *);
signals (java.lang.ClassCastException) (* the type of this element is not compatible with this *);

clear

public void clear()
Specified by:
clear in interface Set
Overrides:
clear in class AbstractCollection
Specifications inherited from overridden method in class AbstractCollection:
      --- None ---
Specifications inherited from overridden method in interface Set:
      --- None ---
Specifications inherited from overridden method in interface Collection:
public behavior
assignable theCollection;
ensures this.theCollection.isEmpty();
ensures_redundantly this.size() == 0;
signals_only java.lang.UnsupportedOperationException;
signals (java.lang.UnsupportedOperationException) (* clear is not supported by this *);

clone

public Object clone()
Overrides:
clone in class Object
Specifications:
     also
public normal_behavior
assignable \nothing;
ensures \result instanceof java.util.Set&&\fresh(\result )&&((java.util.Set)\result ).equals(this);
ensures_redundantly \result != this;
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]);

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.