import java.util.NoSuchElementException; public class GArrayQueue<E> implements GQueue<E>, Cloneable { //Data protected Object[] array; //Elements protected int begin; //First element protected int end; //Last element protected int number; //Number of elements //Constructors public GArrayQueue() { this(10); } public GArrayQueue(int n){ ... } @SuppressWarnings("unchecked") public GArrayQueue(Object[] data) { this(data.length + 10); for(int i = 0; i < data.length; i++) add((E)data[i]); } //GQueue methods implementation public boolean isEmpty(){ return number == 0; } public boolean add(E x) throws IllegalStateException { if(isFull()) throw new IllegalStateException(); ... return true; } @SuppressWarnings("unchecked") public E element() throws NoSuchElementException { if(isEmpty()) throw new NoSuchElementException(); return (E)array[begin]; } public E remove() throws NoSuchElementException { E result = this.element(); ... return result; } public boolean offer(E e) { try { this.add(e); return true; }catch(IllegalStateException ex) { return false; } } public E peek() { try { return this.element(); }catch(NoSuchElementException e) { return null; } } public E poll() { try { return this.remove(); }catch(NoSuchElementException e) { return null; } } public Object[] toArray() { Object[] result = new Object[number]; ... return result; } //Other methods public boolean isFull(){ return number >= array.length; } public int capacity() { return array.length; } //Override method @SuppressWarnings("unchecked") public Object clone() { GArrayQueue<E> copy = null; try { copy = (GArrayQueue<E>)super.clone(); copy.array = this.array.clone(); copy.begin = this.begin; copy.end = this.end; copy.number = this.number; } catch (java.lang.CloneNotSupportedException e) {} return copy; } }