1 /* 2 * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package test.java.util.SequencedCollection; 25 26 import java.util.*; 27 28 /** 29 * A complete Deque implementation that inherits the reversed() method 30 * from SequencedCollection. Useful for testing ReverseOrderDequeView. 31 * Underlying implementation provided by ArrayDeque. 32 */ 33 public class SimpleDeque<E> implements Deque<E> { 34 35 final Deque<E> deque; 36 SimpleDeque()37 public SimpleDeque() { 38 deque = new ArrayDeque<>(); 39 } 40 SimpleDeque(Collection<? extends E> c)41 public SimpleDeque(Collection<? extends E> c) { 42 deque = new ArrayDeque<>(c); 43 } 44 45 // ========== Object ========== 46 equals(Object o)47 public boolean equals(Object o) { 48 return deque.equals(o); 49 } 50 hashCode()51 public int hashCode() { 52 return deque.hashCode(); 53 } 54 toString()55 public String toString() { 56 return deque.toString(); 57 } 58 59 // ========== Collection ========== 60 add(E e)61 public boolean add(E e) { 62 return deque.add(e); 63 } 64 addAll(Collection<? extends E> c)65 public boolean addAll(Collection<? extends E> c) { 66 return deque.addAll(c); 67 } 68 clear()69 public void clear() { 70 deque.clear(); 71 } 72 contains(Object o)73 public boolean contains(Object o) { 74 return deque.contains(o); 75 } 76 containsAll(Collection<?> c)77 public boolean containsAll(Collection<?> c) { 78 return deque.containsAll(c); 79 } 80 isEmpty()81 public boolean isEmpty() { 82 return deque.isEmpty(); 83 } 84 iterator()85 public Iterator<E> iterator() { 86 return deque.iterator(); 87 } 88 remove(Object o)89 public boolean remove(Object o) { 90 return deque.remove(o); 91 } 92 removeAll(Collection<?> c)93 public boolean removeAll(Collection<?> c) { 94 return deque.removeAll(c); 95 } 96 retainAll(Collection<?> c)97 public boolean retainAll(Collection<?> c) { 98 return deque.retainAll(c); 99 } 100 size()101 public int size() { 102 return deque.size(); 103 } 104 toArray()105 public Object[] toArray() { 106 return deque.toArray(); 107 } 108 toArray(T[] a)109 public <T> T[] toArray(T[] a) { 110 return deque.toArray(a); 111 } 112 113 // ========== Deque ========== 114 addFirst(E e)115 public void addFirst(E e) { 116 deque.addFirst(e); 117 } 118 addLast(E e)119 public void addLast(E e) { 120 deque.addLast(e); 121 } 122 offerFirst(E e)123 public boolean offerFirst(E e) { 124 return deque.offerFirst(e); 125 } 126 offerLast(E e)127 public boolean offerLast(E e) { 128 return deque.offerLast(e); 129 } 130 removeFirst()131 public E removeFirst() { 132 return deque.removeFirst(); 133 } 134 removeLast()135 public E removeLast() { 136 return deque.removeLast(); 137 } 138 pollFirst()139 public E pollFirst() { 140 return deque.pollFirst(); 141 } 142 pollLast()143 public E pollLast() { 144 return deque.pollLast(); 145 } 146 getFirst()147 public E getFirst() { 148 return deque.getFirst(); 149 } 150 getLast()151 public E getLast() { 152 return deque.getLast(); 153 } 154 peekFirst()155 public E peekFirst() { 156 return deque.peekFirst(); 157 } 158 peekLast()159 public E peekLast() { 160 return deque.peekLast(); 161 } 162 removeFirstOccurrence(Object o)163 public boolean removeFirstOccurrence(Object o) { 164 return deque.removeFirstOccurrence(o); 165 } 166 removeLastOccurrence(Object o)167 public boolean removeLastOccurrence(Object o) { 168 return deque.removeLastOccurrence(o); 169 } 170 offer(E e)171 public boolean offer(E e) { 172 return deque.offer(e); 173 } 174 remove()175 public E remove() { 176 return deque.remove(); 177 } 178 poll()179 public E poll() { 180 return deque.poll(); 181 } 182 element()183 public E element() { 184 return deque.element(); 185 } 186 peek()187 public E peek() { 188 return deque.peek(); 189 } 190 push(E e)191 public void push(E e) { 192 deque.push(e); 193 } 194 pop()195 public E pop() { 196 return deque.pop(); 197 } 198 descendingIterator()199 public Iterator<E> descendingIterator() { 200 return deque.descendingIterator(); 201 } 202 } 203