org.jmlspecs.models
Class JMLValueBag
java.lang.Object
org.jmlspecs.models.JMLValueBagSpecs
org.jmlspecs.models.JMLValueBag
- All Implemented Interfaces:
- Cloneable, JMLCollection, JMLType, JMLValueType, Serializable
- public class JMLValueBag
- extends JMLValueBagSpecs
- implements JMLCollection
Bags (i.e., multisets) of values. This type uses
".equals" to compare elements, and clones 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
,
JMLValueBagEnumerator
,
JMLValueBagSpecs
,
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.JMLValueBagEntry);
public invariant ( \forall org.jmlspecs.models.JMLType e1; ; this.count(e1) >= 0);
public invariant ( \forall org.jmlspecs.models.JMLValueBag s2; s2 != null; ( \forall org.jmlspecs.models.JMLType e1, e2; ; this.equational_theory(this,s2,e1,e2)));
public invariant this.elementType <: \type(org.jmlspecs.models.JMLType);
public invariant ( \forall org.jmlspecs.models.JMLType 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); |
Method Summary |
JMLType |
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 JMLValueBag |
convertFrom(non_null Collection c)
Return the bag containing all the value in the
given collection. |
static JMLValueBag |
convertFrom(non_null JMLCollection c)
Return the bag containing all the value in the
given JMLCollection. |
static JMLValueBag |
convertFrom(non_null JMLType[] a)
Return the bag containing all the elements in the given array. |
int |
count(JMLType elem)
Tell how many times the given element occurs ".equals"
to an element in this bag. |
JMLValueBag |
difference(non_null JMLValueBag b2)
Return a bag containing the items in this bag minus the
items in the given bag. |
JMLValueBagEnumerator |
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 JMLValueBagEntry |
getMatchingEntry(JMLType item)
Find a JMLValueBagEntry that is for the same element, if possible. |
boolean |
has(JMLType elem)
Tell whether the given element occurs ".equals"
to an element in this bag. |
int |
hashCode()
Return a hash code for this object |
JMLValueBag |
insert(nullable JMLType elem)
Return a bag containing the given item and the ones in
this bag. |
JMLValueBag |
insert(nullable JMLType 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. |
JMLValueBag |
intersection(non_null JMLValueBag 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 JMLValueBag b2)
Tells whether every item in this bag is contained in the
argument, but the argument is strictly larger. |
boolean |
isProperSuperbag(non_null JMLValueBag b2)
Tells whether every item in the argument is contained in this bag
argument, but this bag is strictly larger. |
boolean |
isSubbag(non_null JMLValueBag b2)
Tells whether every item in this bag is contained in the argument. |
boolean |
isSuperbag(non_null JMLValueBag b2)
Tells whether every item in the argument is contained in this bag. |
JMLIterator |
iterator()
Returns an iterator over this bag. |
JMLValueBag |
remove(nullable JMLType elem)
Return a bag containing the items in this bag except for
one of the given element. |
JMLValueBag |
remove(nullable JMLType elem,
int cnt)
Return a bag containing the items in this bag, except for
the given number of the given element. |
JMLValueBag |
removeAll(nullable JMLType elem)
Return a bag containing the items in this bag, except for
all items that are ".equals" to the given item. |
static JMLValueBag |
singleton(JMLType e)
Return the singleton bag containing the given element. |
JMLType[] |
toArray()
Return a new array containing all the elements of this. |
JMLValueSequence |
toSequence()
Return a new JMLValueSequence containing all the elements of this. |
JMLValueSet |
toSet()
Return a new JMLValueSet containing all the elements of this. |
String |
toString()
Return a string representation of this object. |
JMLValueBag |
union(non_null JMLValueBag b2)
Return a bag containing the items in either this bag or the
given bag. |
the_list
protected final JMLValueBagEntryNode the_list
- The list representing the contents of this bag. Each element
of this list is of type JMLValueBagEntry.
- 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 JMLValueBag EMPTY
- The empty JMLValueBag.
- See Also:
JMLValueBag()
- Specifications: non_null
JMLValueBag
public JMLValueBag()
- 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(org.jmlspecs.models.JMLType)&&!this.containsNull;
JMLValueBag
public JMLValueBag(JMLType elem)
- Initialize this bag to contain the given element.
- Parameters:
elem
- the element that is the sole contents of this bag.- See Also:
singleton(org.jmlspecs.models.JMLType)
- 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 *);
- also
-
public model_program { ... }
- implies_that
-
ensures this.containsNull <==> elem == null;
ensures elem != null ==> this.elementType == \typeof(elem);
ensures elem == null ==> this.elementType <: \type(org.jmlspecs.models.JMLType);
JMLValueBag
protected JMLValueBag(JMLValueBagEntryNode 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(org.jmlspecs.models.JMLType) : ls.entryElementType);
ensures this.containsNull == (ls == null ? false : ls.containsNullElements);
equational_theory
public boolean equational_theory(JMLValueBag s,
JMLValueBag s2,
JMLType e1,
JMLType e2)
- An equational specification of the properties of bags.
- Specifications: pure
-
public normal_behavior
{|-
ensures \result <==> (new org.jmlspecs.models.JMLValueBag()).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.JMLValueBag()).int_size() == 0;
- also
-
ensures \result <==> s.insert(e1).int_size() == (s.int_size()+1);
- also
-
ensures \result <==> s.isSubbag(s2) == ( \forall org.jmlspecs.models.JMLType 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.JMLValueBag()).remove(e1).equals(new org.jmlspecs.models.JMLValueBag());
- 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.JMLValueBag()).has(e1);
- also
-
ensures \result <==> (new org.jmlspecs.models.JMLValueBag(e1)).equals(new org.jmlspecs.models.JMLValueBag().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.JMLValueBag()).isEmpty();
ensures \result <==> !s.insert(e1).isEmpty();
ensures \result <==> (new org.jmlspecs.models.JMLValueBag(null)).has(e2) == (e2 == null);
ensures \result <==> (e1 != null ==> new org.jmlspecs.models.JMLValueBag(e1).has(e2) == (e1.equals(e2)));
singleton
public static JMLValueBag singleton(JMLType e)
- Return the singleton bag containing the given element.
- See Also:
JMLValueBag(JMLType)
- Specifications: pure non_null
-
public normal_behavior
ensures \result != null&&\result .equals(new org.jmlspecs.models.JMLValueBag(e));
convertFrom
public static JMLValueBag convertFrom(non_null JMLType[] 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 JMLValueBag convertFrom(non_null Collection c)
throws ClassCastException
- Return the bag containing all the value in the
given collection.
- Throws:
ClassCastException
- if some element in c is not an instance of
JMLType.- See Also:
containsAll(java.util.Collection)
- Specifications: pure non_null
-
public normal_behavior
requires c != null&&(c.elementType <: \type(org.jmlspecs.models.JMLType));
ensures \result != null&&\result .int_size() == c.size()&&(* \result contains each element in c *);
ensures_redundantly \result != null&&\result .int_size() == c.size()&&( \forall org.jmlspecs.models.JMLType x; ; c.contains(x) <==> \result .has(x));
- also
-
public exceptional_behavior
requires c != null&&( \exists java.lang.Object o; c.contains(o); !(o instanceof org.jmlspecs.models.JMLType));
signals_only java.lang.ClassCastException;
convertFrom
public static JMLValueBag convertFrom(non_null JMLCollection c)
throws ClassCastException
- Return the bag containing all the value in the
given JMLCollection.
- Throws:
ClassCastException
- if some element in c is not an instance of
JMLType.
- Specifications: pure non_null
-
public normal_behavior
requires c != null&&(c.elementType <: \type(org.jmlspecs.models.JMLType));
ensures \result != null&&( \forall org.jmlspecs.models.JMLType 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 org.jmlspecs.models.JMLType));
signals_only java.lang.ClassCastException;
count
public int count(JMLType 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(JMLType)
- Specifications: (class)pure
- also
-
public normal_behavior
ensures \result >= 0&&(* \result is the number of times elem occurs in this *);
- Specifications inherited from overridden method count(JMLType elem) in class JMLValueBagSpecs:
(class)pure -
public normal_behavior
ensures \result >= 0&&(* \result is the number of times elem tests as ".equals" to one of the objects in the bag *);
has
public boolean has(JMLType elem)
- Tell whether the given element occurs ".equals"
to an element in this bag.
- Parameters:
elem
- the element sought.- See Also:
count(JMLType)
- Specifications: (class)pure
- also
-
public normal_behavior
ensures \result <==> (this.count(elem) > 0);
- Specifications inherited from overridden method has(JMLType elem) in class JMLValueBagSpecs:
(class)pure -
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(JMLValueSet)
,
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.JMLValueBag&&( \forall org.jmlspecs.models.JMLType e; ; this.count(e) == ((org.jmlspecs.models.JMLValueBag)b2).count(e));
- implies_that
-
public normal_behavior
requires b2 != null&&b2 instanceof org.jmlspecs.models.JMLValueBag;
ensures \result ==> this.int_size() == ((org.jmlspecs.models.JMLValueBag)b2).int_size()&&this.containsNull == ((org.jmlspecs.models.JMLValueBag)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;
- |}
- Specifications inherited from overridden method equals(Object ob2) in interface JMLValueType:
pure- also
-
public normal_behavior
ensures \result ==> ob2 != null&&(* all externally-visible objects contained in ob2 test as ".equals()" to the corresponding object in this (and vice versa) *);
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(JMLType)
- Specifications: (class)pure
-
public normal_behavior
ensures \result == ( \forall org.jmlspecs.models.JMLType 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 class JMLValueBagSpecs:
(class)pure -
public normal_behavior
ensures \result >= 0&&(* \result is the number of elements in the 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 JMLValueBag b2)
- Tells whether every item in this bag is contained in the argument.
- See Also:
isProperSubbag(JMLValueBag)
,
isSuperbag(JMLValueBag)
- Specifications: (class)pure
-
public normal_behavior
requires b2 != null;
ensures \result <==> ( \forall org.jmlspecs.models.JMLType e; ; this.count(e) <= b2.count(e));
isProperSubbag
public boolean isProperSubbag(non_null JMLValueBag b2)
- Tells whether every item in this bag is contained in the
argument, but the argument is strictly larger.
- See Also:
isSubbag(JMLValueBag)
,
isProperSuperbag(JMLValueBag)
- Specifications: (class)pure
-
public normal_behavior
requires b2 != null;
ensures \result <==> this.isSubbag(b2)&&!this.equals(b2);
isSuperbag
public boolean isSuperbag(non_null JMLValueBag b2)
- Tells whether every item in the argument is contained in this bag.
- See Also:
isProperSuperbag(JMLValueBag)
,
isSubbag(JMLValueBag)
,
containsAll(java.util.Collection)
- Specifications: (class)pure
-
public normal_behavior
requires b2 != null;
ensures \result == b2.isSubbag(this);
isProperSuperbag
public boolean isProperSuperbag(non_null JMLValueBag b2)
- Tells whether every item in the argument is contained in this bag
argument, but this bag is strictly larger.
- See Also:
isSuperbag(JMLValueBag)
,
isProperSubbag(JMLValueBag)
- Specifications: (class)pure
-
public normal_behavior
requires b2 != null;
ensures \result == b2.isProperSubbag(this);
choose
public JMLType 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 org.jmlspecs.models.JMLType 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 clones the
elements of the bag.
- Specified by:
clone
in interface JMLType
- Specified by:
clone
in class JMLValueBagSpecs
- Specifications: non_null (class)pure
- also
-
public normal_behavior
ensures \result instanceof org.jmlspecs.models.JMLValueBag&&this.equals(\result );
ensures_redundantly \result != null;
- Specifications inherited from overridden method in class JMLValueBagSpecs:
(class)pure- 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);
- Specifications inherited from overridden method in interface JMLValueType:
pure- also
-
public normal_behavior
ensures \result instanceof org.jmlspecs.models.JMLValueType&&(* all externally-visible mutable objects contained directly in "this" must be cloned in \result. *);
- implies_that
-
ensures (* no direct aliases are created between this and \result *);
getMatchingEntry
protected JMLValueBagEntry getMatchingEntry(JMLType item)
- Find a JMLValueBagEntry 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 JMLValueBag insert(nullable JMLType elem)
throws IllegalStateException
- Return a bag containing the given item and the ones in
this bag.
- Throws:
IllegalStateException
- See Also:
insert(JMLType, int)
,
has(JMLType)
,
remove(JMLType)
- Specifications: non_null (class)pure
-
public normal_behavior
requires this.size < 2147483647;
{|-
requires elem != null;
ensures \result != null&&( \forall org.jmlspecs.models.JMLType 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 org.jmlspecs.models.JMLType e; ; (e == null ==> \result .count(e) == this.count(e)+1)&&(e != null ==> \result .count(e) == this.count(e)));
- |}
- also
-
public model_program { ... }
insert
public JMLValueBag insert(nullable JMLType 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(JMLType)
,
has(JMLType)
,
remove(JMLType, int)
- Specifications: non_null (class)pure
- also
-
public normal_behavior
requires cnt > 0;
requires this.size <= 2147483647-cnt;
{|-
requires elem != null;
ensures \result != null&&( \forall org.jmlspecs.models.JMLType 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 org.jmlspecs.models.JMLType 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);
- Specifications inherited from overridden method insert(JMLType elem, int cnt) in class JMLValueBagSpecs:
non_null (class)pure -
public model_program { ... }
- also
-
signals (java.lang.IllegalArgumentException) cnt < 0;
remove
public JMLValueBag remove(nullable JMLType elem)
- Return a bag containing the items in this bag except for
one of the given element.
- See Also:
remove(JMLType, int)
,
insert(JMLType)
- Specifications: non_null (class)pure
-
public normal_behavior
{|-
requires elem != null;
ensures \result != null&&( \forall org.jmlspecs.models.JMLType 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 org.jmlspecs.models.JMLType e; ; (e == null ==> \result .count(e) == this.count(e)-1)&&(e != null ==> \result .count(e) == this.count(e)));
- |}
remove
public JMLValueBag remove(nullable JMLType 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(JMLType)
,
insert(JMLType, int)
- Specifications: non_null (class)pure
-
public normal_behavior
requires cnt > 0;
{|-
requires elem != null;
ensures \result != null&&( \forall org.jmlspecs.models.JMLType 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 org.jmlspecs.models.JMLType 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 JMLValueBag removeAll(nullable JMLType elem)
- Return a bag containing the items in this bag, except for
all items that are ".equals" to the given item.
- See Also:
remove(JMLType)
,
remove(JMLType, int)
- Specifications: non_null (class)pure
-
public normal_behavior
requires elem != null;
ensures \result != null&&( \forall org.jmlspecs.models.JMLType 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 org.jmlspecs.models.JMLType e; ; (e == null ==> \result .count(e) == 0)&&(e != null ==> \result .count(e) == this.count(e)));
intersection
public JMLValueBag intersection(non_null JMLValueBag 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(JMLValueBag)
,
difference(JMLValueBag)
- Specifications: non_null (class)pure
-
public normal_behavior
requires b2 != null;
ensures \result != null&&( \forall org.jmlspecs.models.JMLType e; ; \result .count(e) == java.lang.Math.min(this.count(e),b2.count(e)));
union
public JMLValueBag union(non_null JMLValueBag 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(JMLValueBag)
,
difference(JMLValueBag)
- Specifications: non_null (class)pure
-
public normal_behavior
requires this.size < 2147483647-b2.size;
requires b2 != null;
ensures \result != null&&( \forall org.jmlspecs.models.JMLType e; ; \result .count(e) == (this.count(e)+b2.count(e)));
difference
public JMLValueBag difference(non_null JMLValueBag 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(JMLValueBag)
,
difference(JMLValueBag)
- Specifications: non_null (class)pure
-
public normal_behavior
requires b2 != null;
ensures \result != null&&( \forall org.jmlspecs.models.JMLType e; ; \result .count(e) == org.jmlspecs.models.JMLMath.max(0,this.count(e)-b2.count(e)));
toSequence
public JMLValueSequence toSequence()
- Return a new JMLValueSequence containing all the elements of this.
- See Also:
toArray()
,
toSet()
- Specifications: non_null (class)pure
-
public normal_behavior
ensures \result != null&&( \forall org.jmlspecs.models.JMLType o; ; \result .count(o) == this.count(o));
toSet
public JMLValueSet toSet()
- Return a new JMLValueSet containing all the elements of this.
- See Also:
toSequence()
- Specifications: non_null (class)pure
-
public normal_behavior
ensures \result != null&&( \forall org.jmlspecs.models.JMLType o; ; \result .has(o) == this.has(o));
toArray
public JMLType[] 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 org.jmlspecs.models.JMLType 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 JMLValueBagEnumerator 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 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.