JML

org.jmlspecs.models
Class JMLEqualsBag

java.lang.Object
  extended byorg.jmlspecs.models.JMLEqualsBag
All Implemented Interfaces:
Cloneable, JMLCollection, JMLType, Serializable

public class JMLEqualsBag
extends Object
implements JMLCollection

Bags (i.e., multisets) of objects. This type uses ".equals" to compare elements, and does not clone elements that are passed into and returned from the bag's methods.

Version:
$Revision: 1.72 $
Author:
Gary T. Leavens, with help from Albert Baker, Clyde Ruby, and others.
See Also:
JMLCollection, JMLType, JMLObjectBag, JMLValueBag, JMLEqualsBagEnumerator, JMLObjectSet, JMLValueSet

Class Specifications
protected invariant this.the_list == null <==> this.size == 0;
public invariant this.size >= 0;
protected invariant this.the_list != null ==> ( \forall int i; 0 <= i&&i < this.the_list.int_size(); this.the_list.itemAt(i) instanceof org.jmlspecs.models.JMLEqualsBagEntry);
public invariant ( \forall java.lang.Object e1; ; this.count(e1) >= 0);
public invariant ( \forall org.jmlspecs.models.JMLEqualsBag s2; s2 != null; ( \forall java.lang.Object e1, e2; ; this.equational_theory(this,s2,e1,e2)));
public invariant this.elementType <: \type(java.lang.Object);
public invariant ( \forall java.lang.Object o; o != null&&this.has(o); \typeof(o) <: this.elementType);
public invariant_redundantly this.isEmpty() ==> !this.containsNull;
public invariant this.owner == null;

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

Specifications inherited from interface JMLCollection
instance public constraint this.elementType == \old(this.elementType);
instance public constraint this.containsNull == \old(this.containsNull);

Model Field Summary
 
Model fields inherited from class java.lang.Object
_getClass, objectState, theString
 
Model fields inherited from interface org.jmlspecs.models.JMLCollection
elementState
 
Ghost Field Summary
 
Ghost fields inherited from class java.lang.Object
objectTimesFinalized, owner
 
Ghost fields inherited from interface org.jmlspecs.models.JMLCollection
containsNull, elementType
 
Field Summary
static JMLEqualsBag EMPTY
          The empty JMLEqualsBag.
[spec_public] protected  int size
          The size of this bag.
protected  JMLEqualsBagEntryNode the_list
          The list representing the contents of this bag.
 
Constructor Summary
  JMLEqualsBag()
          Initialize this bag to be empty.
  JMLEqualsBag(Object elem)
          Initialize this bag to contain the given element.
protected JMLEqualsBag(JMLEqualsBagEntryNode ls, int sz)
          Initialize this bag with the given representation.
 
Model Method Summary
 boolean equational_theory(JMLEqualsBag s, JMLEqualsBag s2, Object e1, Object e2)
          An equational specification of the properties of bags.
 
Model methods inherited from class java.lang.Object
hashValue
 
Model methods inherited from interface org.jmlspecs.models.JMLCollection
size
 
Method Summary
 Object choose()
          Return an arbitrary element of this.
 Object clone()
          Return a clone of this object.
 boolean containsAll(non_null Collection c)
          Tell whether, for each element in the given collection, there is a ".equals" element in this bag.
static JMLEqualsBag convertFrom(non_null Object[] a)
          Return the bag containing all the elements in the given array.
static JMLEqualsBag convertFrom(non_null Collection c)
          Return the bag containing all the object in the given collection.
static JMLEqualsBag convertFrom(non_null JMLCollection c)
          Return the bag containing all the object in the given JMLCollection.
 int count(Object elem)
          Tell how many times the given element occurs ".equals" to an element in this bag.
 JMLEqualsBag difference(non_null JMLEqualsBag b2)
          Return a bag containing the items in this bag minus the items in the given bag.
 JMLEqualsBagEnumerator elements()
          Returns an Enumeration over this bag.
 boolean equals(nullable Object b2)
          Test whether this object's value is equal to the given argument.
