org.jutil.java.collections
Class Collections

java.lang.Object
  |
  +--org.jutil.java.collections.Collections

public abstract class Collections
extends java.lang.Object

A utility class for perform operations on collections similar to java.util.Collections.

Version:
$Revision: 1.16 $
Author:
Marko van Dooren

Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
Collections()
           
 
Method Summary
static boolean containsExplicitly(java.util.Collection collection, java.lang.Object element)
          public invariant_redundantly
(\forall Collection c; c != null;
(\forall Object o1; c.contains(o1);
(\exists Object o2; containsEplicitly(c, o2);
((o1 == null) && (o2 == null)) ||
((o1 != null) && (o1.equals(o2)))));

public invariant_redundantly
(\forall Collection c; c!= null;
(\forall Object o2; containsEplicitly(collection, o2);
c.contains(o2)));

public behavior

pre collection != null;

post \result == (\exists int i; i >= 0 && i < collection.toArray().length;
collection.toArray()[i] == element);
Check whether or not the given collection contains the given element when using == for comparison instead of equals().
static boolean identical(java.util.Collection first, java.util.Collection second)
          public behavior

// True if both collections are null
post ((first == null) && (second == null)) ==> \result == true;

// False if only one of both is null.
post ((first == null) || (second == null)) &&
!((first == null) && (second == null)) ==> \result ==false;

// If both collections are non-null, true if both collections
// have the same size and contains the exact same elements.
post ((first != null) && (second != null)) ==>
\result == (first.size() == second.size()) &&
(\forall Object o1; containsExplicitly(first, o1);
nbExplicitOccurrences(first,o1) == nbExplicitOccurrences(second, o2));
Check whether the two given collections contain the same elements.
static boolean identical(java.util.Map first, java.util.Map second)
          // True if both maps are null
post ((first == null) && (second == null)) ==> \result == true;

// False if only one of both is null.
post ((first == null) || (second == null)) &&
!((first == null) && (second == null)) ==> \result ==false;

// If both maps are non-null, true if both maps
// have the same size and contains the same (key,value) pairs.
post ((first != null) && (second != null)) ==>
\result == (first.size() == second.size()) &&
(\forall Object k; first.containsKey(k);
second.containsKey(k) && second.get(k) == first.get(k)) &&
first.size() == second.size();
post (\forall Map.Entry e1; first.entrySet().contains(e1);
(\exists Map.Entry e2; second.entrySet().contains(e2);
(e1.getKey() == e2.getKey()) &&
Check whether the two given maps contain the same entries.
static int nbExplicitOccurrences(java.lang.Object element, java.util.Collection collection)
          public behavior

pre collection != null;

post \result == (\num_of int i; i >= 0 && i < collection.toArray().length;
collection.toArray()[i] == element);
Return the number of times has been added to .
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

Collections

public Collections()
Method Detail

containsExplicitly

public static boolean containsExplicitly(java.util.Collection collection,
                                         java.lang.Object element)
public invariant_redundantly
(\forall Collection c; c != null;
(\forall Object o1; c.contains(o1);
(\exists Object o2; containsEplicitly(c, o2);
((o1 == null) && (o2 == null)) ||
((o1 != null) && (o1.equals(o2)))));

public invariant_redundantly
(\forall Collection c; c!= null;
(\forall Object o2; containsEplicitly(collection, o2);
c.contains(o2)));

public behavior

pre collection != null;

post \result == (\exists int i; i >= 0 && i < collection.toArray().length;
collection.toArray()[i] == element);
Check whether or not the given collection contains the given element when using == for comparison instead of equals().
Parameters:
collection - The collection
element - The element

nbExplicitOccurrences

public static int nbExplicitOccurrences(java.lang.Object element,
                                        java.util.Collection collection)
public behavior

pre collection != null;

post \result == (\num_of int i; i >= 0 && i < collection.toArray().length;
collection.toArray()[i] == element);
Return the number of times has been added to .
Parameters:
element - The element of which the number of occurrences is requested.
collection - The collection in which the number of occurrences has to be counted.

identical

public static boolean identical(java.util.Collection first,
                                java.util.Collection second)
public behavior

// True if both collections are null
post ((first == null) && (second == null)) ==> \result == true;

// False if only one of both is null.
post ((first == null) || (second == null)) &&
!((first == null) && (second == null)) ==> \result ==false;

// If both collections are non-null, true if both collections
// have the same size and contains the exact same elements.
post ((first != null) && (second != null)) ==>
\result == (first.size() == second.size()) &&
(\forall Object o1; containsExplicitly(first, o1);
nbExplicitOccurrences(first,o1) == nbExplicitOccurrences(second, o2));
Check whether the two given collections contain the same elements. Test are done with ==
Parameters:
first - The first collection
second - The second collection

identical

public static boolean identical(java.util.Map first,
                                java.util.Map second)
// True if both maps are null
post ((first == null) && (second == null)) ==> \result == true;

// False if only one of both is null.
post ((first == null) || (second == null)) &&
!((first == null) && (second == null)) ==> \result ==false;

// If both maps are non-null, true if both maps
// have the same size and contains the same (key,value) pairs.
post ((first != null) && (second != null)) ==>
\result == (first.size() == second.size()) &&
(\forall Object k; first.containsKey(k);
second.containsKey(k) && second.get(k) == first.get(k)) &&
first.size() == second.size();
post (\forall Map.Entry e1; first.entrySet().contains(e1);
(\exists Map.Entry e2; second.entrySet().contains(e2);
(e1.getKey() == e2.getKey()) &&
Check whether the two given maps contain the same entries. Test are done with ==
Parameters:
first - The first map
second - The second map