7 |
|
import java.io.Serializable; |
8 |
|
import java.util.function.Consumer; |
9 |
|
import java.util.stream.Stream; |
10 |
– |
import java.util.stream.Streams; |
10 |
|
|
11 |
|
/** |
12 |
|
* Resizable-array implementation of the {@link Deque} interface. Array |
315 |
|
* @return {@code true} if the deque contained the specified element |
316 |
|
*/ |
317 |
|
public boolean removeFirstOccurrence(Object o) { |
318 |
< |
if (o == null) |
319 |
< |
return false; |
320 |
< |
int mask = elements.length - 1; |
321 |
< |
int i = head; |
322 |
< |
Object x; |
323 |
< |
while ( (x = elements[i]) != null) { |
324 |
< |
if (o.equals(x)) { |
325 |
< |
delete(i); |
326 |
< |
return true; |
318 |
> |
if (o != null) { |
319 |
> |
int mask = elements.length - 1; |
320 |
> |
int i = head; |
321 |
> |
Object x; |
322 |
> |
while ( (x = elements[i]) != null) { |
323 |
> |
if (o.equals(x)) { |
324 |
> |
delete(i); |
325 |
> |
return true; |
326 |
> |
} |
327 |
> |
i = (i + 1) & mask; |
328 |
|
} |
329 |
– |
i = (i + 1) & mask; |
329 |
|
} |
330 |
|
return false; |
331 |
|
} |
658 |
|
* @return {@code true} if this deque contains the specified element |
659 |
|
*/ |
660 |
|
public boolean contains(Object o) { |
661 |
< |
if (o == null) |
662 |
< |
return false; |
663 |
< |
int mask = elements.length - 1; |
664 |
< |
int i = head; |
665 |
< |
Object x; |
666 |
< |
while ( (x = elements[i]) != null) { |
667 |
< |
if (o.equals(x)) |
668 |
< |
return true; |
669 |
< |
i = (i + 1) & mask; |
661 |
> |
if (o != null) { |
662 |
> |
int mask = elements.length - 1; |
663 |
> |
int i = head; |
664 |
> |
Object x; |
665 |
> |
while ( (x = elements[i]) != null) { |
666 |
> |
if (o.equals(x)) |
667 |
> |
return true; |
668 |
> |
i = (i + 1) & mask; |
669 |
> |
} |
670 |
|
} |
671 |
|
return false; |
672 |
|
} |
810 |
|
/** |
811 |
|
* Saves this deque to a stream (that is, serializes it). |
812 |
|
* |
813 |
+ |
* @param s the stream |
814 |
+ |
* @throws java.io.IOException if an I/O error occurs |
815 |
|
* @serialData The current size ({@code int}) of the deque, |
816 |
|
* followed by all of its elements (each an object reference) in |
817 |
|
* first-to-last order. |
831 |
|
|
832 |
|
/** |
833 |
|
* Reconstitutes this deque from a stream (that is, deserializes it). |
834 |
+ |
* @param s the stream |
835 |
+ |
* @throws ClassNotFoundException if the class of a serialized object |
836 |
+ |
* could not be found |
837 |
+ |
* @throws java.io.IOException if an I/O error occurs |
838 |
|
*/ |
839 |
|
private void readObject(java.io.ObjectInputStream s) |
840 |
|
throws java.io.IOException, ClassNotFoundException { |