protected  JMLEqualsBagEntry getMatchingEntry(Object item)
          Find a JMLEqualsBagEntry that is for the same element, if possible.
 boolean has(Object elem)
          Tell whether the given element occurs ".equals" to an element in this bag.
 int hashCode()
          Return a hash code for this object
 JMLEqualsBag insert(nullable Object elem)
          Return a bag containing the given item and the ones in this bag.
 JMLEqualsBag insert(nullable Object elem, int cnt)
          Return a bag containing the given item the given number of times, in addition to the ones in this bag.
 int int_size()
          Tell the number of elements in this bag.
 JMLEqualsBag intersection(non_null JMLEqualsBag b2)
          Return a bag containing the items in both this bag and the given bag.
 boolean isEmpty()
          Tell whether this bag has no elements.
 boolean isProperSubbag(non_null JMLEqualsBag b2)
          Tells whether every item in this bag is contained in the argument, but the argument is strictly larger.
 boolean isProperSuperbag(non_null JMLEqualsBag b2)
          Tells whether every item in the argument is contained in this bag argument, but this bag is strictly larger.
 boolean isSubbag(non_null JMLEqualsBag b2)
          Tells whether every item in this bag is contained in the argument.
 boolean isSuperbag(non_null JMLEqualsBag b2)
          Tells whether every item in the argument is contained in this bag.
 JMLIterator iterator()
          Returns an iterator over this bag.
 JMLEqualsBag remove(nullable Object elem)
          Return a bag containing the items in this bag except for one of the given element.
 JMLEqualsBag remove(nullable Object elem, int cnt)
          Return a bag containing the items in this bag, except for the given number of the given element.
 JMLEqualsBag removeAll(nullable Object elem)
          Return a bag containing the items in this bag, except for all items that are ".equals" to the given item.
static JMLEqualsBag singleton(Object e)
          Return the singleton bag containing the given element.
 Object[] toArray()
          Return a new array containing all the elements of this.
 JMLEqualsSequence toSequence()
          Return a new JMLEqualsSequence containing all the elements of this.
 JMLEqualsSet toSet()
          Return a new JMLEqualsSet containing all the elements of this.
 String toString()
          Return a string representation of this object.
 JMLEqualsBag union(non_null JMLEqualsBag b2)
          Return a bag containing the items in either this bag or the given bag.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

the_list

protected final JMLEqualsBagEntryNode the_list
The list representing the contents of this bag. Each element of this list is of type JMLEqualsBagEntry.

Specifications:
is in groups: objectState
maps the_list.elementState \into elementState

size

protected final int size
The size of this bag.

Specifications: spec_public
is in groups: objectState

EMPTY

public static final JMLEqualsBag EMPTY
The empty JMLEqualsBag.

See Also:
JMLEqualsBag()
Specifications: non_null
Constructor Detail

JMLEqualsBag

public JMLEqualsBag()
Initialize this bag to be empty.

See Also:
EMPTY
Specifications: (class)pure
public normal_behavior
assignable objectState, elementType, containsNull, owner;
ensures this.isEmpty();
ensures_redundantly (* this is an empty bag *);
    implies_that
ensures this.elementType <: \type(java.lang.Object)&&!this.containsNull;

JMLEqualsBag

public JMLEqualsBag(Object elem)
Initialize this bag to contain the given element.

Parameters:
elem - the element that is the sole contents of this bag.
See Also:
singleton(java.lang.Object)
Specifications: (class)pure
public normal_behavior
assignable objectState, elementType, containsNull, owner;
ensures this.count(elem) == 1&&this.int_size() == 1;
ensures_redundantly (* this is a singleton bag containing elem *);
    implies_that
ensures this.containsNull <==> elem == null;
ensures elem != null ==> this.elementType == \typeof(elem);
ensures elem == null ==> this.elementType <: \type(java.lang.Object);

JMLEqualsBag

protected JMLEqualsBag(JMLEqualsBagEntryNode ls,
                       int sz)
Initialize this bag with the given representation.

Specifications: (class)pure
requires ls == null <==> sz == 0;
requires sz >= 0;
assignable objectState, elementType, containsNull, owner;
ensures this.elementType == (ls == null ? \type(java.lang.Object) : ls.entryElementType);
ensures this.containsNull == (ls == null ? false : ls.containsNullElements);
Model Method Detail

equational_theory

