org.zedlib
Interface Bag

All Superinterfaces:
Collection, Function, Relation, Set, Set
All Known Implementing Classes:
HashBag

public interface Bag
extends Function

Bags are collections of elements of X in which the number of times an element occurs is significant.

Author:
Brad Long

Method Summary
 boolean add(Baglet b)
          Adds a maplet to this relation.
 boolean add(Object x, int y)
          Adds an object to this bag with the specified number of occurrences.
 boolean containsMember(Object x)
          Determines whether an object is in the bag.
 boolean containsValue(int count)
          A convenience function for the alternative range().contains(new Integer(count)).
 int getCount(Object o)
          Counts the number of times an element appears in this bag.
 boolean isSubBagOf(Bag c)
          Determines whether this bag is a sub-bag of a given bag.
 Object put(Object x, int y)
          Adds an object to this bag a specified number of times.
 
Methods inherited from interface org.zedlib.Function
containsKey, containsValue, getMaplet, put
 
Methods inherited from interface org.zedlib.Relation
add, add, addAll, composition, domain, domainAntiRestriction, domainRestriction, image, inverse, isFunction, isInjection, isReflexive, override, range, rangeAntiRestriction, rangeRestriction, transitiveClosure
 
Methods inherited from interface org.zedlib.Set
cartesianProduct, difference, identity, intersection, isSubsetOf, isSupersetOf, union
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Method Detail

getCount

public int getCount(Object o)
Counts the number of times an element appears in this bag.

Parameters:
o - the object for which to count occurrences
Returns:
the number of times the given key appears in the bag

containsValue

public boolean containsValue(int count)
A convenience function for the alternative range().contains(new Integer(count)).

Parameters:
count - any integer
Returns:
true if at least one object exists in the bag occurrence times.

add

public boolean add(Object x,
                   int y)
Adds an object to this bag with the specified number of occurrences.

Parameters:
x - the object to add
y - the number of times the object should appear in the bag
Returns:
true if the maplet was added or false if the maplet already exists or number of occurrences given is less then one.

add

public boolean add(Baglet b)
Adds a maplet to this relation.

Parameters:
b - the baglet to add to this bag
Returns:
true if the given maplet was added to this relation
See Also:
Set.add(Object o)

put

public Object put(Object x,
                  int y)
Adds an object to this bag a specified number of times.

Parameters:
x - the object to add
y - the number of times the object should appear in the bag
Returns:
the Integer object that was replaced or null if x was not previously in the bag.

containsMember

public boolean containsMember(Object x)
Determines whether an object is in the bag. The relationship B.containsMember(x) holds exactly if x appears in B a non-zero number of times. A convenience function for the alternative domain().contains(x).

Parameters:
x - the object to check for existence
Returns:
true if the object is in the bag

isSubBagOf

public boolean isSubBagOf(Bag c)
Determines whether this bag is a sub-bag of a given bag. A bag B is a sub-bag of another bag C if each element occurs in B no more often than it occurs in C.

Parameters:
c - any bag
Returns:
true if this bag is a sub-bag of c


Copyright © 2006 Brad Long. All Rights Reserved.