@Test public void testFront() { Sequence<String> seq2 = seq.front(); assertTrue("Front of empty seq did not return empty", seq2.isEmpty()); seq.append("a"); seq.append("b"); seq.append("c"); seq.append("d"); seq.append("e"); Sequence<String> seq1 = seq.front(); assertEquals("Length of the sequence after taking front was wrong", 4 , seq1.length()); assertEquals("Head of the front sequence wrong", "a", seq1.peekHead()); assertEquals("Last element of front sequence wrong", "d", seq1.peekLast()); assertEquals("Original sequence length wrong", 5, seq.length()); assertEquals("Original sequence head wrong = don't modify the original when taking front", "a", seq.peekHead()); assertEquals("Original sequence last element wrong, don't modify the original", "e", seq.peekLast()); }
@Override public Sequence front() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); boolean halt = false; int index = front; while (halt == false){ if (index == backingArray.length){ index = 0; } if (index == rear){ halt = true; } if(backingArray[index] == null){ if (index == 0){ tempSequence.backingArray[backingArray.length-1] = null; tempSequence.fillCount -=1; tempSequence.rear = tempSequence.backingArray.length-1; } else{ tempSequence.backingArray[index-1] = null; tempSequence.fillCount-=1; tempSequence.rear-=1; } } index+=1; } return tempSequence; }
CircularArraySequence implements Sequence { @Override public Sequence front() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); boolean halt = false; int index = front; while (halt == false){ if (index == backingArray.length){ index = 0; } if (index == rear){ halt = true; } if(backingArray[index] == null){ if (index == 0){ tempSequence.backingArray[backingArray.length-1] = null; tempSequence.fillCount -=1; tempSequence.rear = tempSequence.backingArray.length-1; } else{ tempSequence.backingArray[index-1] = null; tempSequence.fillCount-=1; tempSequence.rear-=1; } } index+=1; } return tempSequence; } }
CircularArraySequence implements Sequence { @Override public Sequence front() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); boolean halt = false; int index = front; while (halt == false){ if (index == backingArray.length){ index = 0; } if (index == rear){ halt = true; } if(backingArray[index] == null){ if (index == 0){ tempSequence.backingArray[backingArray.length-1] = null; tempSequence.fillCount -=1; tempSequence.rear = tempSequence.backingArray.length-1; } else{ tempSequence.backingArray[index-1] = null; tempSequence.fillCount-=1; tempSequence.rear-=1; } } index+=1; } return tempSequence; } CircularArraySequence(int size);  CircularArraySequence(CircularArraySequence<T> seq); }
CircularArraySequence implements Sequence { @Override public Sequence front() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); boolean halt = false; int index = front; while (halt == false){ if (index == backingArray.length){ index = 0; } if (index == rear){ halt = true; } if(backingArray[index] == null){ if (index == 0){ tempSequence.backingArray[backingArray.length-1] = null; tempSequence.fillCount -=1; tempSequence.rear = tempSequence.backingArray.length-1; } else{ tempSequence.backingArray[index-1] = null; tempSequence.fillCount-=1; tempSequence.rear-=1; } } index+=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 front() { CircularArraySequence<T> tempSequence = new CircularArraySequence<T>(this); boolean halt = false; int index = front; while (halt == false){ if (index == backingArray.length){ index = 0; } if (index == rear){ halt = true; } if(backingArray[index] == null){ if (index == 0){ tempSequence.backingArray[backingArray.length-1] = null; tempSequence.fillCount -=1; tempSequence.rear = tempSequence.backingArray.length-1; } else{ tempSequence.backingArray[index-1] = null; tempSequence.fillCount-=1; tempSequence.rear-=1; } } index+=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();  }