mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8266571: Sequenced Collections
Reviewed-by: alanb
This commit is contained in:
parent
bad6aa68e4
commit
17ce0976e4
42 changed files with 7060 additions and 150 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -428,6 +428,35 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
return elementData(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws NoSuchElementException {@inheritDoc}
|
||||
* @since 21
|
||||
*/
|
||||
public E getFirst() {
|
||||
if (size == 0) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
return elementData(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws NoSuchElementException {@inheritDoc}
|
||||
* @since 21
|
||||
*/
|
||||
public E getLast() {
|
||||
int last = size - 1;
|
||||
if (last < 0) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
return elementData(last);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the element at the specified position in this list with
|
||||
* the specified element.
|
||||
|
@ -491,6 +520,24 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
size = s + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @since 21
|
||||
*/
|
||||
public void addFirst(E element) {
|
||||
add(0, element);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @since 21
|
||||
*/
|
||||
public void addLast(E element) {
|
||||
add(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the element at the specified position in this list.
|
||||
* Shifts any subsequent elements to the left (subtracts one from their
|
||||
|
@ -510,6 +557,41 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
return oldValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws NoSuchElementException {@inheritDoc}
|
||||
* @since 21
|
||||
*/
|
||||
public E removeFirst() {
|
||||
if (size == 0) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
Object[] es = elementData;
|
||||
@SuppressWarnings("unchecked") E oldValue = (E) es[0];
|
||||
fastRemove(es, 0);
|
||||
return oldValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws NoSuchElementException {@inheritDoc}
|
||||
* @since 21
|
||||
*/
|
||||
public E removeLast() {
|
||||
int last = size - 1;
|
||||
if (last < 0) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
Object[] es = elementData;
|
||||
@SuppressWarnings("unchecked") E oldValue = (E) es[last];
|
||||
fastRemove(es, last);
|
||||
return oldValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue