@Test public void testTail() { Sequence<String> seq2 = seq.tail(); assertTrue("empty sequence tail should empty seq", seq2.isEmpty()); seq.append("a"); seq.append("b"); seq.append("c"); seq.append("d"); seq.append("e"); Sequence<String> seq1 = seq.tail(); assertEquals("Length of tail sequence incorrect", 4 , seq1.length()); assertEquals("Head of tail sequence incorrect", "b", seq1.peekHead()); assertEquals("Last element of tail sequence incorrect", "e", seq1.peekLast()); assertEquals("Length of original sequence changed when taking tail", 5, seq.length()); assertEquals("Original sequence head changed when taking tail", "a", seq.peekHead()); assertEquals("Original sequence last changed when taking tail", "e", seq.peekLast()); }
@Override public Sequence tail() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); if (backingArray[front]!=null){ tempSequence.backingArray[front] = null; tempSequence.fillCount-=1; if (front == backingArray.length-1){ tempSequence.front = 0; } else{ tempSequence.front+=1; } } return tempSequence; }
CircularArraySequence implements Sequence { @Override public Sequence tail() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); if (backingArray[front]!=null){ tempSequence.backingArray[front] = null; tempSequence.fillCount-=1; if (front == backingArray.length-1){ tempSequence.front = 0; } else{ tempSequence.front+=1; } } return tempSequence; } }
CircularArraySequence implements Sequence { @Override public Sequence tail() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); if (backingArray[front]!=null){ tempSequence.backingArray[front] = null; tempSequence.fillCount-=1; if (front == backingArray.length-1){ tempSequence.front = 0; } else{ tempSequence.front+=1; } } return tempSequence; } CircularArraySequence(int size);  CircularArraySequence(CircularArraySequence<T> seq); }
CircularArraySequence implements Sequence { @Override public Sequence tail() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); if (backingArray[front]!=null){ tempSequence.backingArray[front] = null; tempSequence.fillCount-=1; if (front == backingArray.length-1){ tempSequence.front = 0; } else{ tempSequence.front+=1; } } return tempSequence; } 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 Sequence tail() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); if (backingArray[front]!=null){ tempSequence.backingArray[front] = null; tempSequence.fillCount-=1; if (front == backingArray.length-1){ tempSequence.front = 0; } else{ tempSequence.front+=1; } } return tempSequence; } 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();  }