edu.colorado.collections
Class IntTreeBag

java.lang.Object
  extended by edu.colorado.collections.IntTreeBag
All Implemented Interfaces:
java.lang.Cloneable

public class IntTreeBag
extends java.lang.Object
implements java.lang.Cloneable

This class is a homework assignment; An IntTreeBag is a collection of int numbers.

Limitations:
Beyond Integer.MAX_VALUE elements, countOccurrences, and size are wrong.
Outline of Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/collections/IntTreeBag.java
Note:
This file contains only blank implementations ("stubs") because this is a Programming Project for my students.

See Also:
IntArrayBag, IntLinkedBag

Constructor Summary
IntTreeBag()
           
 
Method Summary
 void add(int element)
          Insert a new element into this bag.
 void addAll(IntTreeBag addend)
          Add the contents of another bag to this bag.
 java.lang.Object clone()
          Generate a copy of this bag.
 int countOccurrences(int target)
          Accessor method to count the number of occurrences of a particular element in this bag.
 int size()
          Determine the number of elements in this bag.
static IntTreeBag union(IntTreeBag b1, IntTreeBag b2)
          Create a new bag that contains all the elements from two other bags.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntTreeBag

public IntTreeBag()
Method Detail

add

public void add(int element)
Insert a new element into this bag.

Parameters:
element - the new element that is being inserted
Postcondition:
A new copy of the element has been added to this bag.
Throws:
java.lang.OutOfMemoryError - Indicates insufficient memory a new IntBTNode.

addAll

public void addAll(IntTreeBag addend)
Add the contents of another bag to this bag.

Parameters:
addend - a bag whose contents will be added to this bag
Precondition:
The parameter, addend, is not null.
Postcondition:
The elements from addend have been added to this bag.
Throws:
java.lang.IllegalArgumentException - Indicates that addend is null.
java.lang.OutOfMemoryError - Indicates insufficient memory to increase the size of the bag.

clone

public java.lang.Object clone()
Generate a copy of this bag.

Overrides:
clone in class java.lang.Object
Parameters:
- - none
Returns:
The return value is a copy of this bag. Subsequent changes to the copy will not affect the original, nor vice versa. Note that the return value must be type cast to an IntTreeBag before it can be used.
Throws:
java.lang.OutOfMemoryError - Indicates insufficient memory for creating the clone.

countOccurrences

public int countOccurrences(int target)
Accessor method to count the number of occurrences of a particular element in this bag.

Parameters:
target - the element that needs to be counted
Returns:
the number of times that target occurs in this bag

size

public int size()
Determine the number of elements in this bag.

Parameters:
- - none
Returns:
the number of elements in this bag

union

public static IntTreeBag union(IntTreeBag b1,
                               IntTreeBag b2)
Create a new bag that contains all the elements from two other bags.

Parameters:
b1 - the first of two bags
b2 - the second of two bags
Precondition:
Neither b1 nor b2 is null.
Returns:
the union of b1 and b2
Throws:
java.lang.IllegalArgumentException - Indicates that one of the arguments is null.
java.lang.OutOfMemoryError - Indicates insufficient memory for the new bag.