public boolean equational_theory(JMLEqualsBag s,
                                 JMLEqualsBag s2,
                                 Object e1,
                                 Object e2)
An equational specification of the properties of bags.

Specifications: pure
public normal_behavior
{|
ensures \result <==> (new org.jmlspecs.models.JMLEqualsBag()).count(e1) == 0;
also
requires e1 != null;
ensures \result <==> s.insert(e1).count(e2) == (e1.equals(e2) ? (s.count(e2)+1) : s.count(e2));
also
ensures \result <==> s.insert(null).count(e2) == (e2 == null ? (s.count(e2)+1) : s.count(e2));
also
ensures \result <==> (new org.jmlspecs.models.JMLEqualsBag()).int_size() == 0;
also
ensures \result <==> s.insert(e1).int_size() == (s.int_size()+1);
also
ensures \result <==> s.isSubbag(s2) == ( \forall java.lang.Object o; ; s.count(o) <= s2.count(o));
also
ensures \result <==> s.equals(s2) == (s.isSubbag(s2)&&s2.isSubbag(s));
also
ensures \result <==> (new org.jmlspecs.models.JMLEqualsBag()).remove(e1).equals(new org.jmlspecs.models.JMLEqualsBag());
also
ensures \result <==> s.insert(null).remove(e2).equals(e2 == null ? s : s.remove(e2).insert(null));
also
requires e1 != null;
ensures \result <==> s.insert(e1).remove(e2).equals(e1.equals(e2) ? s : s.remove(e2).insert(e1));
also
ensures \result <==> s.isEmpty() == (s.int_size() == 0);
also
ensures \result <==> (new org.jmlspecs.models.JMLEqualsBag()).has(e1);
also
ensures \result <==> (new org.jmlspecs.models.JMLEqualsBag(e1)).equals(new org.jmlspecs.models.JMLEqualsBag().insert(e1));
also
ensures \result <==> s.isProperSubbag(s2) == (s.isSubbag(s2)&&!s.equals(s2));
also
ensures \result <==> s.isSuperbag(s2) == s2.isSubbag(s);
also
ensures \result <==> s.isProperSuperbag(s2) == s2.isProperSubbag(s);
|}
    implies_that
ensures \result <==> (new org.jmlspecs.models.JMLEqualsBag()).isEmpty();
ensures \result <==> !s.insert(e1).isEmpty();
ensures \result <==> (new org.jmlspecs.models.JMLEqualsBag(null)).has(e2) == (e2 == null);
ensures \result <==> (e1 != null ==> new org.jmlspecs.models.JMLEqualsBag(e1).has(e2) == (e1.equals(e2)));
Method Detail

singleton

public static JMLEqualsBag singleton(Object e)
Return the singleton bag containing the given element.

See Also:
JMLEqualsBag(Object)
Specifications: pure non_null
public normal_behavior
ensures \result != null&&\result .equals(new org.jmlspecs.models.JMLEqualsBag(e));

convertFrom

public static JMLEqualsBag convertFrom(non_null Object[] a)
Return the bag containing all the elements in the given array.

Specifications: pure non_null
public normal_behavior
requires a != null;
ensures \result != null&&\result .int_size() == a.length&&(* \result contains each element in a *);
ensures_redundantly \result != null&&\result .int_size() == a.length&&( \forall int i; 0 <= i&&i < a.length; \result .has(a[i]));

convertFrom

public static JMLEqualsBag convertFrom(non_null Collection c)
                                throws ClassCastException
Return the bag containing all the object in the given collection.

Throws:
ClassCastException - if some element in c is not an instance of Object.
See Also:
containsAll(java.util.Collection)
Specifications: pure non_null
public normal_behavior
requires c != null&&(c.elementType <: \type(java.lang.Object));
ensures \result != null&&\result .int_size() == c.size()&&(* \result contains each element in c *);
ensures_redundantly \result != null&&\result .int_size() == c.size()&&( \forall java.lang.Object x; ; c.contains(x) <==> \result .has(x));
     also
public exceptional_behavior
requires c != null&&( \exists java.lang.Object o; c.contains(o); !(o instanceof java.lang.Object));
signals_only java.lang.ClassCastException;

convertFrom

