Class ListOfBuckets<E>

java.lang.Object
  extended by ListOfBuckets<E>

public class ListOfBuckets<E>
extends java.lang.Object

This class represents a list of buckets, storing values at specified indices.


Constructor Summary
ListOfBuckets(int numBuckets)
          Constructs a list of buckets of a given size
 
Method Summary
 void add(int bucketNum, E newItem)
          Adds an item to the specified bucket
 java.util.ArrayList<E> asList()
          Converts the list of buckets into an ArrayList, preserving the order of items
 void clear()
          Clears each bucket in the list
 java.util.ArrayList<E> getBucket(int bucketNum)
          Accesses the items stored in a particular bucket
 int numBuckets()
          Determines the number of buckets in the list
 int numStored()
          Determines the total number of items stored in the list
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListOfBuckets

public ListOfBuckets(int numBuckets)
Constructs a list of buckets of a given size

Parameters:
numBuckets - the number of buckets in the list
Method Detail

numBuckets

public int numBuckets()
Determines the number of buckets in the list

Returns:
the number of buckets

numStored

public int numStored()
Determines the total number of items stored in the list

Returns:
the number of items that have been added to the buckets

add

public void add(int bucketNum,
                E newItem)
Adds an item to the specified bucket

Parameters:
bucketNum - the bucket number (0 <= bucketNum < numBuckets())
newItem - the item to be added to that bucket

getBucket

public java.util.ArrayList<E> getBucket(int bucketNum)
Accesses the items stored in a particular bucket

Parameters:
bucketNum - the bucket number (0 <= bucketNum < numBuckets())
Returns:
the list of items stored in that bucket

clear

public void clear()
Clears each bucket in the list


asList

public java.util.ArrayList<E> asList()
Converts the list of buckets into an ArrayList, preserving the order of items

Returns:
an ArrayList containing all items from the buckets, in order