Question: public class ArrayMultiSet extends AbstractCollection { /** Array in which the elements in this multiset are stored. */ private E[] _store; /** Array indices below

public class ArrayMultiSet
/** Array in which the elements in this multiset are stored. */
private E[] _store;
/** Array indices below this amount contain the active elements in this collection. */
private int _size;
/** Modification counter used to preserve the fail-fast nature of its iterators. */
private long _modCount;
/** Constant value used as the initial length of the backing store. */
private static final int DEFAULT_BACKING_STORE_LENGTH = 12;
/**
* Creates a new empty multiset.
*/
public ArrayMultiSet() {
_store = (E[]) new Object[DEFAULT_BACKING_STORE_LENGTH];
}
/**
* Update the multiset so that it includes all of the elements from before the call AND the given element.
*
* @param e Item to be added to this collection.
* @return True when the element was successfully added; false otherwise. This always returns true.
*/
@Override
public boolean add(E e) {
_store = getStoreWithSpace();
includeElement(e);
return true;
}
/**
* Checks if the backing store has a space in which another element can be stored. When there is no space, the method
* allocates an array with twice as much space, copies the existing elements into that new array, and then returns
* that new array. Otherwise, it returns the original backing store.
*/
private E[] getStoreWithSpace() {
}
/**
* Includes the element in the multiset while updating the instance variables so that the class invariant is
* preserved.
* Precondition: _store is guaranteed to have sufficient space for including the new element (preconditions are
* guaranteed to be true at the start)
*
* @param elem Element to be included in the multiset
*/
private void includeElement(E elem) {
}
@Override
public int size() {
return _size;
}
@Override
public boolean isEmpty() {
return _size == 0;
}
}
The first method is getstoreNithSpace().This method does not change_store. getstoreWithspace) checks if there is space in the backing store and (when it has space to include another element) returns store or (when store is full) returns a newly allocated array with an appropriate amount of space You will also need to implement includeElement(.includeElentupdates the instance variables so that the element is included in the instance
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