public static JMLEqualsBag convertFrom(non_null JMLCollection c)
                                throws ClassCastException
Return the bag containing all the object in the given JMLCollection.

Throws:
ClassCastException - if some element in c is not an instance of Object.
Specifications: pure non_null
public normal_behavior
requires c != null&&(c.elementType <: \type(java.lang.Object));
ensures \result != null&&( \forall java.lang.Object x; ; c.has(x) <==> \result .has(x));
ensures_redundantly \result .int_size() == c.int_size();
     also
public exceptional_behavior
requires c != null&&( \exists java.lang.Object o; c.has(o); !(o instanceof java.lang.Object));
signals_only java.lang.ClassCastException;

count

public int count(Object elem)
Tell how many times the given element occurs ".equals" to an element in this bag.

Parameters:
elem - the element sought.
Returns:
the number of times elem occurs in this bag.
See Also:
has(Object)
Specifications: (class)pure
public normal_behavior
ensures \result >= 0&&(* \result is the number of times elem occurs in this *);
    implies_that
ensures \result >= 0;

has

public boolean has(Object elem)
Tell whether the given element occurs ".equals" to an element in this bag.

Specified by:
has in interface JMLCollection
Parameters:
elem - the element sought.
See Also:
count(Object)
Specifications: (class)pure
     also
public normal_behavior
ensures \result <==> (this.count(elem) > 0);
Specifications inherited from overridden method has(Object elem) in interface JMLCollection:
       pure
public normal_behavior
ensures (* \result <==> elem is equal to one of the elements in the collection. *);
ensures_redundantly !this.containsNull&&elem == null ==> !\result ;
ensures_redundantly elem != null&&!(\typeof(elem) <: this.elementType) ==> !\result ;

containsAll

public boolean containsAll(non_null Collection c)
Tell whether, for each element in the given collection, there is a ".equals" element in this bag.

Parameters:
c - the collection whose elements are sought.
See Also:
#isSuperbag(JMLEqualsSet), convertFrom(java.util.Collection)
Specifications: (class)pure
public normal_behavior
requires c != null;
ensures \result <==> ( \forall java.lang.Object o; c.contains(o); this.has(o));

equals

public boolean equals(nullable Object b2)
Test whether this object's value is equal to the given argument. This comparison uses ".equals" to compare elements.

Note that the elementTypes may be different for otherwise equal bags.

Specified by:
equals in interface JMLType
Overrides:
equals in class Object
Specifications: (class)pure
     also
public normal_behavior
ensures \result <==> b2 != null&&b2 instanceof org.jmlspecs.models.JMLEqualsBag&&( \forall java.lang.Object e; ; this.count(e) == ((org.jmlspecs.models.JMLEqualsBag)b2).count(e));
    implies_that
public normal_behavior
requires b2 != null&&b2 instanceof org.jmlspecs.models.JMLEqualsBag;
ensures \result ==> this.int_size() == ((org.jmlspecs.models.JMLEqualsBag)b2).int_size()&&this.containsNull == ((org.jmlspecs.models.JMLEqualsBag)b2).containsNull;
Specifications inherited from overridden method equals(Object obj) in class Object:
       pure
public normal_behavior
requires obj != null;
ensures (* \result is true when obj is "equal to" this object *);
     also
public normal_behavior
requires this == obj;
ensures \result ;
     also
public code normal_behavior
requires obj != null;
ensures \result <==> this == obj;
     also
diverges false;
ensures obj == null ==> !\result ;
Specifications inherited from overridden method equals(Object ob2) in interface JMLType:
       pure
     also
public normal_behavior
ensures \result ==> ob2 != null&&(* ob2 is not distinguishable from this, except by using mutation or == *);
    implies_that
public normal_behavior
{|
requires ob2 != null&&ob2 instanceof org.jmlspecs.models.JMLType;
ensures ((org.jmlspecs.models.JMLType)ob2).equals(this) == \result ;
also
requires ob2 == this;
ensures \result <==> true;
|}

hashCode

public int hashCode()
Return a hash code for this object

Specified by:
hashCode in interface JMLType
Overrides:
hashCode in class Object
Specifications: pure
Specifications inherited from overridden method in class Object:
public behavior
assignable objectState;
ensures (* \result is a hash code for this object *);
     also
