Question
***ONLY POWERSET ITERATOR NOTHING ELSE import java.util.Iterator; import java.util.NoSuchElementException; /** * ArraySet.java. * * Provides an implementation of the Set interface using an * array
***ONLY POWERSET ITERATOR NOTHING ELSE
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* ArraySet.java.
*
* Provides an implementation of the Set interface using an
* array as the underlying data structure. Values in the array
* are kept in ascending natural order and, where possible,
* methods take advantage of this. Many of the methods with parameters
* of type ArraySet are specifically designed to take advantage
* of the ordered array implementation.
*
*/
public class ArraySet> implements Set {
////////////////////////////////////////////
// DO NOT CHANGE THE FOLLOWING TWO FIELDS //
////////////////////////////////////////////
T[] elements;
int size;
////////////////////////////////////
// DO NOT CHANGE THIS CONSTRUCTOR //
////////////////////////////////////
/**
* Instantiates an empty set.
*/
@SuppressWarnings("unchecked")
public ArraySet() {
elements = (T[]) new Comparable[1];
size = 0;
}
///////////////////////////////////
// DO NOT CHANGE THE SIZE METHOD //
///////////////////////////////////
/**
* Returns the current size of this collection.
*
* @return the number of elements in this collection.
*/
@Override
public int size() {
return size;
}
//////////////////////////////////////
// DO NOT CHANGE THE ISEMPTY METHOD //
//////////////////////////////////////
/**
* Tests to see if this collection is empty.
*
* @return true if this collection contains no elements,
* false otherwise.
*/
@Override
public boolean isEmpty() {
return size == 0;
}
///////////////////////////////////////
// DO NOT CHANGE THE TOSTRING METHOD //
///////////////////////////////////////
/**
* Return a string representation of this ArraySet.
*
* @return a string representation of this ArraySet
*/
@Override
public String toString() {
if (isEmpty()) {
return "[]";
}
StringBuilder result = new StringBuilder();
result.append("[");
for (T element : this) {
result.append(element + ", ");
}
result.delete(result.length() - 2, result.length());
result.append("]");
return result.toString();
}
/**
* Ensures the collection contains the specified element. Elements are
* maintained in ascending natural order at all times. Neither
duplicate nor
* null values are allowed.
*
* @param element The element whose presence is to be ensured.
* @return true if collection is changed, false otherwise.
*/
@Override
public boolean add(T element) {
return false;
}
/**
* Ensures the collection does not contain the specified element.
* If the specified element is present, this method removes it
* from the collection. Elements are maintained in ascending natural
* order at all times.
*
* @param element The element to be removed.
* @return true if collection is changed, false otherwise.
*/
@Override
public boolean remove(T element) {
return false;
}
/**
* Searches for specified element in this collection.
*
* @param element The element whose presence in this collection
* is to be tested.
* @return true if this collection contains the specified element,
* false otherwise.
*/
@Override
public boolean contains(T element) {
return false;
}
/**
* Tests for equality between this set and the parameter set.
* Returns true if this set contains exactly the same elements
* as the parameter set, regardless of order.
*
* @return true if this set contains exactly the same elements
* as the parameter set, false otherwise
*/
@Override
public boolean equals(Set s) {
return false;
}
/**
* Tests for equality between this set and the parameter set.
* Returns true if this set contains exactly the same elements
* as the parameter set, regardless of order.
*
* @return true if this set contains exactly the same elements
* as the parameter set, false otherwise
*/
public boolean equals(ArraySet s) {
return false;
}
/**
* Returns a set that is the union of this set and the parameter set.
*
* @return a set that contains all the elements of this set and
* the parameter set
*/
@Override
public Set union(Set s) {
return null;
}
/**
* Returns a set that is the union of this set and the parameter set.
*
* @return a set that contains all the elements of this set and
* the parameter set
*/
public Set union(ArraySet s) {
return null;
}
/**
* Returns a set that is the intersection of this set
* and the parameter set.
*
* @return a set that contains elements that are in both
* this set and the parameter set
*/
@Override
public Set intersection(Set s) {
return null;
}
/**
* Returns a set that is the intersection of this set and
* the parameter set.
*
* @return a set that contains elements that are in both
* this set and the parameter set
*/
public Set intersection(ArraySet s) {
return null;
}
/**
* Returns a set that is the complement of this set and
* the parameter set.
*
* @return a set that contains elements that are in this
* set but not the parameter set
*/
@Override
public Set complement(Set s) {
return null;
}
/**
* Returns a set that is the complement of this set and
* the parameter set.
*
* @return a set that contains elements that are in this
* set but not the parameter set
*/
public Set complement(ArraySet s) {
return null;
}
/**
* Returns an iterator over the elements in this ArraySet.
* No specific order can be assumed.
*
* @return an iterator over the elements in this ArraySet
*/
@Override
public Iterator iterator() {
// ALMOST ALL THE TESTS DEPEND ON THIS METHOD WORKING CORRECTLY.
// MAKE SURE YOU GET THIS ONE WORKING FIRST.
// HINT: JUST USE THE SAME CODE/STRATEGY AS THE ARRAYBAG CLASS
// FROM LECTURE. THE ONLY DIFFERENCE IS THAT YOU'LL NEED THE
// ARRAYITERATOR CLASS TO BE NESTED, NOT TOP-LEVEL.
return null;
}
/**
* Returns an iterator over the elements in this ArraySet.
* The elements are returned in descending order.
*
* @return an iterator over the elements in this ArraySet
*/
public Iterator descendingIterator() {
return null;
}
/**
* Returns an iterator over the members of the power set
* of this ArraySet. No specific order can be assumed.
*
* @return an iterator over members of the power set
*/
public Iterator> powerSetIterator() {
return null;
}
}
***JUST POWERSET ITERATOR METHOD NOTHING ELSE***
* Returns an iterator over the members of the power set * of this ArraySet. No specific order can be assumed. return an iterator over members of the power set public IteratorStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started