package programmingexample4;
import java.util.ArrayList;
import java.util.Iterator;
/**
* A bag implemented using an ArrayList.
*
* @author Robert Clifton-Everest
*
* @invariant for all c in counts, c.getCount() > 0
*
* @param
*/
public class ArrayListBag
private ArrayList
/**
* Create a new empty bag.
*/
public ArrayListBag() {
this.counts = new ArrayList
}
private Count
for (Count
if (c.getElement().equals(o))
return c;
return null;
}
@Override
public void add(E e) {
add(e,1);
}
@Override
public void add(E e, int n) {
Count
if (c != null) {
c.incrementCount(n);
} else if (n > 0) {
counts.add(new Count
}
}
@Override
public void remove(E e) {
remove(e, 1);
}
@Override
public void remove(E e, int n) {
// TODO Implement this
}
@Override
public int count(Object o) {
Count
if (c != null)
return c.getCount();
return 0;
}
@Override
public int size() {
// TODO Implement this
return 0;
}
@Override
public Bag
// TODO Implement this
return null;
}
@Override
public Iterator
return counts.iterator();
}
/**
* For this method, it should be possible to compare all other possible bags
* for equality with this bag. For example, if an ArrayListBag
* LinkedListBag
* are equal. Similarly, if a Bag
* Bag
*/
@Override
public boolean equals(Object o) {
// TODO Implement this
return false;
}
}