@Test public void testHead() { assertTrue("New sequence not reporting its empty", seq.isEmpty()); assertEquals("Head of the new sequence not null", null, seq.head()); seq.append("a"); assertEquals("Head returned incorrect when one element", "a", seq.head()); assertEquals("Head returned incorrect when no element", null, seq.head()); seq.append("s"); seq.append("r"); seq.append("t"); seq.append("i"); assertEquals("Head returned incorrect value after several appends", "s", seq.head()); seq.last(); assertEquals("After removing last element, the head changed", "r", seq.head()); }
@Override public Object head() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); T firstObj = null; if (front == 0 || backingArray[front]==null){ if (backingArray[front]==null){ firstObj = null; } else{ firstObj = tempSequence.backingArray[front]; backingArray[front] = null; front+=1; fillCount-=1; } } else if (front == backingArray.length-1){ firstObj = tempSequence.backingArray[backingArray.length-1]; backingArray[backingArray.length-1] = null; front = 0; fillCount-=1; } else{ firstObj = tempSequence.backingArray[front]; backingArray[front] = null; front+=1; fillCount-=1; } return firstObj; }
CircularArraySequence implements Sequence { @Override public Object head() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); T firstObj = null; if (front == 0 || backingArray[front]==null){ if (backingArray[front]==null){ firstObj = null; } else{ firstObj = tempSequence.backingArray[front]; backingArray[front] = null; front+=1; fillCount-=1; } } else if (front == backingArray.length-1){ firstObj = tempSequence.backingArray[backingArray.length-1]; backingArray[backingArray.length-1] = null; front = 0; fillCount-=1; } else{ firstObj = tempSequence.backingArray[front]; backingArray[front] = null; front+=1; fillCount-=1; } return firstObj; } }
CircularArraySequence implements Sequence { @Override public Object head() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); T firstObj = null; if (front == 0 || backingArray[front]==null){ if (backingArray[front]==null){ firstObj = null; } else{ firstObj = tempSequence.backingArray[front]; backingArray[front] = null; front+=1; fillCount-=1; } } else if (front == backingArray.length-1){ firstObj = tempSequence.backingArray[backingArray.length-1]; backingArray[backingArray.length-1] = null; front = 0; fillCount-=1; } else{ firstObj = tempSequence.backingArray[front]; backingArray[front] = null; front+=1; fillCount-=1; } return firstObj; } CircularArraySequence(int size);  CircularArraySequence(CircularArraySequence<T> seq); }
CircularArraySequence implements Sequence { @Override public Object head() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); T firstObj = null; if (front == 0 || backingArray[front]==null){ if (backingArray[front]==null){ firstObj = null; } else{ firstObj = tempSequence.backingArray[front]; backingArray[front] = null; front+=1; fillCount-=1; } } else if (front == backingArray.length-1){ firstObj = tempSequence.backingArray[backingArray.length-1]; backingArray[backingArray.length-1] = null; front = 0; fillCount-=1; } else{ firstObj = tempSequence.backingArray[front]; backingArray[front] = null; front+=1; fillCount-=1; } return firstObj; } CircularArraySequence(int size);  CircularArraySequence(CircularArraySequence<T> seq); @Override Object head(); @Override Object last(); @Override Sequence front(); @Override Sequence tail(); @Override Sequence<T> concat(Sequence seq); @Override boolean contains(Sequence subseq); @Override boolean contains(Object element); @Override void append(Object element); @Override void prepend(Object element); @Override boolean isEmpty(); @Override Object peekHead(); @Override Object peekLast(); @Override boolean equals(Sequence seq); @Override int length(); @Override Iterator<T> iterator(); String toString(); }
CircularArraySequence implements Sequence { @Override public Object head() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); T firstObj = null; if (front == 0 || backingArray[front]==null){ if (backingArray[front]==null){ firstObj = null; } else{ firstObj = tempSequence.backingArray[front]; backingArray[front] = null; front+=1; fillCount-=1; } } else if (front == backingArray.length-1){ firstObj = tempSequence.backingArray[backingArray.length-1]; backingArray[backingArray.length-1] = null; front = 0; fillCount-=1; } else{ firstObj = tempSequence.backingArray[front]; backingArray[front] = null; front+=1; fillCount-=1; } return firstObj; } CircularArraySequence(int size);  CircularArraySequence(CircularArraySequence<T> seq); @Override Object head(); @Override Object last(); @Override Sequence front(); @Override Sequence tail(); @Override Sequence<T> concat(Sequence seq); @Override boolean contains(Sequence subseq); @Override boolean contains(Object element); @Override void append(Object element); @Override void prepend(Object element); @Override boolean isEmpty(); @Override Object peekHead(); @Override Object peekLast(); @Override boolean equals(Sequence seq); @Override int length(); @Override Iterator<T> iterator(); String toString();  }