public code normal_behavior
assignable \nothing;
Specifications inherited from overridden method in interface JMLType:
       pure

isEmpty

public boolean isEmpty()
Tell whether this bag has no elements.

See Also:
int_size(), has(Object)
Specifications: (class)pure
public normal_behavior
ensures \result == ( \forall java.lang.Object e; ; this.count(e) == 0);

int_size

public int int_size()
Tell the number of elements in this bag.

Specified by:
int_size in interface JMLCollection
Specifications: (class)pure
     also
public normal_behavior
ensures \result >= 0&&(* \result is the size of this bag *);
Specifications inherited from overridden method in interface JMLCollection:
       pure
public normal_behavior
requires this.size() <= 2147483647;
ensures \result == this.size();

isSubbag

public boolean isSubbag(non_null JMLEqualsBag b2)
Tells whether every item in this bag is contained in the argument.

See Also:
isProperSubbag(JMLEqualsBag), isSuperbag(JMLEqualsBag)
Specifications: (class)pure
public normal_behavior
requires b2 != null;
ensures \result <==> ( \forall java.lang.Object e; ; this.count(e) <= b2.count(e));

isProperSubbag

public boolean isProperSubbag(non_null JMLEqualsBag b2)
Tells whether every item in this bag is contained in the argument, but the argument is strictly larger.

See Also:
isSubbag(JMLEqualsBag), isProperSuperbag(JMLEqualsBag)
Specifications: (class)pure
public normal_behavior
requires b2 != null;
ensures \result <==> this.isSubbag(b2)&&!this.equals(b2);

isSuperbag

public boolean isSuperbag(non_null JMLEqualsBag b2)
Tells whether every item in the argument is contained in this bag.

See Also:
isProperSuperbag(JMLEqualsBag), isSubbag(JMLEqualsBag), containsAll(java.util.Collection)
Specifications: (class)pure
public normal_behavior
requires b2 != null;
ensures \result == b2.isSubbag(this);

isProperSuperbag

public boolean isProperSuperbag(non_null JMLEqualsBag b2)
Tells whether every item in the argument is contained in this bag argument, but this bag is strictly larger.

See Also:
isSuperbag(JMLEqualsBag), isProperSubbag(JMLEqualsBag)
Specifications: (class)pure
public normal_behavior
requires b2 != null;
ensures \result == b2.isProperSubbag(this);

choose

public Object choose()
              throws JMLNoSuchElementException
Return an arbitrary element of this.

Throws:
JMLNoSuchElementException - if this is empty.
See Also:
isEmpty(), elements()
Specifications: (class)pure
public normal_behavior
requires !this.isEmpty();
ensures ( \exists java.lang.Object e; this.has(e); \result .equals(e));
     also
public exceptional_behavior
requires this.isEmpty();
signals_only org.jmlspecs.models.JMLNoSuchElementException;
    implies_that
ensures \result != null ==> \typeof(\result ) <: this.elementType;
ensures !this.containsNull ==> \result != null;
signals_only org.jmlspecs.models.JMLNoSuchElementException;
signals (org.jmlspecs.models.JMLNoSuchElementException) this.size == 0;

clone

public Object clone()
Return a clone of this object. This method does not clone the elements of the bag.

Specified by:
clone in interface JMLType
Overrides:
clone in class Object
Specifications: non_null (class)pure
     also
