예제 #1
0
 /*@  public normal_behavior
 @    requires othMap != null && errval != null;
 @    requires int_size()
 @             <= Integer.MAX_VALUE - othMap.difference(this).int_size();
 @    ensures (\forall JMLObjectObjectPair pair; ;
 @                 \result.theRelation.has(pair)
 @                    ==
 @                       (!othMap.isDefinedAt(pair.key)
 @                        && this.elementImage(pair.key).has(pair.value))
 @                    || (!this.isDefinedAt(pair.key)
 @                        && othMap.elementImage(pair.key)
 @                                 .has(pair.value))
 @                    || (this.isDefinedAt(pair.key)
 @                        && othMap.isDefinedAt(pair.key)
 @                        && pair.value  == (errval))
 @                );
 @ implies_that
 @    requires othMap != null && errval != null;
 @*/
 public /*@ non_null @*/ JMLObjectToObjectMap clashReplaceUnion(
     JMLObjectToObjectMap othMap, Object errval) throws IllegalStateException {
   JMLObjectSet overlap = this.domain_.intersection(othMap.domain_);
   Enumeration overlapEnum = overlap.elements();
   othMap = othMap.restrictedTo(othMap.domain_.difference(overlap));
   JMLObjectToObjectMap newMap = this.restrictedTo(this.domain_.difference(overlap));
   JMLObjectToObjectRelation newRel;
   if (newMap.size_ <= Integer.MAX_VALUE - othMap.size_) {
     newRel =
         new JMLObjectToObjectRelation(
             newMap.imagePairSet_.union(othMap.imagePairSet_),
             newMap.domain_.union(othMap.domain_),
             newMap.size_ + othMap.size_);
   } else {
     throw new IllegalStateException(TOO_BIG_TO_UNION);
   }
   Object dv;
   while (overlapEnum.hasMoreElements()) {
     // @ assume overlapEnum.moreElements;
     Object oo = overlapEnum.nextElement();
     // @ assume oo != null && oo instanceof Object;
     dv = (Object) oo;
     newRel = newRel.add(dv, errval);
   }
   return newRel.toFunction();
 } // @ nowarn Exception;
  /*@  public normal_behavior
  @    requires othRel != null;
  @    ensures (\forall JMLValueEqualsPair pair; ;
  @                 \result.theRelation.has(pair)
  @                    == (\exists Object val;
  @                            othRel.elementImage(pair.key).has(val);
  @                            this.elementImage(val).has(pair.value)
  @                            )
  @                );
  @*/
  public /*@ non_null @*/ JMLObjectToEqualsRelation compose(
      /*@ non_null @*/ JMLObjectToEqualsRelation othRel) {
    JMLValueSet newImagePairSet = new JMLValueSet();
    JMLObjectSet newDom = new JMLObjectSet();
    int newSize = 0;

    JMLObjectToEqualsRelationImageEnumerator imagePairEnum = othRel.imagePairs();
    JMLObjectValuePair imagePair;
    JMLEqualsSet img1;
    JMLEqualsSet img2;
    int imgSize;
    while (imagePairEnum.hasMoreElements()) {
      imagePair = imagePairEnum.nextImagePair();
      // @ assume imagePair.value != null;
      // @ assume imagePair.value instanceof JMLEqualsSet;
      img1 = (JMLEqualsSet) imagePair.value;
      img2 = this.image(img1);
      imgSize = img2.int_size();
      if (imgSize > 0) {
        newImagePairSet = newImagePairSet.insert(new JMLObjectValuePair(imagePair.key, img2));
        newSize = newSize + imgSize;
        newDom = newDom.insert(imagePair.key);
      }
    }
    return new JMLObjectToEqualsRelation(newImagePairSet, newDom, newSize);
  } // @ nowarn Exception;
예제 #3
0
 /*@  public normal_behavior
 @    requires isDefinedAt(dv);
 @    ensures elementImage(dv).has(\result);
 @ also
 @  public exceptional_behavior
 @    requires !isDefinedAt(dv);
 @    signals_only JMLNoSuchElementException;
 @*/
 public /*@ non_null @*/ Object apply(JMLType dv) throws JMLNoSuchElementException {
   JMLObjectSet img = elementImage(dv);
   if (img.int_size() == 1) {
     Object res = img.choose();
     // @ assume res != null;
     return res;
   } else {
     throw new JMLNoSuchElementException("Map not defined at " + dv);
   }
 } // @ nowarn NonNullResult;
예제 #4
0
 /*@  public normal_behavior
 @    requires othMap != null
 @          && this.domain().intersection(othMap.domain()).isEmpty();
 @    requires int_size() <= Integer.MAX_VALUE - othMap.int_size();
 @    ensures \result.equals(this.union(othMap));
 @ also
 @  public exceptional_behavior
 @    requires othMap != null
 @          && !this.domain().intersection(othMap.domain()).isEmpty();
 @    signals_only JMLMapException;
 @*/
 public /*@ non_null @*/ JMLObjectToObjectMap disjointUnion(
     /*@ non_null @*/ JMLObjectToObjectMap othMap) throws JMLMapException, IllegalStateException {
   JMLObjectSet overlappingDom = domain_.intersection(othMap.domain_);
   if (overlappingDom.isEmpty()) {
     if (this.size_ <= Integer.MAX_VALUE - othMap.size_) {
       return new JMLObjectToObjectMap(
           this.imagePairSet_.union(othMap.imagePairSet_),
           this.domain_.union(othMap.domain_),
           this.size_ + othMap.size_);
     } else {
       throw new IllegalStateException(TOO_BIG_TO_UNION);
     }
   } else {
     throw new JMLMapException(
         "Overlapping domains in " + " disjointUnion operation", overlappingDom);
   }
 }