run: ------------------------------ java.lang.NullPointerException: null parameter test add ------------------------------ test toString ArrayListASDV[10 20 ] ArrayListASDV[a b c d ]...

1 answer below »
Implement all methods without code and your output should match exactly the output shown


run: ------------------------------ java.lang.NullPointerException: null parameter test add ------------------------------ test toString ArrayListASDV[10 20 ] ArrayListASDV[a b c d ] ArrayListASDV[A1{x=-1} A1{x=-2} ] ------------------------------ test contains java.lang.IndexOutOfBoundsException: 30 out of bounds contains E contains c: true contains null: false contains k: false ArrayListASDV[a b c d ] contains A(-1): true contains A(-3): false java.lang.IndexOutOfBoundsException: 12 is out of bounds ------------------------------ test toArray(): [ a b c d ] --------------------------------------- test clear() ArrayListASDV[] --------------------------------------- test size 0 --------------------------------------- test add(index, element) current array size:8 current array size:16 current array size:32 ArrayListASDV[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ] ArrayListASDV[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z z ] ArrayListASDV[A B C D E F G H I J K L M N O P Q R S T U V W X Y y Z z ] --------------------------------------- test remove(index) z ArrayListASDV[A B C D E F G H I J K L M N O P Q R S T U V W X Y y Z ] --------------------------------------- test remove(Object) ArrayListASDV[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ] false --------------------------------------- test set(index, Object) ArrayListASDV[0 B C D E F G H I J K L M N O P Q R S T U V W X Y 25 ] --------------------------------------- test indexOf() 0 1 25 24 -1 --------------------------------------- test lastndexOf() 0 10 -1 ArrayListASDV[0 B C D E F G H I J 0 K L M N O P Q R S T U V W X Y 25 ] --------------------------------------- test sublist(from, to) ArrayListASDV[B C D E F G H I J ] ArrayListASDV[K L M N O P Q R S T U V W X Y ] ArrayListASDV[] --------------------------------------- test toArray() K L M N O P Q R S T U V W X Y --------------------------------------- test toArray(T[] a) small size a 10 20 null null --------------------------------------- test toArray(T[] a) Big size a A1{x=100} null null --------------------------------------- test Iterator() ArrayListASDV[0 B C D E F G H I J 0 K L M N O P Q R S T U V W X Y 25 ] 0 B C D E F G H I J 0 K L M N O P Q R S T U V W X Y 25 --------------------------------------- test ListIterator1() ArrayListASDV[10 20 30 40 ] next index: 2previous index: 130next index: 3previous index: 240 next index: 4previous index: 340next index: 3previous index: 230next index: 2previous index: 120next index: 1previous index: 010 next index: 0 previous index: -1 --------------------------------------- test forEachRemaining() 10 21 31 41 --------------------------------------- test containsAll(Collection) true false --------------------------------------- test removeAll(Collection) ArrayListASDV[10 20 30 40 10 11 10 ] true ArrayListASDV[20 30 40 11 ] ArrayListASDV[20 30 11 ] java.lang.ClassCastException: Incompatible types: java.lang.Integer, java.lang.Double ArrayListASDV[20 30 11 ] java.lang.ClassCastException: Incompatible types: java.lang.Integer, withCode.A1 --------------------------------------- test retainAll(Collection) ArrayListASDV[30 ] --------------------------------------- test addAll(Collection) ArrayListASDV[30 1 2 3 4 ] --------------------------------------- test addAll(index, Collection) ArrayListASDV[30 1 100 200 300 2 3 4 ] BUILD SUCCESSFUL (total time: 0 seconds) run: ------------------------------ java.lang.NullPointerException: null parameter test add ------------------------------ test toString ArrayListASDV[10 20 ] ArrayListASDV[a b c d ] ArrayListASDV[A1{x=-1} A1{x=-2} ] ------------------------------ test contains java.lang.IndexOutOfBoundsException: 30 out of bounds contains E contains c: true contains null: false contains k: false ArrayListASDV[a b c d ] contains A(-1): true contains A(-3): false java.lang.IndexOutOfBoundsException: 12 is out of bounds ------------------------------ test toArray(): [ a b c d ] --------------------------------------- test clear() ArrayListASDV[] --------------------------------------- test size 0 --------------------------------------- test add(index, element) current array size:8 current array size:16 current array size:32 ArrayListASDV[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ] ArrayListASDV[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z z ] ArrayListASDV[A B C D E F G H I J K L M N O P Q R S T U V W X Y y Z z ] --------------------------------------- test remove(index) z ArrayListASDV[A B C D E F G H I J K L M N O P Q R S T U V W X Y y Z ] --------------------------------------- test remove(Object) ArrayListASDV[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ] false --------------------------------------- test set(index, Object) ArrayListASDV[0 B C D E F G H I J K L M N O P Q R S T U V W X Y 25 ] --------------------------------------- test indexOf() 0 1 25 24 -1 --------------------------------------- test lastndexOf() 0 10 -1 ArrayListASDV[0 B C D E F G H I J 0 K L M N O P Q R S T U V W X Y 25 ] --------------------------------------- test sublist(from, to) ArrayListASDV[B C D E F G H I J ] ArrayListASDV[K L M N O P Q R S T U V W X Y ] ArrayListASDV[] --------------------------------------- test toArray() K L M N O P Q R S T U V W X Y --------------------------------------- test toArray(T[] a) small size a 10 20 null null --------------------------------------- test toArray(T[] a) Big size a A1{x=100} null null --------------------------------------- test Iterator() ArrayListASDV[0 B C D E F G H I J 0 K L M N O P Q R S T U V W X Y 25 ] 0 B C D E F G H I J 0 K L M N O P Q R S T U V W X Y 25 --------------------------------------- test ListIterator1() ArrayListASDV[10 20 30 40 ] next index: 2previous index: 130next index: 3previous index: 240 next index: 4previous index: 340next index: 3previous index: 230next index: 2previous index: 120next index: 1previous index: 010 next index: 0 previous index: -1 --------------------------------------- test forEachRemaining() 10 21 31 41 --------------------------------------- test containsAll(Collection) true false --------------------------------------- test removeAll(Collection) ArrayListASDV[10 20 30 40 10 11 10 ] true ArrayListASDV[20 30 40 11 ] ArrayListASDV[20 30 11 ] java.lang.ClassCastException: Incompatible types: java.lang.Integer, java.lang.Double ArrayListASDV[20 30 11 ] java.lang.ClassCastException: Incompatible types: java.lang.Integer, withCode.A1 --------------------------------------- test retainAll(Collection) ArrayListASDV[30 ] --------------------------------------- test addAll(Collection) ArrayListASDV[30 1 2 3 4 ] --------------------------------------- test addAll(index, Collection) ArrayListASDV[30 1 100 200 300 2 3 4 ] BUILD SUCCESSFUL (total time: 0 seconds) ArrayListASDV.java /Users/ASDV2/Desktop/+slcc/+courses/F20/2520/MP6/src/noCode/ArrayListASDV.java package noCode; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.function.Consumer; /** * * @author ASDV2 */ public class ArrayListASDV implements Serializable, Cloneable, List { private E[] list; private int index;//the index to add at ( length of array) //private Class type; /** * Constructs an empty list with an initial capacity of three. * */ public ArrayListASDV() { list = (E[]) new Object[3]; index = 0; } /** * Constructs an empty list with the specified initial capacity. * * @param initialCapacity - the initial capacity of the list * @throws IllegalArgumentException - if the specified initial capacity is * negative */ public ArrayListASDV(int initialCapacity) { if (initialCapacity < 0) { throw new illegalargumentexception("initialcapacity id negative: " + initialcapacity); } list = (e[]) new object[initialcapacity]; index = 0; } /** * constructs a list containing the elements of the specified collection, in * the order they are returned by the collection's iterator. * * @param c - the collection whose elements are to be placed into this * @throws nullpointerexception - if the specified collection is null * * */ public arraylistasdv(collection c) { throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates. } /** * returns true if this collection changed as a result of the call. false if * this collection does not permit duplicates and already contains the * specified element. * * @param e - element whose presence in this collection is to be ensured * * @return true if this collection changed as a result of the call * @throws classcastexception - if the class of the specified element * prevents it from being added to this collection * @throws nullpointerexception - if the specified element is null and this * collection does not permit null elements * @throws illegalargumentexception - if some property of the element * prevents it from being added to this collection */ @override public boolean add(e e) { throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates. } /** * returns the number of elements in this list. * * @return the number of elements in this list. */ @override public int size() { return index; } @override public string tostring() { 0)="" {="" throw="" new="" illegalargumentexception("initialcapacity="" id="" negative:="" "="" +="" initialcapacity);="" }="" list="(E[])" new="" object[initialcapacity];="" index="0;" }="" **="" *="" constructs="" a="" list="" containing="" the="" elements="" of="" the="" specified="" collection,="" in="" *="" the="" order="" they="" are="" returned="" by="" the="" collection's="" iterator.="" *="" *="" @param="" c="" -="" the="" collection="" whose="" elements="" are="" to="" be="" placed="" into="" this="" *="" @throws="" nullpointerexception="" -="" if="" the="" specified="" collection="" is="" null="" *="" *="" */="" public="" arraylistasdv(collection="" c)="" {="" throw="" new="" unsupportedoperationexception("not="" supported="" yet.");="" to="" change="" body="" of="" generated="" methods,="" choose="" tools="" |="" templates.="" }="" **="" *="" returns="" true="" if="" this="" collection="" changed="" as="" a="" result="" of="" the="" call.="" false="" if="" *="" this="" collection="" does="" not="" permit="" duplicates="" and="" already="" contains="" the="" *="" specified="" element.="" *="" *="" @param="" e="" -="" element="" whose="" presence="" in="" this="" collection="" is="" to="" be="" ensured="" *="" *="" @return="" true="" if="" this="" collection="" changed="" as="" a="" result="" of="" the="" call="" *="" @throws="" classcastexception="" -="" if="" the="" class="" of="" the="" specified="" element="" *="" prevents="" it="" from="" being="" added="" to="" this="" collection="" *="" @throws="" nullpointerexception="" -="" if="" the="" specified="" element="" is="" null="" and="" this="" *="" collection="" does="" not="" permit="" null="" elements="" *="" @throws="" illegalargumentexception="" -="" if="" some="" property="" of="" the="" element="" *="" prevents="" it="" from="" being="" added="" to="" this="" collection="" */="" @override="" public="" boolean="" add(e="" e)="" {="" throw="" new="" unsupportedoperationexception("not="" supported="" yet.");="" to="" change="" body="" of="" generated="" methods,="" choose="" tools="" |="" templates.="" }="" **="" *="" returns="" the="" number="" of="" elements="" in="" this="" list.="" *="" *="" @return="" the="" number="" of="" elements="" in="" this="" list.="" */="" @override="" public="" int="" size()="" {="" return="" index;="" }="" @override="" public="" string="" tostring()="">
Answered 2 days AfterOct 12, 2021

Answer To: run: ------------------------------ java.lang.NullPointerException: null parameter test add...

Ramachandran answered on Oct 14 2021
121 Votes
Order-93530/original/noCode/ArrayListASDV.java
Order-93530/original/noCode/ArrayListASDV.java
package noCode;
import java.io.Serializable;
import java.util.*;
import java.util.function.Consumer;
/**
 * @author ASDV2
 */
public class ArrayListASDV
        implements Serializable, Cloneable, List {
    private E[] list;
    private int index;//the index to add at ( length of array)
    //private Class type;
    /**
     * Constructs an empty list with an initial capacity of three.
     */
    public ArrayListASDV() {
        list = (E[]) new Object[3];
        index = 0;
    }
    /**
     * Constructs an empty list with the specified initial capacity.
     *
     * @param initialCapacity - the initial capacity of the list
     * @throws IllegalArgumentException - if the specified initial capacity is
     *                                  negative
     */
    public ArrayListASDV(int initialCapacity) {
        if (initialCapacity < 0) {
            throw new IllegalArgumentException("initialCapacity id negative: " + initialCapacity);
        }
        list = (E[]) new Object[initialCapacity];
        index = 0;
    }
    /**
     * Constructs a list containing the elements of the specified collection, in
     * the order they are returned by the collection's iterator.
     *
     * @param c - the collection whose elements are to be placed into this
     * @throws NullPointerException - if the specified collection is null
     */
    public ArrayListASDV(Collection c) {
        if (c == null) {
            throw new NullPointerException("Input collection is null");
        }
        list = (E[]) new Object[c.size()];
        index = 0;
        for (E element : c) {
            list[index] = element;
            index++;
        }
    }
    /**
     * Returns true if this collection changed as a result of the call. false if
     * this collection does not permit duplicates and already contains the
     * specified element.
     *
     * @param e - element whose presence in this collection is to be ensured
     * @return true if this collection changed as a result of the call
     * @throws ClassC
astException       - if the class of the specified element
     *                                  prevents it from being added to this collection
     * @throws NullPointerException     - if the specified element is null and this
     *                                  collection does not permit null elements
     * @throws IllegalArgumentException - if some property of the element
     *                                  prevents it from being added to this collection
     */
    @Override
    public boolean add(E e) {
        if (e == null) {
            throw new NullPointerException("null parameter");
        }
        if (size() >= list.length) {
            list = Arrays.copyOf(list, index + index / 2);
        }
        list[index] = e;
        index++;
        return true;
    }
    /**
     * Returns the number of elements in this list.
     *
     * @return the number of elements in this list.
     */
    @Override
    public int size() {
        return index;
    }
    @Override
    public String toString() {
        String s = "ArrayListASDV[";
        for (int i = 0; i < index; ++i) {
            s += list[i] + " ";
        }
        s += "]";
        return s;
    }
    /**
     * Returns true if this list contains no elements.
     *
     * @return true if this list contains no elements
     */
    @Override
    public boolean isEmpty() {
        return this.index == 0;
    }
    /**
     * Returns true if this list contains the specified element. More formally,
     * returns true if and only if this list contains at least one element e
     * such that (o==null ? e==null : o.equals(e)).
     *
     * @param o - element whose presence in this list is to be tested
     * @return true if this list contains the specified element
     */
    @Override
    public boolean contains(Object o) {
        for (E e : list) {
            if ((o == null && e == null) || (o != null && o.equals(e))) {
                return true;
            }
        }
        return false;
    }
    /**
     * Returns an array containing all of the elements in this list in proper
     * sequence (from first to last element). The returned array will be "safe"
     * in that no references to it are maintained by this list. (In other words,
     * this method must allocate a new array). The caller is thus free to modify
     * the returned array. This method acts as bridge between array-based and
     * collection-based APIs. Returns: an array containing all of the elements
     * in this list in proper sequence
     *
     * @return an array containing all of the elements in this list in proper
     * sequence
     */
    @Override
    public Object[] toArray() {
        return Arrays.copyOf(list, index);
    }
    /**
     * Removes the first occurrence of the specified element from this list, if
     * it is present. If the list does not contain the element, it is unchanged.
     * More formally, removes the element with the lowest index i such that
     * (o==null ? get(i)==null : o.equals(get(i))) (if such an element exists).
     * Returns true if this list contained the specified element (or
     * equivalently, if this list changed as a result of the call).
     *
     * @param o - element to be removed from this list, if present
     * @return true if this list contained the specified element
     */
    @Override
    public boolean remove(Object o) {
        boolean result = false;
        for (int tempIndex = 0; tempIndex < index; tempIndex++) {
            if ((o == null && list[tempIndex] == null) || (o != null && o.equals(list[tempIndex]))) {
                result = true;
            }
            if (result) {
                list[tempIndex] = list[tempIndex + 1];
            }
        }
        if (result) {
            index--;
        }
        return result;
    }
    /**
     * Removes all of the elements from this list. The list will be empty after
     * this call returns. Note: Traverse the array and set all of its elements
     * to null. Set its index to zero.
     */
    @Override
    public void clear() {
        for (int tempIndex = 0; tempIndex < index; tempIndex++) {
            list[tempIndex] = null;
        }
        index = 0;
    }
    /**
     * Returns the element at the specified position in this list.
     *
     * @param index of the element to return
     * @return the element at the specified position in this list
     * @throws IndexOutOfBoundsException - if the index is out of range (index
     *                                   GE 0 || index GE size())
     */
    @Override
    public E get(int index) {
        checkIndex(index);
        return list[index];
    }
    /**
     * Replaces the element at the specified position in this list with the
     * specified element.
     *
     * @param index   - index of the element to replace
     * @param element - element to be stored at the specified position
     * @return the element previously at the specified position
     * @throws IndexOutOfBoundsException - if the index is out of range (index
     *                                   GE 0 || index GE size())
     */
    @Override
    public E set(int index, E element) {
        checkIndex(index);
        E prev = list[index];
        list[index] = element;
        return prev;
    }
    /**
     * Inserts the specified element at the specified position in this list.
     * Shifts the element currently at that position (if any) and any subsequent
     * elements to the right (adds one to their indices).
     *
     * @param index   - index at which the specified element is to be inserted
     *                element
     * @param element -     element to be inserted
     * @throws NullPointerException      - if the specified element is null and this
     *                                   collection does not permit null elements
     * @throws IndexOutOfBoundsException - if the index is out of range (index
     *                                   GE 0 || index GE size())
     */
    @Override
    public void add(int index, E element) {
        if (element == null) {
            throw new NullPointerException("null parameter");
        }
        checkIndex(index);
        if (size() >= list.length) {
            list = Arrays.copyOf(list, size() + size() / 2);
        }
        int tempIndex = this.index;
        while (tempIndex > index) {
            list[tempIndex] = list[tempIndex - 1];
            tempIndex--;
        }
        list[index] = element;
        this.index++;
    }
    /**
     * Removes the element at the specified position in this list. Shifts any
     * subsequent elements to the left (subtracts one from their indices).
     *
     * @param index - the index of the element to be removed
     * @return the element that was removed from the list
     * @throws IndexOutOfBoundsException - if the index is out of range (index
     *                                   GE 0 || index GE size())
     */
    @Override
    public E remove(int index) {
        checkIndex(index);
        E e = list[index];
        if (size() - (index + 1) >= 0)
            System.arraycopy(list, index + 1, list, index , size() - (index + 1));
        list[--this.index] = null;
        return e;
    }
    private void checkIndex(int index) {
        if (index < 0 || index > size()) {
            throw new IndexOutOfBoundsException(index + " out of bounds");
        }
    }
    /**
     * Returns the index of the first occurrence of the specified element in
     * this list, or -1 if this list does not contain the element. More
     * formally, returns the lowest index i such that
     * (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such
     * index. Parameters:
     *
     * @param o - element to search for
     * @return the index of the first occurrence of the specified element in
     * this list, or -1 if this list does not contain the element
     */
    @Override
    public int indexOf(Object o) {
        for (int tempIndex = 0; tempIndex < this.index; tempIndex++) {
            if ((o == null && list[tempIndex] == null) || (o != null && o.equals(list[tempIndex]))) {
                return tempIndex;
            }
        }
        return -1;
    }
    /**
     * Returns the index of the last occurrence of the specified element in this
     * list, or -1 if this list does not contain the element. More formally,
     * returns the highest index i such that
     * (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such
     * index. Parameters:
     *
     * @param o - element to search for
     * @return the index of the last occurrence of the specified element in this
     * list, or -1 if this list does not contain the element
     */
    @Override
    public int lastIndexOf(Object o) {
        int res = -1;
        for (int tempIndex = 0; tempIndex < this.index; tempIndex++) {
            if ((o == null && list[tempIndex] == null) || (o != null && o.equals(list[tempIndex]))) {
                res = tempIndex;
            }
        }
        return res;
    }
    /**
     * Returns a view of the portion of this list between the specified
     * fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex
     * are equal, the returned list is empty.) The returned list is backed by
     * this list, so non-structural changes in the returned list are reflected
     * in this list, and vice-versa. The returned list supports all of the
     * optional list operations. This method eliminates the need for explicit
     * range operations (of the sort that commonly exist for arrays). Any
     * operation that expects a list can be used as a range operation by passing
     * a subList view instead of a whole list. For example, the following idiom
     * removes a range of elements from a list: list.subList(from, to).clear();
     * 


     * Similar idioms may be constructed for ArrayList.indexOf(Object) and
     * ArrayList.lastIndexOf(Object), and all of the algorithms in the
     * Collections class can be applied to a subList. The semantics of the list
     * returned by this method become undefined if the backing list (i.e., this
     * list) is structurally modified in any way other than via the returned
     * list. (Structural modifications are those that change the size of this
     * list, or otherwise perturb it in such a fashion that iterations in
     * progress may yield incorrect results.)
     *
     * @param fromIndex - low endpoint (inclusive) of the subList
     * @param toIndex   - high endpoint (exclusive) of the subList
     * @return a view of the specified range within this list
     * @throws IndexOutOfBoundsException - for an illegal endpoint index value
     *                                   (fromIndex LE 0 || toIndex > size || fromIndex > toIndex)
     * @throws IllegalArgumentException  - if the endpoint indices are out of
     *                                   order (fromIndex > toIndex)
     */
    @Override
    public List subList(int fromIndex, int toIndex) {
        if (fromIndex < 0 || toIndex > size() || fromIndex > toIndex) {
            throw new IndexOutOfBoundsException(fromIndex + " is out of bounds");
        }
        ArrayListASDV subList = new ArrayListASDV<>();
        for (int tempIndex = fromIndex; tempIndex < toIndex; tempIndex++) {
            subList.add(list[tempIndex]);
        }
        return subList;
    }
    /**
     * Returns an array containing all of the elements in this list in proper
     * sequence (from first to last element); the runtime type of the returned
     * array is that of the specified array. If the list fits in the specified
     * array, it is returned therein. Otherwise, a new array is allocated with
     * the runtime type of the specified array and the size of this list. If the
     * list fits in the specified array with room to spare (i.e., the array has
     * more elements than the list), the element in the array immediately
     * following the end of the collection is set to null. (This is useful in
     * determining the length of the list only if the caller knows that the list
     * does not contain any null elements.)
     *
     * @param a - the array into which the elements of the list are to be
     *          stored, if it is big enough; otherwise, a new array of the same runtime
     *          type is allocated for this purpose.
     * @return an array containing the elements of the list
     * @throws ArrayStoreException  - if the runtime type of the specified array
     *                              is not a supertype of the runtime type of every element in this list
     * @throws NullPointerException - if the specified array is null
     */
    @Override
    public  T[] toArray(T[] a) {
        Class clazz = a.getClass();
        //>length of a is too small
        if (a.length < index)
        // Make a new array of a's runtime type
        {
            return (T[]) Arrays.copyOf(this.list,
                    index,
                    a.getClass());
        }
        //>length of a is good
        System.arraycopy(this.list, 0, a, 0, index);
        //>length of a is greater than this list set nulls
        if (a.length > index) {
            for (int i = index; i < a.length; ++i) {
                a[i] = null;
            }
        }
        return a;
    }
    @Override
    public Iterator iterator() {
        return listIterator(0);
    }
    /**
     * Returns a list iterator over the elements in this list (in proper
     * sequence). The returned list iterator is fail-fast.
     *
     * @return a list iterator over the elements in this list (in proper
     * sequence
     */
    @Override
    public ListIterator listIterator() {
        return listIterator(0);
    }
    @Override
    public ListIterator listIterator(int index) {
        ListIterator it = new ListIterator() {
            int current = index;
            /**
             * Returns true if this list iterator has more elements when
             * traversing the list in the forward direction. (In other words,
             * returns true if ListIterator.next would return an element rather
             * than throwing an exception.)
             *
             * @return true if the list iterator has more elements when
             * traversing the list in the forward direction
             */
            @Override
            public boolean hasNext() {
                return current < size();
            }
            /**
             * Returns the next element in the list and advances the cursor
             * position. This method may be called repeatedly to iterate through
             * the list, or intermixed with calls to ListIterator.previous to go
             * back and forth. (Note that alternating calls to next and previous
             * will return the same element repeatedly.)
             *
             * @return the next element in the list
             * @throws NoSuchElementException - if the iteration has no next
             * element
             */
            @Override
            public E next() {
                if (!hasNext()) {
                    throw new NoSuchElementException("no element");
                }
                E e = list[current];
                current++;
                return e;
            }
            @Override
            public boolean hasPrevious() {
                return current != 0;
            }
            @Override
            public E previous() {
                if (!hasPrevious()) {
                    throw new NoSuchElementException("no element");
                }
                current--;
                return list[current];
            }
            /**
             * Returns the index of the element that would be returned by a
             * subsequent call to next(). (Returns list size if the list
             * iterator is at the end of the list.)
             *
             * @return the index of the element that would be returned by a
             * subsequent call to next, or list size if the list iterator is at
             * the end of the list
             */
            @Override
            public int nextIndex() {
                return current;
            }
            /**
             * Returns the index of the element that would be returned by a
             * subsequent call to previous(). (Returns -1 if the list iterator
             * is at the beginning of the list.)
             *
             * @return the index of the element that would be returned by a
             * subsequent call to previous, or -1 if the list iterator is at the
             * beginning of the list
             */
            @Override
            public int previousIndex() {
                return current - 1;
            }
            @Override
            public void forEachRemaining(Consumer action) {
                while (current < size()) {
                    action.accept(list[current]);
                    current++;
                }
            }
            @Override
            public void remove() {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            @Override
            public void set(E e) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            @Override
            public void add(E e) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        };
        return it;
    }
    /**
     * Returns true if this collection contains all of the elements in the
     * specified collection.
     * 


     * Parameters: c - collection to be checked for containment in this
     * collection Returns: true if this collection contains all of the elements
     * in the specified collection Throws: ClassCastException - if the types of
     * one or more elements in the specified collection are incompatible with
     * this collection (optional) NullPointerException - if the specified
     * collection contains one or more null elements and this collection does
     * not permit null elements (optional), or if the specified collection is
     * null.
     *
     * @param c - collection to be checked for containment in this collection
     * @return true if this collection contains all of the elements in the
     * specified collection.
     * @throws ClassCastException - if the types of one or more elements in the
     *                            specified collection are incompatible with this collection
     */
    @Override
    public boolean containsAll(Collection c) {
        boolean res = true;
        for (Object o : c) {
            if (!contains(o)) {
                res = false;
                break;
            }
        }
        return res;
    }
    @Override
    public boolean addAll(Collection c) {
        if (c == null) {
            throw new NullPointerException("null parameter");
        }
        if (size() + c.size() >= list.length) {
            list = Arrays.copyOf(list, size() + c.size());
        }
        for (E e : c) {
            list[index]...

SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here