public normal_behavior
ensures \result instanceof org.jmlspecs.models.JMLEqualsBag&&this.equals(\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 JMLType:
       pure
     also
public normal_behavior
ensures \result != null;
ensures \result instanceof org.jmlspecs.models.JMLType;
ensures ((org.jmlspecs.models.JMLType)\result ).equals(this);
    implies_that
ensures \result != null&&\typeof(\result ) <: \type(org.jmlspecs.models.JMLType);

getMatchingEntry

protected JMLEqualsBagEntry getMatchingEntry(Object item)
Find a JMLEqualsBagEntry that is for the same element, if possible.

Parameters:
item - the item sought.
Returns:
null if the item is not in the bag.
Specifications: (class)pure
assignable \nothing;
ensures this.the_list == null ==> \result == null;
ensures_redundantly \result != null ==> this.the_list != null;
ensures \result != null ==> 0 <= \result .count&&\result .count <= this.size;

insert

public JMLEqualsBag insert(nullable Object elem)
                    throws IllegalStateException
Return a bag containing the given item and the ones in this bag.

Throws:
IllegalStateException
See Also:
insert(Object, int), has(Object), remove(Object)
Specifications: non_null (class)pure
public normal_behavior
requires this.size < 2147483647;
{|
requires elem != null;
ensures \result != null&&( \forall java.lang.Object e; ; ((e.equals(elem)) ==> \result .count(e) == this.count(e)+1)&&(!(e.equals(elem)) ==> \result .count(e) == this.count(e)));
also
requires elem == null;
ensures \result != null&&( \forall java.lang.Object e; ; (e == null ==> \result .count(e) == this.count(e)+1)&&(e != null ==> \result .count(e) == this.count(e)));
|}
     also
public model_program { ... }

insert

public JMLEqualsBag insert(nullable Object elem,
                           int cnt)
                    throws IllegalArgumentException,
                           IllegalStateException
Return a bag containing the given item the given number of times, in addition to the ones in this bag.

Throws:
IllegalArgumentException
IllegalStateException
See Also:
insert(Object), has(Object), remove(Object, int)
Specifications: non_null (class)pure
public normal_behavior
requires cnt > 0;
requires this.size <= 2147483647-cnt;
{|
requires elem != null;
ensures \result != null&&( \forall java.lang.Object e; ; ((e != null&&e.equals(elem)) ==> \result .count(e) == this.count(e)+cnt)&&(e == null||!(e.equals(elem)) ==> \result .count(e) == this.count(e)));
also
requires elem == null;
ensures \result != null&&( \forall java.lang.Object e; ; (e == null ==> \result .count(e) == this.count(e)+cnt)&&(e != null ==> \result .count(e) == this.count(e)));
|}
     also
public normal_behavior
requires cnt == 0;
ensures \result != null&&\result .equals(this);
     also
signals (java.lang.IllegalArgumentException) cnt < 0;

remove

public JMLEqualsBag remove(nullable Object elem)
Return a bag containing the items in this bag except for one of the given element.

See Also:
remove(Object, int), insert(Object)
Specifications: non_null (class)pure
public normal_behavior
{|
requires elem != null;
ensures \result != null&&( \forall java.lang.Object e; ; ((e.equals(elem)&&this.has(e)) ==> \result .count(e) == this.count(e)-1)&&(!(e.equals(elem)) ==> \result .count(e) == this.count(e)));
also
requires elem == null;
ensures \result != null&&( \forall java.lang.Object e; ; (e == null ==> \result .count(e) == this.count(e)-1)&&(e != null ==> \result .count(e) == this.count(e)));
|}

remove

public JMLEqualsBag remove(nullable Object elem,
                           int cnt)
                    throws IllegalArgumentException
Return a bag containing the items in this bag, except for the given number of the given element.

Throws:
IllegalArgumentException
See Also:
remove(Object), insert(Object, int)
Specifications: non_null (class)pure
public normal_behavior
requires cnt > 0;
{|
requires elem != null;
ensures \result != null&&( \forall java.lang.Object e; ; ((e.equals(elem)&&this.has(e)) ==> \result .count(e) == org.jmlspecs.models.JMLMath.max(0,this.count(e)-cnt))&&(!(e.equals(elem)) ==> \result .count(e) == this.count(e)));
also
requires elem == null;
ensures \result != null&&( \forall java.lang.Object e; ; (e == null ==> \result .count(e) == org.jmlspecs.models.JMLMath.max(0,this.count(e)-cnt))&&(e != null ==> \result .count(e) == this.count(e)));
|}
     also
public normal_behavior
requires cnt == 0;
ensures \result != null&&\result .equals(this);
    implies_that
requires 0 <= cnt;

removeAll

public JMLEqualsBag removeAll(nullable Object elem)
Return a bag containing the items in this bag, except for all items that are ".equals" to the given item.

See Also:
remove(Object), remove(Object, int)
Specifications: non_null (class)pure
public normal_behavior
requires elem != null;
ensures \result != null&&( \forall java.lang.Object e; ; ((e.equals(elem)&&this.has(e)) ==> \result .count(e) == 0)&&(!(e.equals(elem)) ==> \result .count(e) == this.count(e)));
     also
public normal_behavior
requires elem == null;
ensures \result != null&&( \forall java.lang.Object e; ; (e == null ==> \result .count(e) == 0)&&(e != null ==> \result .count(e) == this.count(e)));

intersection

public JMLEqualsBag intersection(non_null JMLEqualsBag b2)
Return a bag containing the items in both this bag and the given bag. Note that items occur the minimum number of times they occur in both bags.

See Also:
union(JMLEqualsBag), difference(JMLEqualsBag)
Specifications: non_null (class)pure
public normal_behavior
requires b2 != null;
ensures \result != null&&( \forall java.lang.Object e; ; \result .count(e) == java.lang.Math.min(this.count(e),b2.count(e)));

union

public JMLEqualsBag union(non_null JMLEqualsBag b2)
Return a bag containing the items in either this bag or the given bag. Note that items occur the sum of times they occur in both bags.

See Also:
intersection(JMLEqualsBag), difference(JMLEqualsBag)
Specifications: non_null (class)pure
public normal_behavior
requires this.size < 2147483647-b2.size;
requires b2 != null;
ensures \result != null&&( \forall java.lang.Object e; ; \result .count(e) == (this.count(e)+b2.count(e)));

difference

public JMLEqualsBag difference(non_null JMLEqualsBag b2)
Return a bag containing the items in this bag minus the items in the given bag. If an item occurs in this bag N times, and M times in the given bag, then it occurs N-M times in the result.

See Also:
union(JMLEqualsBag), difference(JMLEqualsBag)
Specifications: non_null (class)pure
public normal_behavior
requires b2 != null;
ensures \result != null&&( \forall java.lang.Object e; ; \result .count(e) == org.jmlspecs.models.JMLMath.max(0,this.count(e)-b2.count(e)));

toSequence

public JMLEqualsSequence toSequence()
Return a new JMLEqualsSequence containing all the elements of this.

See Also:
toArray(), toSet()
Specifications: non_null (class)pure
public normal_behavior
ensures \result != null&&( \forall java.lang.Object o; ; \result .count(o) == this.count(o));

toSet

public JMLEqualsSet toSet()
Return a new JMLEqualsSet containing all the elements of this.

See Also:
toSequence()
Specifications: non_null (class)pure
public normal_behavior
ensures \result != null&&( \forall java.lang.Object o; ; \result .has(o) == this.has(o));

toArray

public Object[] toArray()
Return a new array containing all the elements of this.

See Also:
toSequence()
Specifications: non_null (class)pure
public normal_behavior
ensures \result != null&&\result .length == this.int_size()&&( \forall java.lang.Object o; ; org.jmlspecs.models.JMLArrayOps.valueEqualsCount(\result ,o) == this.count(o));
ensures_redundantly \result != null&&\result .length == this.int_size()&&( \forall int i; 0 <= i&&i < \result .length; org.jmlspecs.models.JMLArrayOps.valueEqualsCount(\result ,\result [i]) == this.count(\result [i]));

elements

public JMLEqualsBagEnumerator elements()
Returns an Enumeration over this bag.

See Also:
iterator()
Specifications: non_null (class)pure
public normal_behavior
ensures \fresh(\result )&&this.equals(\result .uniteratedElems);

iterator

public JMLIterator iterator()
Returns an iterator over this bag.

Specified by:
iterator in interface JMLCollection
See Also:
elements()
Specifications: non_null (class)pure
     also
public normal_behavior
ensures \fresh(\result )&&\result .equals(new org.jmlspecs.models.JMLEnumerationToIterator(this.elements()));
Specifications inherited from overridden method in interface JMLCollection:
       pure non_null
public normal_behavior
ensures \fresh(\result )&&\result .elementType == this.elementType;
ensures !this.containsNull ==> !\result .returnsNull;

toString

public String toString()
Return a string representation of this object.

Overrides:
toString in class Object
Specifications: non_null (class)pure
     also
public normal_behavior
ensures (* \result is a string representation of this *);
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;

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.