@Test public void testPeekLast() { assertEquals("Peek last should return null if empty", null, seq.peekLast()); seq.append("a"); assertEquals("Peek last returns wrong value for 1 element", "a", seq.peekLast()); seq.append("b"); assertEquals("Peek last returns wrong value for 2 elements", "b", seq.peekLast()); seq.append("x"); assertEquals("Peek last returns wrong value for multiple elements","x", seq.peekLast()); seq.append("z"); seq.prepend("D"); seq.prepend("C"); seq.last(); seq.last(); seq.last(); seq.last(); seq.last(); assertEquals("Peek doesn't wrap past zero", "C", seq.peekLast()); }
@Override public Object peekLast() { if (rear==0){ if (backingArray[backingArray.length-1]==null){ return backingArray[rear]; } else{ return backingArray[backingArray.length-1]; } } return backingArray[rear-1]; }
CircularArraySequence implements Sequence { @Override public Object peekLast() { if (rear==0){ if (backingArray[backingArray.length-1]==null){ return backingArray[rear]; } else{ return backingArray[backingArray.length-1]; } } return backingArray[rear-1]; } }
CircularArraySequence implements Sequence { @Override public Object peekLast() { if (rear==0){ if (backingArray[backingArray.length-1]==null){ return backingArray[rear]; } else{ return backingArray[backingArray.length-1]; } } return backingArray[rear-1]; } CircularArraySequence(int size);  CircularArraySequence(CircularArraySequence<T> seq); }
CircularArraySequence implements Sequence { @Override public Object peekLast() { if (rear==0){ if (backingArray[backingArray.length-1]==null){ return backingArray[rear]; } else{ return backingArray[backingArray.length-1]; } } return backingArray[rear-1]; } 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 peekLast() { if (rear==0){ if (backingArray[backingArray.length-1]==null){ return backingArray[rear]; } else{ return backingArray[backingArray.length-1]; } } return backingArray[rear-1]; } 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();  }